summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorLaurent Smet <las@odoo.com>2020-04-27 11:14:47 +0000
committerLaurent Smet <las@odoo.com>2020-05-05 07:16:39 +0000
commit035fadb7d5df3f55cc6accdee9b2179bcee7b0f0 (patch)
tree3f7f1806b25bd466c00e0991f80c548522c18a7e /addons
parenta599f1402e937dfa869774f3e8345c0c645425fd (diff)
[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>
Diffstat (limited to 'addons')
-rw-r--r--addons/account/models/company.py10
-rw-r--r--addons/account/tests/test_account_move_entry.py17
2 files changed, 27 insertions, 0 deletions
diff --git a/addons/account/models/company.py b/addons/account/models/company.py
index 4535f0da68d..40128bb2f4a 100644
--- a/addons/account/models/company.py
+++ b/addons/account/models/company.py
@@ -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()
diff --git a/addons/account/tests/test_account_move_entry.py b/addons/account/tests/test_account_move_entry.py
index c4198a1eecb..aba886a1929 100644
--- a/addons/account/tests/test_account_move_entry.py
+++ b/addons/account/tests/test_account_move_entry.py
@@ -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()