Skip to content

Commit 97cfb77

Browse files
committed
Merge PR #909 into 18.0
Signed-off-by JordiBForgeFlow
2 parents 53d8e3e + d97225d commit 97cfb77

2 files changed

Lines changed: 57 additions & 2 deletions

File tree

product_multi_company_stock/models/product_template.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ class ProductTemplate(models.Model):
1313
def _check_company_ids(self):
1414
for record in self:
1515
if record.company_ids:
16+
variants = record.with_context(active_test=False).product_variant_ids
1617
quants = self.env["stock.quant"].search(
1718
[
18-
("product_id", "in", record.product_variant_ids.ids),
19+
("product_id", "in", variants.ids),
1920
("company_id", "not in", record.company_ids.ids),
2021
("quantity", "!=", 0),
2122
("location_id.usage", "=", "internal"),
@@ -33,7 +34,7 @@ def _check_company_ids(self):
3334
)
3435
moves = self.env["stock.move"].search(
3536
[
36-
("product_id", "in", record.product_variant_ids.ids),
37+
("product_id", "in", variants.ids),
3738
("company_id", "not in", record.company_ids.ids),
3839
]
3940
)

product_multi_company_stock/tests/test_product_multi_company_stock.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)