diff --git a/addons/product/models/product.py b/addons/product/models/product.py index 9cbca007a4b..d3680c4f1e5 100644 --- a/addons/product/models/product.py +++ b/addons/product/models/product.py @@ -659,7 +659,7 @@ class ProductProduct(models.Model): continue if partner_id and seller.name not in [partner_id, partner_id.parent_id]: continue - if float_compare(quantity_uom_seller, seller.min_qty, precision_digits=precision) == -1: + if quantity is not None and float_compare(quantity_uom_seller, seller.min_qty, precision_digits=precision) == -1: continue if seller.product_id and seller.product_id != self: continue diff --git a/addons/purchase_stock/models/stock_rule.py b/addons/purchase_stock/models/stock_rule.py index b9c5fbd7cdf..6cf956b8fb5 100644 --- a/addons/purchase_stock/models/stock_rule.py +++ b/addons/purchase_stock/models/stock_rule.py @@ -150,7 +150,7 @@ class StockRule(models.Model): delay, delay_description = super()._get_lead_days(product, **values) bypass_delay_description = self.env.context.get('bypass_delay_description') buy_rule = self.filtered(lambda r: r.action == 'buy') - seller = 'supplierinfo' in values and values['supplierinfo'] or product.with_company(buy_rule.company_id)._select_seller() + seller = 'supplierinfo' in values and values['supplierinfo'] or product.with_company(buy_rule.company_id)._select_seller(quantity=None) if not buy_rule or not seller: return delay, delay_description buy_rule.ensure_one() diff --git a/addons/purchase_stock/tests/test_purchase_lead_time.py b/addons/purchase_stock/tests/test_purchase_lead_time.py index 486dbefe270..886b519ee39 100644 --- a/addons/purchase_stock/tests/test_purchase_lead_time.py +++ b/addons/purchase_stock/tests/test_purchase_lead_time.py @@ -339,3 +339,28 @@ class TestPurchaseLeadTime(PurchaseTestCommon): self.assertEqual(fields.Date.to_date(new_order.date_order), fields.Date.today() + timedelta(days=2)) self.assertEqual(new_order.order_line.product_uom_qty, 5.0) self.patcher.stop() + + def test_supplier_lead_time(self): + """ Basic stock configuration and a supplier with a minimum qty and a lead time """ + self.env['stock.warehouse.orderpoint'].search([]).unlink() + orderpoint_form = Form(self.env['stock.warehouse.orderpoint']) + orderpoint_form.product_id = self.product_1 + orderpoint_form.product_min_qty = 10 + orderpoint_form.product_max_qty = 50 + orderpoint_form.save() + + self.env['product.supplierinfo'].search([('product_tmpl_id', '=', self.product_1.product_tmpl_id.id)]).unlink() + self.env['product.supplierinfo'].create({ + 'name': self.partner_1.id, + 'min_qty': 1, + 'price': 1, + 'delay': 7, + 'product_tmpl_id': self.product_1.product_tmpl_id.id, + }) + + self.env['procurement.group'].run_scheduler() + purchase_order = self.env['purchase.order'].search([('partner_id', '=', self.partner_1.id)]) + + today = fields.Datetime.start_of(fields.Datetime.now(), 'day') + self.assertEqual(purchase_order.date_order, today) + self.assertEqual(fields.Datetime.start_of(purchase_order.date_planned, 'day'), today + timedelta(days=7))