[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
This commit is contained in:
Rifakat Haradwala 2014-10-17 18:40:12 +05:30 committed by Martin Trigaux
parent 7ab70cab74
commit a08b9c2c41
3 changed files with 44 additions and 3 deletions

View File

@ -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)

View File

@ -1,3 +1,4 @@
from . import test_tax
from . import test_search
from . import test_reconciliation
from . import test_account_move_closed_period

View File

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