From 6524b7965281af324179b8a6ef6f45e175961665 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Fri, 5 Apr 2019 08:17:05 +0000 Subject: [PATCH] [FIX] stock: constrains should raise ValidationError Before this commit, some constrains rose UserError Which is not compliant with the api.constrains After this commit, the constrains raise ValidationError OPW 1949572 closes odoo/odoo#32444 Signed-off-by: Lucas Perais (lpe) --- addons/stock/models/stock_inventory.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/addons/stock/models/stock_inventory.py b/addons/stock/models/stock_inventory.py index 5dacb1b5b25..2b4f077dabb 100644 --- a/addons/stock/models/stock_inventory.py +++ b/addons/stock/models/stock_inventory.py @@ -3,7 +3,7 @@ from odoo import api, fields, models, _ from odoo.addons import decimal_precision as dp -from odoo.exceptions import UserError +from odoo.exceptions import UserError, ValidationError from odoo.tools import float_utils @@ -148,13 +148,13 @@ class Inventory(models.Model): if self.filter == 'none' and self.product_id and self.location_id and self.lot_id: return if self.filter not in ('product', 'product_owner') and self.product_id: - raise UserError(_('The selected inventory options are not coherent.')) + raise ValidationError(_('The selected inventory options are not coherent.')) if self.filter != 'lot' and self.lot_id: - raise UserError(_('The selected inventory options are not coherent.')) + raise ValidationError(_('The selected inventory options are not coherent.')) if self.filter not in ('owner', 'product_owner') and self.partner_id: - raise UserError(_('The selected inventory options are not coherent.')) + raise ValidationError(_('The selected inventory options are not coherent.')) if self.filter != 'pack' and self.package_id: - raise UserError(_('The selected inventory options are not coherent.')) + raise ValidationError(_('The selected inventory options are not coherent.')) def action_reset_product_qty(self): self.mapped('line_ids').write({'product_qty': 0}) @@ -406,7 +406,7 @@ class InventoryLine(models.Model): """ for line in self: if line.product_id.type != 'product': - raise UserError(_("You can only adjust stockable products.") + '\n\n%s -> %s' % (line.product_id.display_name, line.product_id.type)) + raise ValidationError(_("You can only adjust stockable products.") + '\n\n%s -> %s' % (line.product_id.display_name, line.product_id.type)) def _get_quants(self): return self.env['stock.quant'].search([