[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
This commit is contained in:
amoyaux
2017-09-08 17:08:08 +02:00
parent f50d732373
commit c1dace134d
2 changed files with 8 additions and 4 deletions
+7 -2
View File
@@ -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
+1 -2
View File
@@ -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,