diff --git a/account_constraints/model/account_move.py b/account_constraints/model/account_move.py index 3123cbf87..46d078faf 100644 --- a/account_constraints/model/account_move.py +++ b/account_constraints/model/account_move.py @@ -18,25 +18,20 @@ # ############################################################################## -from openerp import models, api +from openerp import models, api, exceptions, _ class AccountMove(models.Model): _inherit = "account.move" - @api.multi + @api.constrains('journal_id', 'period_id', 'date') def _check_fiscal_year(self): for move in self: if move.journal_id.allow_date_fy: date_start = move.period_id.fiscalyear_id.date_start date_stop = move.period_id.fiscalyear_id.date_stop if not date_start <= move.date <= date_stop: - return False + raise exceptions.Warning( + _('You cannot create entries with date not in the ' + 'fiscal year of the chosen period')) return True - - _constraints = [ - (_check_fiscal_year, - 'You cannot create entries with date not in the ' - 'fiscal year of the chosen period', - ['line_id']), - ]