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, + })] + })