sale_order_route: take into account the scenario where route_id has a value, then SO is cancelled+back to draft, then route_id = False and SO is confirmed again

This commit is contained in:
Alexis de Lattre
2020-02-13 10:55:25 +01:00
parent 53f6ab5d0f
commit 12bd157ad4

View File

@@ -10,13 +10,17 @@ class SaleOrder(models.Model):
route_id = fields.Many2one(
'stock.location.route', string='Route',
ondelete='restrict', readonly=True,
ondelete='restrict', readonly=True, track_visibility='onchange',
states={'draft': [('readonly', False)], 'sent': [('readonly', False)]},
domain=[('sale_selectable', '=', True)])
def _action_confirm(self):
for order in self.filtered(lambda o: o.route_id):
# Caution: take into account the scenario where
# route_id has a value, then SO is cancelled+back to draft,
# then route_id = False and SO is confirmed again
for order in self:
vals = {'route_id': order.route_id.id or False}
order.order_line.filtered(
lambda l: l.product_id.type in ('product', 'consu')).write(
{'route_id': order.route_id.id})
lambda l:
l.product_id.type in ('product', 'consu')).write(vals)
super(SaleOrder, self)._action_confirm()