mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[IMP] Use constraint decorator on account_constraints+
This commit is contained in:
@@ -18,25 +18,20 @@
|
|||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
from openerp import models, api
|
from openerp import models, api, exceptions, _
|
||||||
|
|
||||||
|
|
||||||
class AccountMove(models.Model):
|
class AccountMove(models.Model):
|
||||||
_inherit = "account.move"
|
_inherit = "account.move"
|
||||||
|
|
||||||
@api.multi
|
@api.constrains('journal_id', 'period_id', 'date')
|
||||||
def _check_fiscal_year(self):
|
def _check_fiscal_year(self):
|
||||||
for move in self:
|
for move in self:
|
||||||
if move.journal_id.allow_date_fy:
|
if move.journal_id.allow_date_fy:
|
||||||
date_start = move.period_id.fiscalyear_id.date_start
|
date_start = move.period_id.fiscalyear_id.date_start
|
||||||
date_stop = move.period_id.fiscalyear_id.date_stop
|
date_stop = move.period_id.fiscalyear_id.date_stop
|
||||||
if not date_start <= move.date <= 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
|
return True
|
||||||
|
|
||||||
_constraints = [
|
|
||||||
(_check_fiscal_year,
|
|
||||||
'You cannot create entries with date not in the '
|
|
||||||
'fiscal year of the chosen period',
|
|
||||||
['line_id']),
|
|
||||||
]
|
|
||||||
|
|||||||
Reference in New Issue
Block a user