Skip to content

Commit f79cc76

Browse files
committed
[MIG] printer_zpl2: Migration to 18.0
1 parent 5ff305c commit f79cc76

11 files changed

+128
-194
lines changed

printer_zpl2/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
{
55
"name": "Printer ZPL II",
6-
"version": "16.0.1.1.0",
6+
"version": "18.0.1.0.0",
77
"category": "Printer",
88
"summary": "Add a ZPL II label printing feature",
99
"author": "SUBTENO-IT, FLorent de Labarre, "

printer_zpl2/models/printing_label_zpl2.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import requests
1111
from PIL import Image, ImageOps
1212

13-
from odoo import _, api, exceptions, fields, models
13+
from odoo import api, exceptions, fields, models
1414
from odoo.exceptions import ValidationError
1515
from odoo.tools.safe_eval import safe_eval, wrap_module
1616

@@ -91,7 +91,7 @@ class PrintingLabelZpl2(models.Model):
9191
@api.constrains("component_ids")
9292
def check_recursion(self):
9393
cr = self._cr
94-
self.flush(["component_ids"])
94+
self.flush_recordset(["component_ids"])
9595
query = (
9696
'SELECT "{}", "{}" FROM "{}" '
9797
'WHERE "{}" IN %s AND "{}" IS NOT NULL'.format(
@@ -115,7 +115,9 @@ def check_recursion(self):
115115
[id1] + list(preds[id1]), [id2] + list(succs[id2])
116116
):
117117
if x == y:
118-
raise ValidationError(_("You can not create recursive labels."))
118+
raise ValidationError(
119+
self.env._("You can not create recursive labels.")
120+
)
119121
succs[x].add(y)
120122
preds[y].add(x)
121123
if id2 not in done:
@@ -370,7 +372,9 @@ def print_label(self, printer, record, page_count=1, **extra):
370372
for label in self:
371373
if record._name != label.model_id.model:
372374
raise exceptions.UserError(
373-
_("This label cannot be used on {model}").format(model=record._name)
375+
self.env._("This label cannot be used on {model}").format(
376+
model=record._name
377+
)
374378
)
375379
# Send the label to printer
376380
label_contents = label._generate_zpl2_data(
@@ -385,7 +389,7 @@ def print_label(self, printer, record, page_count=1, **extra):
385389
def new_action(self, model_id):
386390
return self.env["ir.actions.act_window"].create(
387391
{
388-
"name": _("Print Label"),
392+
"name": self.env._("Print Label"),
389393
"binding_model_id": model_id,
390394
"res_model": "wizard.print.record.label",
391395
"view_mode": "form",
@@ -522,9 +526,9 @@ def _generate_labelary_image(self):
522526
return base64.b64encode(imgByteArr.getvalue())
523527
else:
524528
_logger.warning(
525-
_("Error with Labelary API. %s") % response.status_code
529+
self.env._("Error with Labelary API. %s") % response.status_code
526530
)
527531

528532
except Exception as e:
529-
_logger.warning(_("Error with Labelary API. %s") % e)
533+
_logger.warning(self.env._("Error with Labelary API. %s") % e)
530534
return False

printer_zpl2/tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright (C) 2016 SYLEAM (<http://www.syleam.fr>)
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33

4+
from . import common
45
from . import test_printing_label_zpl2
56
from . import test_wizard_print_record_label
67
from . import test_generate_action

printer_zpl2/tests/common.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from odoo.addons.base.tests.common import BaseCommon
2+
3+
model = "odoo.addons.base_report_to_printer.models.printing_server"
4+
5+
6+
class PrinterZpl2Common(BaseCommon):
7+
@classmethod
8+
def setUpClass(cls):
9+
super().setUpClass()
10+
cls.Model = cls.env["printing.label.zpl2"]
11+
cls.ComponentModel = cls.env["printing.label.zpl2.component"]
12+
cls.server = cls.env["printing.server"].create({})
13+
cls.printer = cls.env["printing.printer"].create(
14+
{
15+
"name": "Printer",
16+
"server_id": cls.server.id,
17+
"system_name": "Sys Name",
18+
"default": True,
19+
"status": "unknown",
20+
"status_message": "Msg",
21+
"model": "res.users",
22+
"location": "Location",
23+
"uri": "URI",
24+
}
25+
)
26+
cls.label_vals = {
27+
"name": "ZPL II Label",
28+
"model_id": cls.env.ref("base_report_to_printer.model_printing_printer").id,
29+
}
30+
cls.label = cls.env["printing.label.zpl2"].create(cls.label_vals)

printer_zpl2/tests/test_generate_action.py

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,12 @@
11
# Copyright (C) 2018 Florent de Labarre (<https://github.com/fmdl>)
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
33

4-
from odoo.tests.common import TransactionCase
4+
from .common import PrinterZpl2Common
55

66
model = "odoo.addons.base_report_to_printer.models.printing_server"
77

88

9-
class TestWizardPrintRecordLabel(TransactionCase):
10-
def setUp(self):
11-
super().setUp()
12-
self.Model = self.env["wizard.print.record.label"]
13-
self.server = self.env["printing.server"].create({})
14-
self.printer = self.env["printing.printer"].create(
15-
{
16-
"name": "Printer",
17-
"server_id": self.server.id,
18-
"system_name": "Sys Name",
19-
"default": True,
20-
"status": "unknown",
21-
"status_message": "Msg",
22-
"model": "res.users",
23-
"location": "Location",
24-
"uri": "URI",
25-
}
26-
)
27-
self.label = self.env["printing.label.zpl2"].create(
28-
{
29-
"name": "ZPL II Label",
30-
"model_id": self.env.ref(
31-
"base_report_to_printer.model_printing_printer"
32-
).id,
33-
}
34-
)
35-
9+
class TestWizardPrintRecordLabel(PrinterZpl2Common):
3610
def test_create_action(self):
3711
"""Check the creation of action"""
3812
self.label.create_action()

printer_zpl2/tests/test_printing_label_zpl2.py

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,18 @@
44
from unittest.mock import patch
55

66
from odoo import exceptions
7-
from odoo.tests.common import TransactionCase
87

98
from ..models import zpl2
9+
from .common import PrinterZpl2Common
1010

1111
model = "odoo.addons.base_report_to_printer.models.printing_server"
1212

1313

14-
class TestPrintingLabelZpl2(TransactionCase):
15-
def setUp(self):
16-
super().setUp()
17-
self.Model = self.env["printing.label.zpl2"]
18-
self.ComponentModel = self.env["printing.label.zpl2.component"]
19-
self.server = self.env["printing.server"].create({})
20-
self.printer = self.env["printing.printer"].create(
21-
{
22-
"name": "Printer",
23-
"server_id": self.server.id,
24-
"system_name": "Sys Name",
25-
"default": True,
26-
"status": "unknown",
27-
"status_message": "Msg",
28-
"model": "res.users",
29-
"location": "Location",
30-
"uri": "URI",
31-
}
32-
)
33-
self.label_vals = {
34-
"name": "ZPL II Label",
35-
"model_id": self.env.ref(
36-
"base_report_to_printer.model_printing_printer"
37-
).id,
38-
}
39-
self.component_vals = {"name": "ZPL II Label Component"}
14+
class TestPrintingLabelZpl2(PrinterZpl2Common):
15+
@classmethod
16+
def setUpClass(cls):
17+
super().setUpClass()
18+
cls.component_vals = {"name": "ZPL II Label Component"}
4019

4120
def new_label(self, vals=None):
4221
values = self.label_vals.copy()

printer_zpl2/tests/test_test_mode.py

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,25 @@
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
33
from unittest.mock import patch
44

5-
from odoo.tests.common import TransactionCase
5+
import requests
6+
7+
from odoo.tools import mute_logger
8+
9+
from .common import PrinterZpl2Common
610

711
model = "odoo.addons.base_report_to_printer.models.printing_server"
812

913

10-
class TestWizardPrintRecordLabel(TransactionCase):
11-
def setUp(self):
12-
super().setUp()
13-
self.Model = self.env["wizard.print.record.label"]
14-
self.server = self.env["printing.server"].create({})
15-
self.printer = self.env["printing.printer"].create(
16-
{
17-
"name": "Printer",
18-
"server_id": self.server.id,
19-
"system_name": "Sys Name",
20-
"default": True,
21-
"status": "unknown",
22-
"status_message": "Msg",
23-
"model": "res.users",
24-
"location": "Location",
25-
"uri": "URI",
26-
}
27-
)
28-
self.label = self.env["printing.label.zpl2"].create(
29-
{
30-
"name": "ZPL II Label",
31-
"model_id": self.env.ref(
32-
"base_report_to_printer.model_printing_printer"
33-
).id,
34-
}
35-
)
14+
class TestWizardPrintRecordLabel(PrinterZpl2Common):
15+
@classmethod
16+
def setUpClass(cls):
17+
cls._super_send = requests.Session.send
18+
super().setUpClass()
19+
20+
@classmethod
21+
def _request_handler(cls, s, r, /, **kw):
22+
"""Don't block external requests."""
23+
return cls._super_send(s, r, **kw)
3624

3725
def test_get_record(self):
3826
"""Check if return a record"""
@@ -64,11 +52,15 @@ def test_emulation_with_bad_header(self):
6452
self.label.test_labelary_mode = True
6553
self.label.labelary_width = 80
6654
self.label.labelary_dpmm = "8dpmm"
55+
# Maximum label size of 15 x 15 inches
6756
self.label.labelary_height = 10000000
6857
self.env["printing.label.zpl2.component"].create(
6958
{"name": "ZPL II Label", "label_id": self.label.id, "data": '"Test"'}
7059
)
71-
self.assertFalse(self.label.labelary_image)
60+
# do not log expected warning "Error with Labelary API. 400"
61+
# "ERROR: Label height is larger than 15.0 inches"
62+
with mute_logger("odoo.addons.printer_zpl2.models.printing_label_zpl2"):
63+
self.assertFalse(self.label.labelary_image)
7264

7365
def test_emulation_with_bad_data_compute(self):
7466
"""Check if bad data compute"""

printer_zpl2/tests/test_wizard_import_zpl2.py

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,10 @@
11
# Copyright (C) 2018 Florent de Labarre (<https://github.com/fmdl>)
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
33

4-
from odoo.tests.common import TransactionCase
4+
from .common import PrinterZpl2Common
55

66

7-
class TestWizardImportZpl2(TransactionCase):
8-
def setUp(self):
9-
super().setUp()
10-
self.Model = self.env["wizard.print.record.label"]
11-
self.server = self.env["printing.server"].create({})
12-
self.printer = self.env["printing.printer"].create(
13-
{
14-
"name": "Printer",
15-
"server_id": self.server.id,
16-
"system_name": "Sys Name",
17-
"default": True,
18-
"status": "unknown",
19-
"status_message": "Msg",
20-
"model": "res.users",
21-
"location": "Location",
22-
"uri": "URI",
23-
}
24-
)
25-
self.label = self.env["printing.label.zpl2"].create(
26-
{
27-
"name": "ZPL II Label",
28-
"model_id": self.env.ref(
29-
"base_report_to_printer.model_printing_printer"
30-
).id,
31-
}
32-
)
33-
7+
class TestWizardImportZpl2(PrinterZpl2Common):
348
def test_open_wizard(self):
359
"""open wizard from label"""
3610
res = self.label.import_zpl2()

printer_zpl2/tests/test_wizard_print_record_label.py

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,21 @@
33

44
from unittest.mock import patch
55

6-
from odoo.tests.common import TransactionCase
6+
from .common import PrinterZpl2Common
77

88
model = "odoo.addons.base_report_to_printer.models.printing_server"
99

1010

11-
class TestWizardPrintRecordLabel(TransactionCase):
12-
def setUp(self):
13-
super().setUp()
14-
self.Model = self.env["wizard.print.record.label"]
15-
self.server = self.env["printing.server"].create({})
16-
self.printer = self.env["printing.printer"].create(
17-
{
18-
"name": "Printer",
19-
"server_id": self.server.id,
20-
"system_name": "Sys Name",
21-
"default": True,
22-
"status": "unknown",
23-
"status_message": "Msg",
24-
"model": "res.users",
25-
"location": "Location",
26-
"uri": "URI",
27-
}
28-
)
29-
self.label = self.env["printing.label.zpl2"].create(
30-
{
31-
"name": "ZPL II Label",
32-
"model_id": self.env.ref(
33-
"base_report_to_printer.model_printing_printer"
34-
).id,
35-
}
36-
)
11+
class TestWizardPrintRecordLabel(PrinterZpl2Common):
12+
@classmethod
13+
def setUpClass(cls):
14+
super().setUpClass()
15+
cls.Wizard = cls.env["wizard.print.record.label"]
3716

3817
@patch(f"{model}.cups")
3918
def test_print_record_label(self, cups):
4019
"""Check that printing a label using the generic wizard works"""
41-
wizard_obj = self.Model.with_context(
20+
wizard_obj = self.Wizard.with_context(
4221
active_model="printing.printer",
4322
active_id=self.printer.id,
4423
active_ids=[self.printer.id],
@@ -75,7 +54,7 @@ def test_wizard_multiple_printers_and_labels(self):
7554
).id,
7655
}
7756
)
78-
wizard_obj = self.Model.with_context(
57+
wizard_obj = self.Wizard.with_context(
7958
active_model="printing.printer",
8059
active_id=self.printer.id,
8160
active_ids=[self.printer.id],
@@ -94,7 +73,7 @@ def test_wizard_multiple_labels_but_on_different_models(self):
9473
"model_id": self.env.ref("base.model_res_users").id,
9574
}
9675
)
97-
wizard_obj = self.Model.with_context(
76+
wizard_obj = self.Wizard.with_context(
9877
active_model="printing.printer",
9978
active_id=self.printer.id,
10079
active_ids=[self.printer.id],

0 commit comments

Comments
 (0)