From c1dace134dc349fa9dbdd045c61b6221ca2b87d4 Mon Sep 17 00:00:00 2001 From: amoyaux Date: Wed, 6 Sep 2017 17:12:09 +0200 Subject: [PATCH] [IMP] sale_stock: raise multiple error at the same time When a user confirm a sale order, he will have one error at a time. This is not user friendly since he has to correct the current error and confirm the sale order again in order to get the next mistake. This commit runs all procurement and catch raised error in order to display them all at once --- addons/sale_stock/models/sale_order.py | 9 +++++++-- addons/stock/models/procurement.py | 3 +-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/addons/sale_stock/models/sale_order.py b/addons/sale_stock/models/sale_order.py index 38ad7ff77a1..9f5d7f2a4ff 100644 --- a/addons/sale_stock/models/sale_order.py +++ b/addons/sale_stock/models/sale_order.py @@ -214,6 +214,7 @@ class SaleOrderLine(models.Model): depending on the sale order line product rule. """ precision = self.env['decimal.precision'].precision_get('Product Unit of Measure') + errors = [] for line in self: if line.state != 'sale' or not line.product_id.type in ('consu','product'): continue @@ -230,8 +231,12 @@ class SaleOrderLine(models.Model): }) values = line._prepare_procurement_values(group_id=line.order_id.procurement_group_id) product_qty = line.product_uom_qty - qty - - self.env['procurement.group'].run(line.product_id, product_qty, line.product_uom, line.order_id.partner_shipping_id.property_stock_customer, line.name, line.order_id.name, values) + try: + self.env['procurement.group'].run(line.product_id, product_qty, line.product_uom, line.order_id.partner_shipping_id.property_stock_customer, line.name, line.order_id.name, values) + except UserError as error: + errors.append(error.name) + if errors: + raise UserError('\n'.join(errors)) return True @api.multi diff --git a/addons/stock/models/procurement.py b/addons/stock/models/procurement.py index bcc9dcbd2c8..f3a43fbe083 100644 --- a/addons/stock/models/procurement.py +++ b/addons/stock/models/procurement.py @@ -80,7 +80,7 @@ class ProcurementRule(models.Model): # Since action_confirm launch following procurement_group we should activate it. move = self.env['stock.move'].sudo().create(data) move.assign_picking() - move.picking_id.action_confirm() + move.action_confirm() return True def _get_stock_move_values(self, product_id, product_qty, product_uom, location_id, name, origin, values, group_id): @@ -303,7 +303,6 @@ class ProcurementGroup(models.Model): 1000 orderpoints. This is appropriate for batch jobs only. """ - OrderPoint = self.env['stock.warehouse.orderpoint'] domain = self._get_orderpoint_domain(company_id=company_id) orderpoints_noprefetch = OrderPoint.with_context(prefetch_fields=False).search(domain,