From dc733ce3cd34cac801c9ea32a07b7ab03628976e Mon Sep 17 00:00:00 2001 From: Djamel Touati Date: Mon, 5 Feb 2024 15:14:57 +0000 Subject: [PATCH] [FIX] purchase_stock: set the supplier with their qty in orderpoint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce the bug: - Create a storable product: - Unit of Measure: KG - Purchase UoM: Tonne - Vendor: “Azure Interior” Quantity: 6T - Recording rule: Min quantity= 500 - Trigger: Manual - Route: Buy - Go to the replenishment page: - Click on the “i” icon - On the Azure Interior line, click on “Set as supplier” Problem: The quantity to order is not updated to 6000 kg because in the "action_set_supplier" function, we compare the quantity of the supplier information with the quantity of the orderpoint without converting the values to the same UoM. So: 500 < 6 → False Therefore, the quantity is not updated. Opw-3705090 closes odoo/odoo#153300 X-original-commit: 9c0550a223b155e4e0859f87d94c1229b53c824a Signed-off-by: William Henrotin (whe) Signed-off-by: Djamel Touati (otd) --- addons/purchase_stock/models/product.py | 5 ++-- .../tests/test_reordering_rule.py | 28 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/addons/purchase_stock/models/product.py b/addons/purchase_stock/models/product.py index 025418d3ab2..725b96f4646 100644 --- a/addons/purchase_stock/models/product.py +++ b/addons/purchase_stock/models/product.py @@ -128,8 +128,9 @@ class SupplierInfo(models.Model): return orderpoint.route_id = self.env['stock.rule'].search([('action', '=', 'buy')], limit=1).route_id.id orderpoint.supplier_id = self - if orderpoint.qty_to_order < self.min_qty: - orderpoint.qty_to_order = self.min_qty + supplier_min_qty = self.product_uom._compute_quantity(self.min_qty, orderpoint.product_id.uom_id) + if orderpoint.qty_to_order < supplier_min_qty: + orderpoint.qty_to_order = supplier_min_qty if self._context.get('replenish_id'): replenish = self.env['product.replenish'].browse(self._context.get('replenish_id')) replenish.supplier_id = self diff --git a/addons/purchase_stock/tests/test_reordering_rule.py b/addons/purchase_stock/tests/test_reordering_rule.py index ca10bbccce8..722de3b3c16 100644 --- a/addons/purchase_stock/tests/test_reordering_rule.py +++ b/addons/purchase_stock/tests/test_reordering_rule.py @@ -1019,3 +1019,31 @@ class TestReorderingRule(TransactionCase): picking.with_user(user).action_assign() # check that the PO line quantity has been updated self.assertEqual(po_line.product_qty, 6, 'The PO line quantity should be 6') + + def test_set_supplier_in_orderpoint(self): + """ + Test that qty_to_order is correctly computed when setting the supplier in an orderpoint + Have a product with a uom in Kg and a purchase uom in Tonne (the purchase UOM should be bigger that the UOM) + and a supplier with a min_qty of 6T + Create an orderpoint with a min_qty of 500Kg and a max_qty of 0Kg + Set the supplier in the orderpoint and check that the qty_to_order is correctly updated to 6000Kg + """ + product = self.env['product.product'].create({ + 'name': 'Storable Product', + 'type': 'product', + 'uom_id': self.env.ref('uom.product_uom_categ_kgm').uom_ids[3].id, + 'uom_po_id': self.env.ref('uom.product_uom_categ_kgm').uom_ids[4].id, + 'seller_ids': [(0, 0, {'partner_id': self.partner.id, 'min_qty': 6})], + }) + warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1) + orderpoint = self.env['stock.warehouse.orderpoint'].create({ + 'warehouse_id': warehouse.id, + 'location_id': warehouse.lot_stock_id.id, + 'product_id': product.id, + 'product_min_qty': 500, + 'product_max_qty': 0, + }) + product.seller_ids.with_context(orderpoint_id=orderpoint.id).action_set_supplier() + self.assertEqual(orderpoint.supplier_id, product.seller_ids, 'The supplier should be set in the orderpoint') + self.assertEqual(orderpoint.product_uom, product.uom_id, 'The orderpoint uom should be the same as the product uom') + self.assertEqual(orderpoint.qty_to_order, 6000)