[IMP] Use constraint decorator on account_constraints+

This commit is contained in:
Adrien Peiffer
2014-11-19 09:23:25 +01:00
parent 3ff24e8099
commit 727702d6d5

View File

@@ -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']),
]