1+ from unittest .mock import patch
2+
13from odoo .tests .common import TransactionCase , tagged
24
35
@@ -11,30 +13,26 @@ def setUpClass(cls):
1113 cls .Wizard = cls .env ["base.document.layout" ]
1214
1315 def test_wizard_default_inherits_company_value (self ):
14- wiz = cls = self .__class__
15- wiz = cls .Wizard .with_company (cls .company .id ).create (
16- {"company_id" : cls .company .id }
16+ wiz = self .Wizard .with_company (self .company .id ).create (
17+ {"company_id" : self .company .id }
1718 )
1819 self .assertEqual (wiz .report_font_size , "11" )
1920
2021 def test_onchange_updates_wizard_field_without_crash (self ):
21- wiz = cls = self .__class__
22- wiz = cls .Wizard .with_company (cls .company .id ).create (
23- {"company_id" : cls .company .id }
22+ wiz = self .Wizard .with_company (self .company .id ).create (
23+ {"company_id" : self .company .id }
2424 )
2525 wiz .report_font_size = "14"
2626 if hasattr (wiz , "_onchange_report_font_size" ):
2727 wiz ._onchange_report_font_size ()
2828 self .assertEqual (wiz .report_font_size , "14" )
2929
3030 def test_apply_wizard_persists_on_company (self ):
31- wiz = cls = self .__class__
32- wiz = cls .Wizard .with_company (cls .company .id ).create (
33- {"company_id" : cls .company .id }
31+ wiz = self .Wizard .with_company (self .company .id ).create (
32+ {"company_id" : self .company .id }
3433 )
3534 wiz .report_font_size = "12"
3635
37- done = False
3836 for meth in (
3937 "execute" ,
4038 "action_confirm" ,
@@ -43,9 +41,56 @@ def test_apply_wizard_persists_on_company(self):
4341 ):
4442 if hasattr (wiz , meth ):
4543 getattr (wiz , meth )()
46- done = True
4744 break
48- if not done :
49- cls .company .write ({"report_font_size" : wiz .report_font_size })
45+ else :
46+ self .company .write ({"report_font_size" : wiz .report_font_size })
47+
48+ self .assertEqual (self .company .report_font_size , "12" )
49+
50+ def test_wizard_reflects_company_change_on_new_instance (self ):
51+ self .company .write ({"report_font_size" : "14" })
52+ wiz = self .Wizard .with_company (self .company .id ).create (
53+ {"company_id" : self .company .id }
54+ )
55+ self .assertEqual (wiz .report_font_size , "14" )
56+
57+ def test_onchange_handles_compute_exception_sets_preview_false (self ):
58+ wiz = self .Wizard .with_company (self .company .id ).create (
59+ {"company_id" : self .company .id }
60+ )
61+ if "preview" not in wiz ._fields :
62+ self .skipTest (
63+ "This Odoo version has no 'preview' field on base.document.layout"
64+ )
65+
66+ wiz .report_font_size = "14"
67+ with patch .object (
68+ type (wiz ), "_compute_preview" , side_effect = Exception ("boom" ), create = True
69+ ):
70+ wiz ._onchange_report_font_size ()
71+ self .assertFalse (bool (wiz .preview ))
72+
73+ def test_apply_uses_action_apply_when_present (self ):
74+ wiz = self .Wizard .with_company (self .company .id ).create (
75+ {"company_id" : self .company .id }
76+ )
77+ wiz .report_font_size = "13"
78+
79+ def _fake_action_apply (self ):
80+ self .company_id .report_font_size = self .report_font_size
81+
82+ with patch .object (type (wiz ), "action_apply" , _fake_action_apply , create = True ):
83+ done = False
84+ for meth in (
85+ "execute" ,
86+ "action_confirm" ,
87+ "action_apply" ,
88+ "action_configure_document_layout" ,
89+ ):
90+ if hasattr (wiz , meth ):
91+ getattr (wiz , meth )()
92+ done = True
93+ break
5094
51- self .assertEqual (cls .company .report_font_size , "12" )
95+ self .assertTrue (done , "Expected loop to call injected action_apply" )
96+ self .assertEqual (self .company .report_font_size , "13" )
0 commit comments