From f6ee398deb936aae009baee68882ca7d023a36a2 Mon Sep 17 00:00:00 2001 From: Adrien Widart Date: Wed, 4 May 2022 07:57:57 +0000 Subject: [PATCH] [FIX] purchase_stock: trigger RR with a defined supplied In a 2-steps configuration, trigger a reordering rule with the vendor defined will raise an error To reproduce the issue: 1. In Settings, enable "Multi-Step Routes" 2. Edit the existing warehouse: - Incoming Shipments: 2 steps 3. Create a product P: - Type: Storable - Add a vendor V - Routes: Buy 4. Create a reordering rule R for P: - Trigger: Manual - Min = Max = 1 5. Open the Replenishment page and edit R: - Preferred Route: Buy - Vendor: V 6. Trigger the orderpoint Error: An Odoo Server Error is displayed "AttributeError: 'product.supplierinfo' object has no attribute 'name'" When triggering the orderpoint, it leads to https://github.com/odoo/odoo/blob/c75a1a8ac9eef6c7d7c95b7bbbb22d919b952e26/addons/purchase_stock/models/stock_rule.py#L331 However, since [1], the `name` of a `product.supplierinfo` has been renamed to `partner_id` [1] f3fe2d50d99698eb0261c2309bd63f9f64b3d703 OPW-2780562 closes odoo/odoo#90597 X-original-commit: bda8b0e610f7ec9b0bcb76de3bb52fb6049f62ff Signed-off-by: Arnold Moyaux Signed-off-by: Adrien Widart --- addons/purchase_stock/models/stock_rule.py | 2 +- .../tests/test_reordering_rule.py | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/addons/purchase_stock/models/stock_rule.py b/addons/purchase_stock/models/stock_rule.py index 18d8a1f528b..bda7561d6cb 100644 --- a/addons/purchase_stock/models/stock_rule.py +++ b/addons/purchase_stock/models/stock_rule.py @@ -328,6 +328,6 @@ class StockRule(models.Model): if values.get('supplierinfo_name'): move_values['restrict_partner_id'] = values['supplierinfo_name'].id elif values.get('supplierinfo_id'): - partner = values['supplierinfo_id'].name + partner = values['supplierinfo_id'].partner_id move_values['restrict_partner_id'] = partner.id return move_values diff --git a/addons/purchase_stock/tests/test_reordering_rule.py b/addons/purchase_stock/tests/test_reordering_rule.py index caa557b4e1b..9b8eb9dbd13 100644 --- a/addons/purchase_stock/tests/test_reordering_rule.py +++ b/addons/purchase_stock/tests/test_reordering_rule.py @@ -656,3 +656,29 @@ class TestReorderingRule(TransactionCase): {'product_id': self.product_01.id, 'qty_done': 1.0, 'state': 'done', 'location_dest_id': stock_location.id}, {'product_id': self.product_01.id, 'qty_done': 2.0, 'state': 'done', 'location_dest_id': sub_location.id}, ]) + + def test_2steps_and_partner_on_orderpoint(self): + """ + Suppose a 2-steps receipt + This test ensures that an orderpoint with its route and supplied defined correctly works + """ + warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)]) + route_buy_id = self.ref('purchase_stock.route_warehouse0_buy') + + warehouse.reception_steps = 'two_steps' + + orderpoint = self.env['stock.warehouse.orderpoint'].create({ + 'name': 'RR for %s' % self.product_01.name, + 'warehouse_id': warehouse.id, + 'location_id': warehouse.lot_stock_id.id, + 'trigger': 'manual', + 'product_id': self.product_01.id, + 'product_min_qty': 1, + 'product_max_qty': 5, + 'route_id': route_buy_id, + 'supplier_id': self.product_01.seller_ids.id, + }) + orderpoint.action_replenish() + + po_line = self.env['purchase.order.line'].search([('partner_id', '=', self.partner.id), ('product_id', '=', self.product_01.id)]) + self.assertEqual(po_line.product_qty, 5)