diff --git a/addons/account/models/account.py b/addons/account/models/account.py index c84c7d06911..e3c093991ed 100644 --- a/addons/account/models/account.py +++ b/addons/account/models/account.py @@ -93,7 +93,7 @@ class AccountAccount(models.Model): def _check_reconcile(self): for account in self: if account.internal_type in ('receivable', 'payable') and account.reconcile == False: - raise ValueError(_('You cannot have a receivable/payable account that is not reconciliable. (account code: %s)') % account.code) + raise ValidationError(_('You cannot have a receivable/payable account that is not reconciliable. (account code: %s)') % account.code) name = fields.Char(required=True, index=True) currency_id = fields.Many2one('res.currency', string='Account Currency', @@ -265,9 +265,9 @@ class AccountJournal(models.Model): def _check_currency(self): if self.currency_id: if self.default_credit_account_id and not self.default_credit_account_id.currency_id.id == self.currency_id.id: - raise UserError(_('Configuration error!\nThe currency of the journal should be the same than the default credit account.')) + raise ValidationError(_('Configuration error!\nThe currency of the journal should be the same than the default credit account.')) if self.default_debit_account_id and not self.default_debit_account_id.currency_id.id == self.currency_id.id: - raise UserError(_('Configuration error!\nThe currency of the journal should be the same than the default debit account.')) + raise ValidationError(_('Configuration error!\nThe currency of the journal should be the same than the default debit account.')) @api.one @api.constrains('type', 'bank_account_id') @@ -530,7 +530,7 @@ class AccountTax(models.Model): @api.constrains('children_tax_ids', 'type_tax_use') def _check_children_scope(self): if not all(child.type_tax_use in ('none', self.type_tax_use) for child in self.children_tax_ids): - raise UserError(_('The application scope of taxes in a group must be either the same as the group or "None".')) + raise ValidationError(_('The application scope of taxes in a group must be either the same as the group or "None".')) @api.one def copy(self, default=None): diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index ff79875cd28..ac5f6d5b534 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -1309,7 +1309,7 @@ class AccountPaymentTermLine(models.Model): @api.constrains('value', 'value_amount') def _check_percent(self): if self.value == 'percent' and (self.value_amount < 0.0 or self.value_amount > 100.0): - raise UserError(_('Percentages for Payment Term Line must be between 0 and 100.')) + raise ValidationError(_('Percentages for Payment Term Line must be between 0 and 100.')) @api.onchange('option') def _onchange_option(self): diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 07b0adcbc76..f1cbcd6fa17 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -4,7 +4,7 @@ import time from collections import OrderedDict from openerp import api, fields, models, _ from openerp.osv import expression -from openerp.exceptions import RedirectWarning, UserError +from openerp.exceptions import RedirectWarning, UserError, ValidationError from openerp.tools.misc import formatLang from openerp.tools import float_is_zero, float_compare from openerp.tools.safe_eval import safe_eval @@ -386,14 +386,14 @@ class AccountMoveLine(models.Model): for line in self: if line.account_id.currency_id: if not line.currency_id or line.currency_id.id != line.account_id.currency_id.id: - raise UserError(_('The selected account of your Journal Entry forces to provide a secondary currency. You should remove the secondary currency on the account.')) + raise ValidationError(_('The selected account of your Journal Entry forces to provide a secondary currency. You should remove the secondary currency on the account.')) @api.multi @api.constrains('currency_id', 'amount_currency') def _check_currency_and_amount(self): for line in self: if (line.amount_currency and not line.currency_id): - raise UserError(_("You cannot create journal items with a secondary currency without filling both 'currency' and 'amount currency' field.")) + raise ValidationError(_("You cannot create journal items with a secondary currency without filling both 'currency' and 'amount currency' field.")) @api.multi @api.constrains('amount_currency') @@ -401,7 +401,7 @@ class AccountMoveLine(models.Model): for line in self: if line.amount_currency: if (line.amount_currency > 0.0 and line.credit > 0.0) or (line.amount_currency < 0.0 and line.debit > 0.0): - raise UserError(_('The amount expressed in the secondary currency must be positive when account is debited and negative when account is credited.')) + raise ValidationError(_('The amount expressed in the secondary currency must be positive when account is debited and negative when account is credited.')) #################################################### # Reconciliation interface methods diff --git a/addons/event/models/event.py b/addons/event/models/event.py index 03bc96d1d1a..a60e06842a8 100644 --- a/addons/event/models/event.py +++ b/addons/event/models/event.py @@ -3,7 +3,7 @@ import pytz from openerp import _, api, fields, models -from openerp.exceptions import AccessError, UserError +from openerp.exceptions import AccessError, UserError, ValidationError class event_type(models.Model): """ Event Type """ @@ -196,13 +196,13 @@ class event_event(models.Model): @api.constrains('seats_max', 'seats_available') def _check_seats_limit(self): if self.seats_availability == 'limited' and self.seats_max and self.seats_available < 0: - raise UserError(_('No more available seats.')) + raise ValidationError(_('No more available seats.')) @api.one @api.constrains('date_begin', 'date_end') def _check_closing_date(self): if self.date_end < self.date_begin: - raise UserError(_('Closing Date cannot be set before Beginning Date.')) + raise ValidationError(_('Closing Date cannot be set before Beginning Date.')) @api.model def create(self, vals): @@ -296,7 +296,7 @@ class event_registration(models.Model): @api.constrains('event_id', 'state') def _check_seats_limit(self): if self.event_id.seats_availability == 'limited' and self.event_id.seats_max and self.event_id.seats_available < (1 if self.state == 'draft' else 0): - raise UserError(_('No more seats available for this event.')) + raise ValidationError(_('No more seats available for this event.')) @api.multi def _check_auto_confirmation(self): diff --git a/addons/event_sale/models/event.py b/addons/event_sale/models/event.py index 94bed87bed3..c54bde9eb24 100644 --- a/addons/event_sale/models/event.py +++ b/addons/event_sale/models/event.py @@ -2,7 +2,7 @@ from openerp import models, fields, api, _ import openerp.addons.decimal_precision as dp -from openerp.exceptions import UserError +from openerp.exceptions import ValidationError from openerp.osv import fields as old_fields @@ -128,7 +128,7 @@ class event_ticket(models.Model): @api.constrains('registration_ids', 'seats_max') def _check_seats_limit(self): if self.seats_max and self.seats_available < 0: - raise UserError(_('No more available seats for the ticket')) + raise ValidationError(_('No more available seats for the ticket')) @api.onchange('product_id') def onchange_product_id(self): @@ -150,7 +150,7 @@ class event_registration(models.Model): @api.constrains('event_ticket_id', 'state') def _check_ticket_seats_limit(self): if self.event_ticket_id.seats_max and self.event_ticket_id.seats_available < 0: - raise UserError(_('No more available seats for this ticket')) + raise ValidationError(_('No more available seats for this ticket')) @api.multi def _check_auto_confirmation(self): diff --git a/addons/lunch/models/lunch.py b/addons/lunch/models/lunch.py index c4906072ad9..cb6e886a75c 100644 --- a/addons/lunch/models/lunch.py +++ b/addons/lunch/models/lunch.py @@ -4,7 +4,7 @@ import datetime from openerp import models, fields, api, _ import openerp.addons.decimal_precision as dp -from openerp.exceptions import AccessError, UserError +from openerp.exceptions import AccessError, ValidationError class LunchOrder(models.Model): @@ -95,7 +95,7 @@ class LunchOrder(models.Model): date_order = datetime.datetime.strptime(self.date, '%Y-%m-%d') date_today = datetime.datetime.strptime(fields.Date.context_today(self), '%Y-%m-%d') if (date_order < date_today): - raise UserError(_('The date of your order is in the past.')) + raise ValidationError(_('The date of your order is in the past.')) @api.one @api.depends('order_line_ids.state') diff --git a/addons/mail/models/mail_alias.py b/addons/mail/models/mail_alias.py index 5581607de18..d15b072b9d4 100644 --- a/addons/mail/models/mail_alias.py +++ b/addons/mail/models/mail_alias.py @@ -5,7 +5,7 @@ import re import unicodedata from openerp import _, api, fields, models, SUPERUSER_ID -from openerp.exceptions import UserError +from openerp.exceptions import ValidationError from openerp.modules.registry import RegistryManager from openerp.tools import ustr from openerp.tools.safe_eval import safe_eval as eval @@ -96,7 +96,7 @@ class Alias(models.Model): try: dict(eval(self.alias_defaults)) except Exception: - raise UserError(_('Invalid expression, it must be a literal python dictionary definition e.g. "{\'field\': \'value\'}"')) + raise ValidationError(_('Invalid expression, it must be a literal python dictionary definition e.g. "{\'field\': \'value\'}"')) @api.model def create(self, vals): diff --git a/addons/sale_timesheet/models/sale_timesheet.py b/addons/sale_timesheet/models/sale_timesheet.py index e2cdbc0efed..37e0f01ceab 100644 --- a/addons/sale_timesheet/models/sale_timesheet.py +++ b/addons/sale_timesheet/models/sale_timesheet.py @@ -4,7 +4,7 @@ from openerp import models, api, fields from openerp.tools.translate import _ -from openerp.exceptions import UserError +from openerp.exceptions import ValidationError class ResCompany(models.Model): @@ -131,7 +131,7 @@ class SaleOrder(models.Model): if line.product_id.track_service == 'timesheet': count += 1 if count > 1: - raise UserError(_("You can use only one product on timesheet within the same sale order. You should split your order to include only one contract based on time and material.")) + raise ValidationError(_("You can use only one product on timesheet within the same sale order. You should split your order to include only one contract based on time and material.")) return {} @api.multi diff --git a/addons/website_forum/models/forum.py b/addons/website_forum/models/forum.py index 4189921f0d6..33be8629dd5 100644 --- a/addons/website_forum/models/forum.py +++ b/addons/website_forum/models/forum.py @@ -15,7 +15,7 @@ from openerp import modules from openerp import tools from openerp import SUPERUSER_ID from openerp.addons.website.models.website import slug -from openerp.exceptions import UserError +from openerp.exceptions import UserError, ValidationError _logger = logging.getLogger(__name__) @@ -139,7 +139,7 @@ class Forum(models.Model): if (self.default_post_type == 'question' and not self.allow_question) \ or (self.default_post_type == 'discussion' and not self.allow_discussion) \ or (self.default_post_type == 'link' and not self.allow_link): - raise UserError(_('You cannot choose %s as default post since the forum does not allow it.') % self.default_post_type) + raise ValidationError(_('You cannot choose %s as default post since the forum does not allow it.') % self.default_post_type) @api.one def _compute_count_posts_waiting_validation(self): @@ -414,7 +414,7 @@ class Post(models.Model): if (self.post_type == 'question' and not self.forum_id.allow_question) \ or (self.post_type == 'discussion' and not self.forum_id.allow_discussion) \ or (self.post_type == 'link' and not self.forum_id.allow_link): - raise UserError(_('This forum does not allow %s') % self.post_type) + raise ValidationError(_('This forum does not allow %s') % self.post_type) def _update_content(self, content, forum_id): forum = self.env['forum.forum'].browse(forum_id) diff --git a/openerp/addons/base/ir/ir_model.py b/openerp/addons/base/ir/ir_model.py index 91d8cf15c12..9138b658e1d 100644 --- a/openerp/addons/base/ir/ir_model.py +++ b/openerp/addons/base/ir/ir_model.py @@ -275,9 +275,9 @@ class IrModelFields(models.Model): if self.state == 'manual' and self.related: field = self._related_field() if field.type != self.ttype: - raise UserError(_("Related field '%s' does not have type '%s'") % (self.related, self.ttype)) + raise ValidationError(_("Related field '%s' does not have type '%s'") % (self.related, self.ttype)) if field.relational and field.comodel_name != self.relation: - raise UserError(_("Related field '%s' does not have comodel '%s'") % (self.related, self.relation)) + raise ValidationError(_("Related field '%s' does not have comodel '%s'") % (self.related, self.relation)) @api.onchange('related') def _onchange_related(self): diff --git a/openerp/addons/test_new_api/models.py b/openerp/addons/test_new_api/models.py index e39135c89fc..41264e71e37 100644 --- a/openerp/addons/test_new_api/models.py +++ b/openerp/addons/test_new_api/models.py @@ -157,7 +157,7 @@ class Message(models.Model): @api.constrains('author', 'discussion') def _check_author(self): if self.discussion and self.author not in self.discussion.participants: - raise ValueError(_("Author must be among the discussion participants.")) + raise ValidationError(_("Author must be among the discussion participants.")) @api.one @api.depends('author.name', 'discussion.name') diff --git a/openerp/models.py b/openerp/models.py index e45adf7f859..3628b0c652b 100644 --- a/openerp/models.py +++ b/openerp/models.py @@ -109,9 +109,9 @@ def raise_on_invalid_object_name(name): def check_pg_name(name): """ Check whether the given name is a valid PostgreSQL identifier name. """ if not regex_pg_name.match(name): - raise ValueError("Invalid characters in table name %r" % name) + raise ValidationError("Invalid characters in table name %r" % name) if len(name) > 63: - raise ValueError("Table name %r is too long" % name) + raise ValidationError("Table name %r is too long" % name) POSTGRES_CONFDELTYPES = { 'RESTRICT': 'r',