Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0] Add printing_auto_base #310

Open
wants to merge 8 commits into
base: 14.0
Choose a base branch
from
Prev Previous commit
[FIX] printing_auto_base: use proper Error
jbaudoux committed Dec 11, 2024
commit e5b0dee319bf4a48f651f739294bf7139be8bed4
8 changes: 4 additions & 4 deletions printing_auto_base/models/printing_auto.py
Original file line number Diff line number Diff line change
@@ -65,89 +65,89 @@
def _check_data_source(self):
for rec in self:
if rec.data_source == "report" and not rec.report_id:
raise UserError(_("Report is not set"))
raise ValidationError(_("Report is not set"))

Check warning on line 68 in printing_auto_base/models/printing_auto.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto.py#L68

Added line #L68 was not covered by tests
if rec.data_source == "attachment" and (
not rec.attachment_domain or rec.attachment_domain == "[]"
):
raise UserError(_("Attachment domain is not set"))
raise ValidationError(_("Attachment domain is not set"))

Check warning on line 72 in printing_auto_base/models/printing_auto.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto.py#L72

Added line #L72 was not covered by tests

def _get_behaviour(self):
if self.printer_id:
result = {"printer": self.printer_id}

Check warning on line 76 in printing_auto_base/models/printing_auto.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto.py#L76

Added line #L76 was not covered by tests
if self.printer_tray_id:
result["tray"] = self.printer_tray_id.system_name
return result

Check warning on line 79 in printing_auto_base/models/printing_auto.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto.py#L78-L79

Added lines #L78 - L79 were not covered by tests
if self.data_source == "report":
return self.report_id.behaviour()
return self.env["ir.actions.report"]._get_user_default_print_behaviour()

Check warning on line 82 in printing_auto_base/models/printing_auto.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto.py#L81-L82

Added lines #L81 - L82 were not covered by tests

