From 849d8ffd2193db2001626e455ed86a96bf1cddb7 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Fri, 5 Jan 2018 14:52:55 +0100 Subject: [PATCH] [FIX] sale: protect SO if done Prevent the modification of the SO line if the SO is locked. opw-803439 --- addons/sale/models/sale.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index 947aa121a89..3c60e7cb0d9 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -729,6 +729,18 @@ class SaleOrderLine(models.Model): msg += _("Invoiced Quantity") + ": %s
" % (line.qty_invoiced,) msg += "" order.message_post(body=msg) + + # Prevent writing on a locked SO. + protected_fields = self._get_protected_fields() + if 'done' in self.mapped('order_id.state') and any(f in values.keys() for f in protected_fields): + fields = self.env['ir.model.fields'].search([ + ('name', 'in', protected_fields), ('model', '=', self._name) + ]) + raise UserError( + _('It is forbidden to modify the following fields in a locked order:\n%s') + % '\n'.join(fields.mapped('field_description')) + ) + result = super(SaleOrderLine, self).write(values) if lines: lines._action_procurement_create() @@ -984,6 +996,12 @@ class SaleOrderLine(models.Model): return product[field_name] * uom_factor * cur_factor, currency_id.id + def _get_protected_fields(self): + return [ + 'product_id', 'name', 'price_unit', 'product_uom', 'product_uom_qty', + 'tax_id', 'analytic_tag_ids' + ] + @api.onchange('product_id', 'price_unit', 'product_uom', 'product_uom_qty', 'tax_id') def _onchange_discount(self): self.discount = 0.0