@@ -1177,6 +1177,7 @@ def test_convert_field_to_company_dependent(self):
1177
1177
)
1178
1178
1179
1179
c1 = self .env ["res.company" ].create ({"name" : "Flancrest" })
1180
+ c2 = self .env ["res.company" ].create ({"name" : "Flancrest2" })
1180
1181
1181
1182
test_partners = self .env ["res.partner" ].create (
1182
1183
[
@@ -1189,15 +1190,30 @@ def test_convert_field_to_company_dependent(self):
1189
1190
1190
1191
# Using company_id as default, only records with company set are updated
1191
1192
util .make_field_company_dependent (cr , "res.partner" , "x_test_cd_1" , "char" )
1192
- self .assertEqual (test_partners [0 ].x_test_cd_1 , {str (c1 .id ): "A" })
1193
- self .assertFalse (test_partners [1 ].x_test_cd_1 )
1194
- self .assertFalse (test_partners [2 ].x_test_cd_1 )
1195
-
1196
- # Ignoring company field and composing value for all companies
1197
1193
util .make_field_company_dependent (cr , "res.partner" , "x_test_cd_2" , "char" , company_field = False )
1198
- self .assertEqual (test_partners [0 ].x_test_cd_2 , {str (id ): "A" for id in self .env ["res.company" ].search ([]).ids })
1199
- self .assertEqual (test_partners [1 ].x_test_cd_2 , {str (id ): "B" for id in self .env ["res.company" ].search ([]).ids })
1200
- self .assertFalse (test_partners [2 ].x_test_cd_2 )
1194
+
1195
+ # TODO: make the ORM re-read the info about these manual fields from the DB
1196
+ test_partners ._fields ["x_test_cd_1" ].company_dependent = True
1197
+ test_partners ._fields ["x_test_cd_2" ].company_dependent = True
1198
+
1199
+ test_partners_c1 = test_partners .with_company (c1 .id )
1200
+ self .assertEqual (test_partners_c1 [0 ].x_test_cd_1 , "A" )
1201
+ self .assertFalse (test_partners_c1 [1 ].x_test_cd_1 )
1202
+ self .assertFalse (test_partners_c1 [2 ].x_test_cd_1 )
1203
+ self .assertEqual (test_partners_c1 [0 ].x_test_cd_2 , "A" )
1204
+ self .assertEqual (test_partners_c1 [1 ].x_test_cd_2 , "B" )
1205
+ self .assertFalse (test_partners_c1 [2 ].x_test_cd_2 )
1206
+
1207
+ # AFU: a bug? We need to invalidate in order to get the value of the other company
1208
+ test_partners .invalidate_recordset ()
1209
+ test_partners_c2 = test_partners .with_company (c2 .id )
1210
+
1211
+ self .assertFalse (test_partners_c2 [0 ].x_test_cd_1 )
1212
+ self .assertFalse (test_partners_c2 [1 ].x_test_cd_1 )
1213
+ self .assertFalse (test_partners_c2 [2 ].x_test_cd_1 )
1214
+ self .assertEqual (test_partners_c2 [0 ].x_test_cd_2 , "A" )
1215
+ self .assertEqual (test_partners_c2 [1 ].x_test_cd_2 , "B" )
1216
+ self .assertFalse (test_partners_c2 [2 ].x_test_cd_2 )
1201
1217
1202
1218
1203
1219
class TestHelpers (UnitTestCase ):
0 commit comments