def _get_record(self, record):
if self.record_change:
try:
return safe_eval(f"obj.{self.record_change}", {"obj": record})
except Exception as e:
raise ValidationError(
raise UserError(

Check warning on line 89 in printing_auto_base/models/printing_auto.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto.py#L86-L89

Added lines #L86 - L89 were not covered by tests
_("The Record change could not be applied because: %s") % str(e)
) from e
return record

Check warning on line 92 in printing_auto_base/models/printing_auto.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto.py#L92

Added line #L92 was not covered by tests

def _check_condition(self, record):
domain = safe_eval(self.condition, {"env": self.env})
return record.filtered_domain(domain)

Check warning on line 96 in printing_auto_base/models/printing_auto.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto.py#L95-L96

Added lines #L95 - L96 were not covered by tests

def _get_content(self, records):
generate_data_func = getattr(

Check warning on line 99 in printing_auto_base/models/printing_auto.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto.py#L99

Added line #L99 was not covered by tests
self, f"_generate_data_from_{self.data_source}", None
)
content = []

Check warning on line 102 in printing_auto_base/models/printing_auto.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto.py#L102

Added line #L102 was not covered by tests
if generate_data_func:
records = self._get_record(records)

Check warning on line 104 in printing_auto_base/models/printing_auto.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto.py#L104

Added line #L104 was not covered by tests
for record in records:
content += generate_data_func(record)
return content

Check warning on line 107 in printing_auto_base/models/printing_auto.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto.py#L106-L107

Added lines #L106 - L107 were not covered by tests

def _prepare_attachment_domain(self, record):
domain = safe_eval(self.attachment_domain)
record_domain = [

Check warning on line 111 in printing_auto_base/models/printing_auto.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto.py#L110-L111

Added lines #L110 - L111 were not covered by tests
("res_id", "=", record.id),
("res_model", "=", record._name),
]
return expression.AND([domain, record_domain])

Check warning on line 115 in printing_auto_base/models/printing_auto.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto.py#L115

Added line #L115 was not covered by tests

def _generate_data_from_attachment(self, record):
domain = self._prepare_attachment_domain(record)
attachments = self.env["ir.attachment"].search(domain)

Check warning on line 119 in printing_auto_base/models/printing_auto.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto.py#L118-L119

Added lines #L118 - L119 were not covered by tests
if not attachments:
raise ValidationError(_("No attachment was found."))
raise UserError(_("No attachment was found."))

Check warning on line 121 in printing_auto_base/models/printing_auto.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto.py#L121

Added line #L121 was not covered by tests
return [base64.b64decode(a.datas) for a in attachments]

def _generate_data_from_report(self, record):
self.ensure_one()
data, _ = self.report_id.with_context(must_skip_send_to_printer=True)._render(

Check warning on line 126 in printing_auto_base/models/printing_auto.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto.py#L125-L126

Added lines #L125 - L126 were not covered by tests
record.id
)
return [data]

Check warning on line 129 in printing_auto_base/models/printing_auto.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto.py#L129

Added line #L129 was not covered by tests

def do_print(self, records):
self.ensure_one()

Check warning on line 132 in printing_auto_base/models/printing_auto.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto.py#L132

Added line #L132 was not covered by tests

behaviour = self._get_behaviour()
printer = behaviour["printer"]

Check warning on line 135 in printing_auto_base/models/printing_auto.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto.py#L134-L135

Added lines #L134 - L135 were not covered by tests

if self.nbr_of_copies <= 0:
return (printer, 0)
records = self._check_condition(records)

Check warning on line 139 in printing_auto_base/models/printing_auto.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto.py#L138-L139

Added lines #L138 - L139 were not covered by tests
if not records:
return (printer, 0)

Check warning on line 141 in printing_auto_base/models/printing_auto.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto.py#L141

Added line #L141 was not covered by tests

if not printer:
raise UserError(

Check warning on line 144 in printing_auto_base/models/printing_auto.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto.py#L144

Added line #L144 was not covered by tests
_("No printer configured to print this {}.").format(self.name)
)

count = 0

Check warning on line 148 in printing_auto_base/models/printing_auto.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto.py#L148

Added line #L148 was not covered by tests
for content in self._get_content(records):
for _n in range(self.nbr_of_copies):
printer.print_document(report=None, content=content, **behaviour)
count += 1
return (printer, count)

Check warning on line 153 in printing_auto_base/models/printing_auto.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto.py#L151-L153

Added lines #L151 - L153 were not covered by tests

Unchanged files with check annotations Beta

printing_auto_error = fields.Text("Printing error")
def _on_printing_auto_start(self):
self.write({"printing_auto_error": False})

Check warning on line 21 in printing_auto_base/models/printing_auto_mixin.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto_mixin.py#L21

Added line #L21 was not covered by tests
def _printing_auto_done_post(self, auto, printer, count):
self.ensure_one()
self.message_post(

Check warning on line 25 in printing_auto_base/models/printing_auto_mixin.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto_mixin.py#L24-L25

Added lines #L24 - L25 were not covered by tests
body=_("{name}: {count} document(s) sent to printer {printer}").format(
name=auto.name, count=count, printer=printer.name
)
)
def _on_printing_auto_done(self, auto, printer, count):
self._printing_auto_done_post(auto, printer, count)

Check warning on line 32 in printing_auto_base/models/printing_auto_mixin.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto_mixin.py#L32

Added line #L32 was not covered by tests
def _on_printing_auto_error(self, e):
self.write({"printing_auto_error": str(e)})

Check warning on line 35 in printing_auto_base/models/printing_auto_mixin.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto_mixin.py#L35

Added line #L35 was not covered by tests
def _get_printing_auto(self):
return self.auto_printing_ids

Check warning on line 38 in printing_auto_base/models/printing_auto_mixin.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto_mixin.py#L38

Added line #L38 was not covered by tests
def _do_print_auto(self, printing_auto):
printing_auto.ensure_one()
printer, count = printing_auto.do_print(self)

Check warning on line 42 in printing_auto_base/models/printing_auto_mixin.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto_mixin.py#L41-L42

Added lines #L41 - L42 were not covered by tests
if count:
self._on_printing_auto_done(printing_auto, printer, count)

Check warning on line 44 in printing_auto_base/models/printing_auto_mixin.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto_mixin.py#L44

Added line #L44 was not covered by tests
def _handle_print_auto(self, printing_auto):
printing_auto.ensure_one()

Check warning on line 47 in printing_auto_base/models/printing_auto_mixin.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto_mixin.py#L47

Added line #L47 was not covered by tests
if printing_auto.action_on_error == "raise":
self._do_print_auto(printing_auto)
return
try:
with self.env.cr.savepoint():
self._do_print_auto(printing_auto)
except Exception as e:
_logger.exception(

Check warning on line 55 in printing_auto_base/models/printing_auto_mixin.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto_mixin.py#L49-L55

Added lines #L49 - L55 were not covered by tests
"An error occurred while printing '%s' for record %s.",
printing_auto,
self,
)
self._on_printing_auto_error(e)

Check warning on line 60 in printing_auto_base/models/printing_auto_mixin.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto_mixin.py#L60

Added line #L60 was not covered by tests
def handle_print_auto(self):
"""Print some report or attachment directly to the corresponding printer."""
self._on_printing_auto_start()
to_print = {}

Check warning on line 65 in printing_auto_base/models/printing_auto_mixin.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto_mixin.py#L64-L65

Added lines #L64 - L65 were not covered by tests
for record in self:
for printing_auto in record._get_printing_auto():
if printing_auto not in to_print.keys():
to_print[printing_auto] = record

Check warning on line 69 in printing_auto_base/models/printing_auto_mixin.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto_mixin.py#L69

Added line #L69 was not covered by tests
else:
to_print[printing_auto] |= record

Check warning on line 71 in printing_auto_base/models/printing_auto_mixin.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto_mixin.py#L71

Added line #L71 was not covered by tests
for printing_auto, records in to_print.items():
records._handle_print_auto(printing_auto)

Check warning on line 73 in printing_auto_base/models/printing_auto_mixin.py

Codecov / codecov/patch

printing_auto_base/models/printing_auto_mixin.py#L73

Added line #L73 was not covered by tests
from odoo_test_helper import FakeModelLoader
from odoo.exceptions import UserError, ValidationError

Check warning on line 9 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L9

Added line #L9 was not covered by tests
from odoo.addons.base_report_to_printer.models.printing_printer import PrintingPrinter

Check warning on line 11 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L11

Added line #L11 was not covered by tests
from .common import TestPrintingAutoCommon, print_document

Check warning on line 13 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L13

Added line #L13 was not covered by tests
@mock.patch.object(PrintingPrinter, "print_document", print_document)
class TestPrintingAutoBase(TestPrintingAutoCommon):
@classmethod

Check warning on line 18 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L17-L18

Added lines #L17 - L18 were not covered by tests
def setUpClass(cls):
super().setUpClass()
cls.loader = FakeModelLoader(cls.env, cls.__module__)
cls.loader.backup_registry()
from .model_test import PrintingAutoTester, PrintingAutoTesterChild

Check warning on line 23 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L20-L23

Added lines #L20 - L23 were not covered by tests
cls.loader.update_registry((PrintingAutoTesterChild, PrintingAutoTester))

Check warning on line 25 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L25

Added line #L25 was not covered by tests
def test_check_data_source(self):
with self.assertRaises(UserError):
self._create_printing_auto_report({"report_id": False})

Check warning on line 29 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L27-L29

Added lines #L27 - L29 were not covered by tests
with self.assertRaises(UserError):
self._create_printing_auto_attachment({"attachment_domain": "[]"})

Check warning on line 32 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L31-L32

Added lines #L31 - L32 were not covered by tests
with self.assertRaises(UserError):
printing_auto = self._create_printing_auto_attachment()
printing_auto.attachment_domain = False

Check warning on line 36 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L34-L36

Added lines #L34 - L36 were not covered by tests
def test_behaviour(self):
expected = {"printer": self.printer_1}
printing_auto = self._create_printing_auto_report(

Check warning on line 40 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L38-L40

Added lines #L38 - L40 were not covered by tests
{"printer_id": self.printer_1.id}
)
self.assertEqual(expected, printing_auto._get_behaviour())

Check warning on line 43 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L43

Added line #L43 was not covered by tests
printing_auto.printer_tray_id = self.tray_1
expected["tray"] = self.tray_1.system_name
self.assertEqual(expected, printing_auto._get_behaviour())

Check warning on line 47 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L45-L47

Added lines #L45 - L47 were not covered by tests
expected = printing_auto.report_id.behaviour()
printing_auto.printer_id = False
printing_auto.printer_tray_id = False
self.assertEqual(expected, printing_auto._get_behaviour())

Check warning on line 52 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L49-L52

Added lines #L49 - L52 were not covered by tests
expected = self.env["ir.actions.report"]._get_user_default_print_behaviour()
printing_auto = self._create_printing_auto_attachment()
self.assertEqual(expected, printing_auto._get_behaviour())

Check warning on line 56 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L54-L56

Added lines #L54 - L56 were not covered by tests
def test_record_change(self):
parent = self.env["res.partner"].create({"name": "Parent"})
partner = parent.create({"name": "Child", "parent_id": parent.id})
printing_auto = self._create_printing_auto_report(

Check warning on line 61 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L58-L61

Added lines #L58 - L61 were not covered by tests
{"record_change": "parent_id"}
)
self.assertEqual(parent, printing_auto._get_record(partner))

Check warning on line 64 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L64

Added line #L64 was not covered by tests
def test_check_condition(self):
partner = self.env["res.partner"].create({"name": "Partner"})
printing_auto = self._create_printing_auto_report(

Check warning on line 68 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L66-L68

Added lines #L66 - L68 were not covered by tests
{"condition": f"[('name', '=', '{partner.name}')]"}
)
self.assertEqual(partner, printing_auto._check_condition(partner))
printing_auto.condition = "[('name', '=', '1')]"
self.assertFalse(printing_auto._check_condition(partner))

Check warning on line 73 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L71-L73

Added lines #L71 - L73 were not covered by tests
def test_get_content(self):
printing_auto_report = self._create_printing_auto_report()
self.assertEqual([self.data], printing_auto_report._get_content(self.record))

Check warning on line 77 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L75-L77

Added lines #L75 - L77 were not covered by tests
printing_auto_attachment = self._create_printing_auto_attachment()
attachment = self._create_attachment(self.record, self.data, "1")
self.assertEqual(

Check warning on line 81 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L79-L81

Added lines #L79 - L81 were not covered by tests
[attachment.raw], printing_auto_attachment._get_content(self.record)
)
attachment.unlink()

Check warning on line 84 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L84

Added line #L84 was not covered by tests
with self.assertRaises(ValidationError):
printing_auto_attachment._get_content(self.record)

Check warning on line 87 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L86-L87

Added lines #L86 - L87 were not covered by tests
def test_do_print(self):
printing_auto = self._create_printing_auto_attachment(

Check warning on line 90 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L89-L90

Added lines #L89 - L90 were not covered by tests
{"attachment_domain": "[('name', 'like', 'printing_auto_test')]"}
)
self._create_attachment(self.record, self.data, "1")
with self.assertRaises(UserError):
printing_auto.do_print(self.record)

Check warning on line 95 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L93-L95

Added lines #L93 - L95 were not covered by tests
printing_auto.printer_id = self.printer_1

Check warning on line 97 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L97

Added line #L97 was not covered by tests
for nbr_of_copies in [0, 2, 1]:
expected = (self.printer_1, nbr_of_copies)
printing_auto.nbr_of_copies = nbr_of_copies
self.assertEqual(expected, printing_auto.do_print(self.record))

Check warning on line 101 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L99-L101

Added lines #L99 - L101 were not covered by tests
printing_auto.condition = "[('name', '=', 'test_printing_auto')]"
expected = (self.printer_1, 0)
self.assertEqual(expected, printing_auto.do_print(self.record))

Check warning on line 105 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L103-L105

Added lines #L103 - L105 were not covered by tests
def test_do_not_print_multiple_time_the_same_record(self):

Check warning on line 107 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L107

Added line #L107 was not covered by tests
"""Check the same record is not printed multiple times.
When the 'record_change' field is being used on the printing auto configuration
The same record could be send for printing multiple times.
"""
printing_auto = self._create_printing_auto_report(

Check warning on line 115 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L115

Added line #L115 was not covered by tests
vals={"record_change": "child_ids", "printer_id": self.printer_1.id}
)
child1 = self.env["printingauto.tester.child"].create({"name": "Child One"})
child2 = self.env["printingauto.tester.child"].create({"name": "Child Two"})
parent1 = self.env["printingauto.tester"].create(

Check warning on line 120 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L118-L120

Added lines #L118 - L120 were not covered by tests
{
"name": "Customer One",
"child_ids": [(4, child1.id, 0)],
"auto_printing_ids": [(4, printing_auto.id, 0)],
}
)
parent2 = self.env["printingauto.tester"].create(

Check warning on line 127 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L127

Added line #L127 was not covered by tests
{
"name": "Customer Two",
"child_ids": [(4, child1.id, 0)],
"auto_printing_ids": [(4, printing_auto.id, 0)],
}
)
parents = parent1 | parent2
generate_data_from = (

Check warning on line 135 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L134-L135

Added lines #L134 - L135 were not covered by tests
"odoo.addons.printing_auto_base.models.printing_auto."
"PrintingAuto._generate_data_from_report"
)
with mock.patch(generate_data_from) as generate_data_from:

Check warning on line 139 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L139

Added line #L139 was not covered by tests
# Both parents have the same child only print the child report once
parents.handle_print_auto()
self.assertEqual(generate_data_from.call_count, 1)
generate_data_from.assert_called_with(child1)
generate_data_from.reset_mock()

Check warning on line 144 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L141-L144

Added lines #L141 - L144 were not covered by tests
# Both parents have different childs, print both child reports
parent2.child_ids = [(6, 0, child2.ids)]
parents.handle_print_auto()
self.assertEqual(generate_data_from.call_count, 2)
generate_data_from.assert_has_calls(

Check warning on line 149 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L146-L149

Added lines #L146 - L149 were not covered by tests
[mock.call(child1), mock.call(child2)], any_order=True
)
generate_data_from.reset_mock()

Check warning on line 152 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L152

Added line #L152 was not covered by tests
# THe parents have one child in common and one parent has a 2nd child
parent2.child_ids = [(4, child1.id, 0)]
parents.handle_print_auto()
self.assertEqual(generate_data_from.call_count, 2)
generate_data_from.assert_has_calls(

Check warning on line 157 in printing_auto_base/tests/test_printing_auto_base.py

Codecov / codecov/patch

printing_auto_base/tests/test_printing_auto_base.py#L154-L157

Added lines #L154 - L157 were not covered by tests
[mock.call(child1), mock.call(child2)], any_order=True
)
def _get_behaviour(self):
if self.is_label and not self.printer_id:
return {"printer": self.env.user.default_label_printer_id}
return super()._get_behaviour()

Check warning on line 16 in printing_auto_label_printer/models/printing_auto.py

Codecov / codecov/patch

printing_auto_label_printer/models/printing_auto.py#L15-L16

Added lines #L15 - L16 were not covered by tests
class TestPrintingAutoBase(TestPrintingAutoCommon):
def test_behaviour_label(self):
self.env.user.default_label_printer_id = self.printer_2
expected = {"printer": self.printer_2}
printing_auto = self._create_printing_auto_attachment({"is_label": True})
self.assertEqual(expected, printing_auto._get_behaviour())

Check warning on line 13 in printing_auto_label_printer/tests/test_printing_auto_label_printer.py

Codecov / codecov/patch

printing_auto_label_printer/tests/test_printing_auto_label_printer.py#L9-L13

Added lines #L9 - L13 were not covered by tests