[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.

This commit is contained in:
KKamaa
2023-11-15 13:54:59 +03:00
committed by Tom Blauwendraat
parent f45deb03b7
commit 6e82fd7dd8
2 changed files with 29 additions and 0 deletions

View File

@@ -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

View File

@@ -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()