[FIX] account: Don't lock a fiscal year with unprocessed statement lines
closes odoo/odoo#50227 Related: odoo/enterprise#10226 Signed-off-by: Quentin De Paoli (qdp) <qdp@openerp.com>
This commit is contained in:
@@ -227,6 +227,7 @@ class ResCompany(models.Model):
|
||||
|
||||
def _validate_fiscalyear_lock(self, values):
|
||||
if values.get('fiscalyear_lock_date'):
|
||||
|
||||
nb_draft_entries = self.env['account.move'].search([
|
||||
('company_id', 'in', self.ids),
|
||||
('state', '=', 'draft'),
|
||||
@@ -234,6 +235,15 @@ class ResCompany(models.Model):
|
||||
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.'))
|
||||
|
||||
has_unreconciled_statement_lines = self.env['account.bank.statement.line'].search_count([
|
||||
('company_id', 'in', self.ids),
|
||||
('is_reconciled', '=', False),
|
||||
])
|
||||
if has_unreconciled_statement_lines:
|
||||
raise ValidationError(_(
|
||||
"There are still unreconciled bank statement lines in the period you want to lock."
|
||||
"You should either reconcile or delete them."))
|
||||
|
||||
def _get_user_fiscal_lock_date(self):
|
||||
"""Get the fiscal lock date for this company depending on the user"""
|
||||
self.ensure_one()
|
||||
|
||||
@@ -142,6 +142,23 @@ class TestAccountMove(AccountTestInvoicingCommon):
|
||||
# The date has been changed to the first valid date.
|
||||
self.assertEqual(copy_move.date, copy_move.company_id.fiscalyear_lock_date + relativedelta(days=1))
|
||||
|
||||
def test_misc_fiscalyear_lock_date_2(self):
|
||||
self.test_move.post()
|
||||
|
||||
# Create a bank statement to get a balance in the suspense account.
|
||||
statement = self.env['account.bank.statement'].create({
|
||||
'journal_id': self.company_data['default_journal_bank'].id,
|
||||
'date': '2016-01-01',
|
||||
'line_ids': [
|
||||
(0, 0, {'payment_ref': 'test', 'amount': 10.0})
|
||||
],
|
||||
})
|
||||
statement.button_post()
|
||||
|
||||
# You can't lock the fiscal year if there is some unreconciled statement.
|
||||
with self.assertRaises(ValidationError), self.cr.savepoint():
|
||||
self.test_move.company_id.fiscalyear_lock_date = fields.Date.from_string('2017-01-01')
|
||||
|
||||
def test_misc_tax_lock_date_1(self):
|
||||
self.test_move.post()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user