Skip to content

Commit 12babe1

Browse files
committed
[FIX] web_font_size_report_layout: tests
1 parent 28f0979 commit 12babe1

File tree

2 files changed

+22
-36
lines changed

2 files changed

+22
-36
lines changed

web_font_size_report_layout/models/base_document_layout.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ class BaseDocumentLayout(models.TransientModel):
1212

1313
@api.onchange("report_font_size")
1414
def _onchange_report_font_size(self):
15-
if hasattr(self, "_compute_preview"):
16-
try:
17-
self._compute_preview()
18-
except Exception:
15+
func = getattr(self, "_compute_preview", None)
16+
if not callable(func):
17+
return
18+
try:
19+
func()
20+
except Exception:
21+
if "preview" in self._fields:
1922
self.preview = False

web_font_size_report_layout/tests/test_document_layout_onchange.py

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,61 +4,44 @@
44

55

66
@tagged("post_install", "-at_install")
7-
class TestDocumentLayoutWizard(TransactionCase):
7+
class TestDocumentLayoutOnchange(TransactionCase):
88
@classmethod
99
def setUpClass(cls):
1010
super().setUpClass()
1111
cls.Company = cls.env["res.company"]
1212
cls.company = cls.Company.create({"name": "WZ Co", "report_font_size": "11"})
1313
cls.Wizard = cls.env["base.document.layout"]
1414

15-
def test_wizard_default_inherits_company_value(self):
15+
def test_onchange_when_compute_preview_absent_does_nothing(self):
1616
wiz = self.Wizard.with_company(self.company.id).create(
1717
{"company_id": self.company.id}
1818
)
19-
self.assertEqual(wiz.report_font_size, "11")
19+
prev = getattr(wiz, "preview", None)
20+
wiz.report_font_size = "10"
2021

21-
def test_onchange_updates_wizard_field_without_crash(self):
22-
wiz = self.Wizard.with_company(self.company.id).create(
23-
{"company_id": self.company.id}
24-
)
25-
wiz.report_font_size = "14"
26-
if hasattr(wiz, "_onchange_report_font_size"):
22+
with patch.object(type(wiz), "_compute_preview", new=None, create=True):
2723
wiz._onchange_report_font_size()
28-
self.assertEqual(wiz.report_font_size, "14")
2924

30-
def test_apply_wizard_persists_on_company_via_fallback(self):
31-
wiz = self.Wizard.with_company(self.company.id).create(
32-
{"company_id": self.company.id}
33-
)
34-
wiz.report_font_size = "12"
35-
self.company.write({"report_font_size": wiz.report_font_size})
36-
self.assertEqual(self.company.report_font_size, "12")
37-
38-
def test_apply_uses_action_apply_when_present(self):
39-
wiz = self.Wizard.with_company(self.company.id).create(
40-
{"company_id": self.company.id}
41-
)
42-
wiz.report_font_size = "13"
43-
44-
def _fake_action_apply(self):
45-
self.company_id.report_font_size = self.report_font_size
46-
47-
with patch.object(type(wiz), "action_apply", _fake_action_apply, create=True):
48-
wiz.action_apply()
49-
50-
self.assertEqual(self.company.report_font_size, "13")
25+
self.assertEqual(getattr(wiz, "preview", None), prev)
5126

5227
def test_onchange_handles_compute_exception_sets_preview_false(self):
5328
wiz = self.Wizard.with_company(self.company.id).create(
5429
{"company_id": self.company.id}
5530
)
5631
self.assertIn("preview", wiz._fields)
57-
5832
wiz.report_font_size = "14"
33+
5934
with patch.object(
6035
type(wiz), "_compute_preview", side_effect=Exception("boom"), create=True
6136
):
6237
wiz._onchange_report_font_size()
6338

6439
self.assertFalse(bool(wiz.preview))
40+
41+
def test_onchange_updates_wizard_field_without_crash(self):
42+
wiz = self.Wizard.with_company(self.company.id).create(
43+
{"company_id": self.company.id}
44+
)
45+
wiz.report_font_size = "14"
46+
wiz._onchange_report_font_size()
47+
self.assertEqual(wiz.report_font_size, "14")

0 commit comments

Comments
 (0)