From 6e82fd7dd8f9aab3ef6ebe5969692fa423de76f4 Mon Sep 17 00:00:00 2001 From: KKamaa Date: Wed, 15 Nov 2023 13:54:59 +0300 Subject: [PATCH] [14.0][FIX] mrp_sale_info: Fix regression introduced by #1009 resulting in AttributeError when values.get("move_dest_ids") is None. This happens for example when manufacturing order is not created from a sale order but from an orderpoint. A test case was added to cover this occurrence. --- mrp_sale_info/models/stock_rule.py | 2 ++ mrp_sale_info/tests/test_mrp_sale_info.py | 27 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/mrp_sale_info/models/stock_rule.py b/mrp_sale_info/models/stock_rule.py index 3e80bacd2..912e8ffb5 100644 --- a/mrp_sale_info/models/stock_rule.py +++ b/mrp_sale_info/models/stock_rule.py @@ -41,4 +41,6 @@ class StockRule(models.Model): moves = moves.move_dest_ids line_ids |= moves.sale_line_id res["sale_line_ids"] = line_ids and [(4, x.id) for x in line_ids] or False + return res # eg in case of orderpoint generating MO + line_ids = moves.sale_line_id return res diff --git a/mrp_sale_info/tests/test_mrp_sale_info.py b/mrp_sale_info/tests/test_mrp_sale_info.py index 09fb94294..6a9e7ccbc 100644 --- a/mrp_sale_info/tests/test_mrp_sale_info.py +++ b/mrp_sale_info/tests/test_mrp_sale_info.py @@ -21,9 +21,15 @@ class TestMrpSaleInfo(common.SavepointCase): ], } ) + cls.product_to_use = cls.env["product.product"].create( + {"name": "Material", "type": "product"} + ) cls.bom = cls.env["mrp.bom"].create( { "product_tmpl_id": cls.product.product_tmpl_id.id, + "bom_line_ids": [ + (0, 0, {"product_id": cls.product_to_use.id, "product_qty": 1.0}), + ], } ) cls.partner = cls.env["res.partner"].create({"name": "Test client"}) @@ -56,3 +62,24 @@ class TestMrpSaleInfo(common.SavepointCase): self.assertEqual(self.sale_order.mrp_production_count, 1) sale_action = self.sale_order.action_view_mrp_production() self.assertEqual(sale_action["res_id"], production.id) + production.action_confirm() + + def test_orderpoint(self): + """Test if orderpoint MO generation still works well""" + prev_productions = self.env["mrp.production"].search([]) + warehouse = self.env["stock.warehouse"].search([], limit=1) + orderpoint = self.env["stock.warehouse.orderpoint"].create( + { + "name": "replenish product", + "location_id": warehouse.lot_stock_id.id, + "product_id": self.product.id, + "product_min_qty": 10, + "product_max_qty": 100, + } + ) + orderpoint._procure_orderpoint_confirm( + company_id=orderpoint.company_id, raise_user_error=False + ) + production = self.env["mrp.production"].search([]) - prev_productions + self.assertEqual(len(production), 1) + production.action_confirm()