@@ -62,3 +62,57 @@ def test_remove_company_with_quants_or_moves(self):
6262 with self .assertRaises (UserError ) as error_move :
6363 product .write ({"company_ids" : [(6 , 0 , [self .company_2 .id ])]})
6464 self .assertIn ("stock moves" , str (error_move .exception ))
65+
66+ def test_remove_company_with_quants_or_moves_archived_product (self ):
67+ product = self .env ["product.product" ].create (
68+ {
69+ "name" : "Test Product" ,
70+ "is_storable" : True ,
71+ "company_ids" : [(6 , 0 , [self .company_1 .id , self .company_2 .id ])],
72+ "active" : False ,
73+ }
74+ )
75+ internal_loc = self .env ["stock.location" ].create (
76+ {
77+ "name" : "Test Internal Location" ,
78+ "usage" : "internal" ,
79+ "company_id" : self .company_1 .id ,
80+ }
81+ )
82+ dest_loc = self .env ["stock.location" ].create (
83+ {
84+ "name" : "Test Customer Location" ,
85+ "usage" : "customer" ,
86+ "company_id" : self .company_1 .id ,
87+ }
88+ )
89+ quant = self .env ["stock.quant" ].create (
90+ {
91+ "product_id" : product .id ,
92+ "location_id" : internal_loc .id ,
93+ "company_id" : self .company_1 .id ,
94+ "quantity" : 10 ,
95+ }
96+ )
97+ with self .assertRaises (UserError ) as error_quant :
98+ product .write ({"company_ids" : [(6 , 0 , [self .company_2 .id ])]})
99+ self .assertIn ("stock quantities" , str (error_quant .exception ))
100+ quant .unlink ()
101+ move = self .env ["stock.move" ].create (
102+ {
103+ "name" : "Test Stock Move" ,
104+ "product_id" : product .id ,
105+ "product_uom_qty" : 10 ,
106+ "product_uom" : product .uom_id .id ,
107+ "location_id" : internal_loc .id ,
108+ "location_dest_id" : dest_loc .id ,
109+ "company_id" : self .company_1 .id ,
110+ }
111+ )
112+
113+ move ._action_confirm ()
114+ move ._action_assign ()
115+ move ._action_done ()
116+ with self .assertRaises (UserError ) as error_move :
117+ product .write ({"company_ids" : [(6 , 0 , [self .company_2 .id ])]})
118+ self .assertIn ("stock moves" , str (error_move .exception ))
0 commit comments