From a08b9c2c41d079d0f2d40c44fb160968d6a391af Mon Sep 17 00:00:00 2001 From: Rifakat Haradwala Date: Fri, 17 Oct 2014 18:40:12 +0530 Subject: [PATCH] [FIX] account: forbid creating entries on closed period Prevent creating/modifying accounting entries made on close periods. The period_id and journal_id field on a account.move.line is a related so was silently (without write call) updated so did not triggered the call to _update_journal_check while modiying the linked account.move Force the check in the validation of the move. As the move can not be balanced without going through this method, this will prevent posted entries in closed accounting period. Fixes #1633, opw 615886 --- addons/account/account.py | 5 +-- addons/account/tests/__init__.py | 1 + .../tests/test_account_move_closed_period.py | 41 +++++++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 addons/account/tests/test_account_move_closed_period.py diff --git a/addons/account/account.py b/addons/account/account.py index f7161ce7bdb..2c883396171 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -1366,9 +1366,6 @@ class account_move(osv.osv): self.validate(cr, uid, ids, context=context) return result - # - # TODO: Check if period is closed ! - # def create(self, cr, uid, vals, context=None): context = dict(context or {}) if vals.get('line_id'): @@ -1538,6 +1535,8 @@ class account_move(osv.osv): line_ids = [] line_draft_ids = [] company_id = None + # makes sure we don't use outdated period + obj_move_line._update_journal_check(cr, uid, journal.id, move.period_id.id, context=context) for line in move.line_id: amount += line.debit - line.credit line_ids.append(line.id) diff --git a/addons/account/tests/__init__.py b/addons/account/tests/__init__.py index 8a0a9394c3a..152f89cdcc1 100644 --- a/addons/account/tests/__init__.py +++ b/addons/account/tests/__init__.py @@ -1,3 +1,4 @@ from . import test_tax from . import test_search from . import test_reconciliation +from . import test_account_move_closed_period diff --git a/addons/account/tests/test_account_move_closed_period.py b/addons/account/tests/test_account_move_closed_period.py new file mode 100644 index 00000000000..68ad8788476 --- /dev/null +++ b/addons/account/tests/test_account_move_closed_period.py @@ -0,0 +1,41 @@ +from datetime import date + +from openerp.tests.common import TransactionCase +from openerp.osv.orm import except_orm + +class TestPeriodState(TransactionCase): + """ + Forbid creation of Journal Entries for a closed period. + """ + + def setUp(self): + super(TestPeriodState, self).setUp() + cr, uid = self.cr, self.uid + self.wizard_period_close = self.registry('account.period.close') + self.wizard_period_close_id = self.wizard_period_close.create(cr, uid, {'sure': 1}) + _, self.sale_journal_id = self.registry("ir.model.data").get_object_reference(cr, uid, "account", "sales_journal") + _, self.period_9_id = self.registry("ir.model.data").get_object_reference(cr, uid, "account", "period_9") + + def test_period_state(self): + cr, uid = self.cr, self.uid + self.wizard_period_close.data_save(cr, uid, [self.wizard_period_close_id], { + 'lang': 'en_US', + 'active_model': 'account.period', + 'active_ids': [self.period_9_id], + 'tz': False, + 'active_id': self.period_9_id + }) + with self.assertRaises(except_orm): + self.registry('account.move').create(cr, uid, { + 'name': '/', + 'period_id': self.period_9_id, + 'journal_id': self.sale_journal_id, + 'date': date.today(), + 'line_id': [(0, 0, { + 'name': 'foo', + 'debit': 10, + }), (0, 0, { + 'name': 'bar', + 'credit': 10, + })] + })