From d38f916cd82db0b52f55991ac68dd863fbdfd8d9 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Fri, 20 Nov 2015 11:08:10 +0100 Subject: [PATCH] [IMP] purchase, product: suggest minimum quantity for vendor This commit introduces the suggestion of a minimum quantity for the chosen vendor. The minimum quantity is suggested only if the quantity on the line is zero. It still allows the user to set a quantity smaller than the minimum quantity for the given vendor. opw-654300 --- addons/product/product.py | 2 +- addons/purchase/purchase.py | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/addons/product/product.py b/addons/product/product.py index 798d8101565..ce5ad1af2d5 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -925,7 +925,7 @@ class product_product(osv.osv): continue if partner_id and seller.name not in [partner_id, partner_id.parent_id]: continue - if quantity_uom_seller and quantity_uom_seller < seller.qty: + if quantity_uom_seller < seller.qty: continue if seller.product_id and seller.product_id != product_id: continue diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index 45c60a77f43..e65a821590a 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -440,7 +440,7 @@ class PurchaseOrderLine(models.Model): line.qty_received = total name = fields.Text(string='Description', required=True) - product_qty = fields.Float(string='Quantity', digits=dp.get_precision('Product Unit of Measure'), required=True, default=1.0) + product_qty = fields.Float(string='Quantity', digits=dp.get_precision('Product Unit of Measure'), required=True) date_planned = fields.Datetime(string='Scheduled Date', required=True, select=True) taxes_id = fields.Many2many('account.tax', string='Taxes') product_uom = fields.Many2one('product.uom', string='Product Unit of Measure', required=True) @@ -581,6 +581,14 @@ class PurchaseOrderLine(models.Model): self.date_planned = self._get_date_planned(seller).strftime(DEFAULT_SERVER_DATETIME_FORMAT) if not seller: + if not self.product_qty: + # Suggest a minimum quantity if possible + seller_min_qty = self.product_id.seller_ids\ + .filtered(lambda r: r.name == self.order_id.partner_id)\ + .sorted(key=lambda r: r.min_qty) + if seller_min_qty: + self.product_qty = seller_min_qty[0].min_qty + self.product_uom = seller_min_qty[0].product_uom return result fpos = self.order_id.fiscal_position_id