22
33from odoo .exceptions import ValidationError
44from odoo .tests import tagged
5- from odoo .tests .common import Form , TransactionCase
5+ from odoo .tests .common import TransactionCase
66
77
88@tagged ("post_install" , "-at_install" )
@@ -32,62 +32,75 @@ def test_01_suffix_model_creation(self):
3232 self .assertTrue (suffix .active )
3333 self .assertEqual (suffix .sequence , 10 ) # Default
3434
35- def test_02_suffix_uniqueness (self ):
36- """Test that suffix name and code must be unique."""
37- with self .assertRaises ((IntegrityError , ValidationError )):
35+ def test_02_suffix_name_uniqueness (self ):
36+ """Test that suffix name must be unique."""
37+ with self .assertRaises ((IntegrityError , ValidationError )), self . cr . savepoint () :
3838 self .env ["spp.name.suffix" ].create (
3939 {
4040 "name" : "Jr." ,
4141 "code" : "JR2" ,
4242 }
4343 )
44- with self .assertRaises ((IntegrityError , ValidationError )):
44+
45+ def test_02b_suffix_code_uniqueness (self ):
46+ """Test that suffix code must be unique."""
47+ with self .assertRaises ((IntegrityError , ValidationError )), self .cr .savepoint ():
4548 self .env ["spp.name.suffix" ].create (
4649 {
4750 "name" : "Junior" ,
4851 "code" : "JR" ,
4952 }
5053 )
5154
52- def test_03_name_with_suffix_using_form (self ):
53- """Test that suffix is appended to the name using form simulation."""
54- with Form (self .env ["res.partner" ]) as partner_form :
55- partner_form .is_registrant = True
56- partner_form .is_group = False
57- partner_form .family_name = "Doe"
58- partner_form .given_name = "John"
59- partner_form .suffix_id = self .suffix_jr
60- individual = partner_form .save ()
55+ def test_03_name_with_suffix (self ):
56+ """Test that suffix is appended to the computed name."""
57+ individual = self .env ["res.partner" ].create (
58+ {
59+ "family_name" : "Doe" ,
60+ "given_name" : "John" ,
61+ "suffix_id" : self .suffix_jr .id ,
62+ "is_registrant" : True ,
63+ "is_group" : False ,
64+ }
65+ )
66+ # Call name_change to generate name (simulates form onchange)
67+ individual .name_change ()
6168 self .assertEqual (
6269 individual .name ,
6370 "DOE, JOHN, JR." ,
6471 "Name should include suffix" ,
6572 )
6673
67- def test_04_name_without_suffix_using_form (self ):
68- """Test that name is generated correctly without suffix."""
69- with Form (self .env ["res.partner" ]) as partner_form :
70- partner_form .is_registrant = True
71- partner_form .is_group = False
72- partner_form .family_name = "Doe"
73- partner_form .given_name = "Jane"
74- individual = partner_form .save ()
74+ def test_04_name_without_suffix (self ):
75+ """Test that name is computed correctly without suffix."""
76+ individual = self .env ["res.partner" ].create (
77+ {
78+ "family_name" : "Doe" ,
79+ "given_name" : "Jane" ,
80+ "is_registrant" : True ,
81+ "is_group" : False ,
82+ }
83+ )
84+ individual .name_change ()
7585 self .assertEqual (
7686 individual .name ,
7787 "DOE, JANE" ,
7888 "Name should not have trailing comma when no suffix" ,
7989 )
8090
81- def test_05_name_with_all_fields_using_form (self ):
91+ def test_05_name_with_all_fields (self ):
8292 """Test name with all fields including addl_name and suffix."""
83- with Form (self .env ["res.partner" ]) as partner_form :
84- partner_form .is_registrant = True
85- partner_form .is_group = False
86- partner_form .family_name = "Smith"
87- partner_form .given_name = "Robert"
88- partner_form .addl_name = "James"
89- partner_form .suffix_id = self .suffix_phd
90- individual = partner_form .save ()
93+ individual = self .env ["res.partner" ].create (
94+ {
95+ "family_name" : "Smith" ,
96+ "given_name" : "Robert" ,
97+ "addl_name" : "James" ,
98+ "suffix_id" : self .suffix_phd .id ,
99+ "is_registrant" : True ,
100+ "is_group" : False ,
101+ }
102+ )
103+ individual .name_change ()
91104 self .assertEqual (
92105 individual .name ,
93106 "SMITH, ROBERT JAMES, PHD" ,
@@ -112,8 +125,8 @@ def test_06_group_name_unaffected(self):
112125 "Group name should not include suffix" ,
113126 )
114127
115- def test_07_name_change_method_direct_call (self ):
116- """Test name_change method called directly ."""
128+ def test_07_suffix_update_triggers_name_change (self ):
129+ """Test that updating suffix and calling name_change updates name ."""
117130 individual = self .env ["res.partner" ].create (
118131 {
119132 "family_name" : "Johnson" ,
0 commit comments