77
88
99class TestStockLotMultiImage (BaseCommon ):
10+ @classmethod
11+ def _get_image_vals (cls , name , image_data ):
12+ """Helper to get image values based on available fields"""
13+ comodel = cls .env ["stock.lot" ]._fields ["image_ids" ].comodel_name
14+ fields_list = cls .env [comodel ]._fields
15+ vals = {"name" : name }
16+ if "storage" in fields_list :
17+ vals ["storage" ] = "filestore"
18+ if "attachment_image" in fields_list :
19+ vals ["attachment_image" ] = image_data
20+ elif "image_1920" in fields_list :
21+ vals ["image_1920" ] = image_data
22+ if "owner_model" in fields_list :
23+ vals ["owner_model" ] = "stock.lot"
24+ return vals
25+
1026 @classmethod
1127 def setUpClass (cls ):
1228 super ().setUpClass ()
1329
30+ # Neutralize invalid domain on image_ids if conflict with stock_lot_image exists
31+ field = cls .env ["stock.lot" ]._fields ["image_ids" ]
32+ comodel_fields = cls .env [field .comodel_name ]._fields
33+ if "owner_model" not in comodel_fields :
34+ # If the domain refers to owner_model, we must clear it to avoid KeyError
35+ # in filtered_domain during record creation/linking.
36+ field .domain = []
37+
1438 # Create test images
1539 cls .transparent_image = ( # 1x1 Transparent GIF
1640 b"R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"
@@ -38,21 +62,9 @@ def setUpClass(cls):
3862 "company_id" : cls .env .company .id ,
3963 "image_ids" : [
4064 Command .create (
41- {
42- "storage" : "filestore" ,
43- "name" : "Image 1" ,
44- "attachment_image" : cls .transparent_image ,
45- "owner_model" : "stock.lot" ,
46- }
47- ),
48- Command .create (
49- {
50- "storage" : "filestore" ,
51- "name" : "Image 2" ,
52- "attachment_image" : cls .black_image ,
53- "owner_model" : "stock.lot" ,
54- }
65+ cls ._get_image_vals ("Image 1" , cls .transparent_image )
5566 ),
67+ Command .create (cls ._get_image_vals ("Image 2" , cls .black_image )),
5668 ],
5769 }
5870 )
@@ -77,14 +89,7 @@ def test_add_image(self):
7789 self .test_lot .write (
7890 {
7991 "image_ids" : [
80- Command .create (
81- {
82- "storage" : "filestore" ,
83- "attachment_image" : self .grey_image ,
84- "name" : "Image 3" ,
85- "owner_model" : "stock.lot" ,
86- }
87- )
92+ Command .create (self ._get_image_vals ("Image 3" , self .grey_image ))
8893 ]
8994 }
9095 )
0 commit comments