Skip to content

Commit

Permalink
[REF] account: externilize fiscal year validation
Browse files Browse the repository at this point in the history
create _validate_fiscalyear() method in res.company
so that it is easier to inherit to modify or extend its
functionality.
  • Loading branch information
Esteban Echeverry committed Apr 24, 2017
1 parent ec8699d commit 9f11b2a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions addons/account/models/company.py
Expand Up @@ -80,15 +80,20 @@ def reflect_code_digits_change(self, digits):
account.write({'code': account.code.rstrip('0').ljust(digits, '0')})

@api.multi
def write(self, values):
#restrict the closing of FY if there are still unposted entries
def _validate_fiscalyear(self, values):
if values.get('fiscalyear_lock_date'):
nb_draft_entries = self.env['account.move'].search([
('company_id', 'in', [c.id for c in self]),
('state', '=', 'draft'),
('date', '<=', values['fiscalyear_lock_date'])])
if nb_draft_entries:
raise ValidationError(_('There are still unposted entries in the period you want to lock. You should either post or delete them.'))

@api.multi
def write(self, values):
#restrict the closing of FY if there are still unposted entries
self._validate_fiscalyear(values)

# Reflect the change on accounts
for company in self:
digits = values.get('accounts_code_digits') or company.accounts_code_digits
Expand Down

0 comments on commit 9f11b2a

Please sign in to comment.