
from openerp import models, api


class AccountMove(models.Model):
    _inherit = "account.move"

    @api.multi
    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
        return True

    _constraints = [
        (_check_fiscal_year,
            'You cannot create entries with date not in the '
            'fiscal year of the chosen period',
            ['line_id']),
    ]


from openerp import models, api, exceptions, _


class AccountMove(models.Model):
    _inherit = "account.move"

    @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:
                    raise exceptions.Warning(
                        _('You cannot create entries with date not in the '
                          'fiscal year of the chosen period'))
        return True

Use constraint decorator on account_constraints+
[IMP] Use constraint decorator on account_constraints+

  
- 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']),
-     ]
- 
Use constraint decorator on account_constraints+
## Code Before:

from openerp import models, api


class AccountMove(models.Model):
    _inherit = "account.move"

    @api.multi
    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
        return True

    _constraints = [
        (_check_fiscal_year,
            'You cannot create entries with date not in the '
            'fiscal year of the chosen period',
            ['line_id']),
    ]

## Instruction:
Use constraint decorator on account_constraints+
## Code After:

from openerp import models, api, exceptions, _


class AccountMove(models.Model):
    _inherit = "account.move"

    @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:
                    raise exceptions.Warning(
                        _('You cannot create entries with date not in the '
                          'fiscal year of the chosen period'))
        return True
