diff --git a/addons/account/models/product.py b/addons/account/models/product.py index 61cbe55803..02aef9842b 100644 --- a/addons/account/models/product.py +++ b/addons/account/models/product.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from flectra import api, fields, models, _ +from flectra.exceptions import ValidationError ACCOUNT_DOMAIN = "[('deprecated', '=', False), ('internal_type','=','other'), ('company_id', '=', current_company_id), ('is_off_balance', '=', False)]" @@ -53,6 +54,12 @@ class ProductTemplate(models.Model): fiscal_pos = self.env['account.fiscal.position'] return fiscal_pos.map_accounts(accounts) + @api.constrains('uom_id') + def _check_uom_not_in_invoice(self): + for template in self: + invoices = self.env['account.move.line'].sudo().search([('product_id.product_tmpl_id.id', '=', template.id)], limit=1) + if invoices: + raise ValidationError(_('The product "%s" is used in invoices. You cannot change its Unit of Measure.', self.display_name)) class ProductProduct(models.Model): _inherit = "product.product" diff --git a/addons/account/views/account_move_views.xml b/addons/account/views/account_move_views.xml index d6b02a387c..938f70227f 100644 --- a/addons/account/views/account_move_views.xml +++ b/addons/account/views/account_move_views.xml @@ -706,20 +706,27 @@