From ce72152679b242476ecec65779f85a2d792cb2f7 Mon Sep 17 00:00:00 2001 From: Dhaval Panchal Date: Fri, 28 Oct 2016 16:30:40 +0530 Subject: [PATCH] [IMP] sale_stock: sale order line quantity warning When you add a sale order line, odoo checks the available quantity through all warehouse and if you add more than available, you get a warning. We improved this warning, by checking the quantity in the warehouse set on the sale order, and if the quantity available in this warehouse is too low, we warn the user with the quantity available in this warehouse and in all other warehouses. --- addons/sale_stock/models/sale_order.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/addons/sale_stock/models/sale_order.py b/addons/sale_stock/models/sale_order.py index d39872a8a5a..313d7e1afaa 100644 --- a/addons/sale_stock/models/sale_order.py +++ b/addons/sale_stock/models/sale_order.py @@ -137,14 +137,21 @@ class SaleOrderLine(models.Model): return {} if self.product_id.type == 'product': precision = self.env['decimal.precision'].precision_get('Product Unit of Measure') + product = self.product_id.with_context(warehouse=self.order_id.warehouse_id.id) product_qty = self.product_uom._compute_quantity(self.product_uom_qty, self.product_id.uom_id) - if float_compare(self.product_id.virtual_available, product_qty, precision_digits=precision) == -1: + if float_compare(product.virtual_available, product_qty, precision_digits=precision) == -1: is_available = self._check_routing() if not is_available: + message = _('You plan to sell %s %s but you only have %s %s available in %s warehouse.') % \ + (self.product_uom_qty, self.product_uom.name, product.virtual_available, product.uom_id.name, self.order_id.warehouse_id.name) + # We check if some products are available in other warehouses. + if float_compare(product.virtual_available, self.product_id.virtual_available, precision_digits=precision) == -1: + message += _('\nThere are %s %s available accross all warehouses.') % \ + (self.product_id.virtual_available, product.uom_id.name) + warning_mess = { 'title': _('Not enough inventory!'), - 'message' : _('You plan to sell %s %s but you only have %s %s available!\nThe stock on hand is %s %s.') % \ - (self.product_uom_qty, self.product_uom.name, self.product_id.virtual_available, self.product_id.uom_id.name, self.product_id.qty_available, self.product_id.uom_id.name) + 'message' : message } return {'warning': warning_mess} return {}