Merge pull request #38 from acsone/7.0-imp-journal-period-close

[IMP] Prevent to re-open account journal after closing period and add a ...
This commit is contained in:
Pedro M. Baeza
2014-10-31 13:43:36 +01:00
4 changed files with 38 additions and 8 deletions

View File

@@ -36,3 +36,23 @@ class AccountPeriod(orm.Model):
'journal_period_ids': fields.one2many('account.journal.period',
'period_id', 'Journal states'),
}
def add_all_journals(self, cr, uid, ids, context=None):
this = self.browse(cr, uid, ids, context=context)[0]
journal_period_obj = self.pool.get('account.journal.period')
journal_period_ids = journal_period_obj\
.search(cr, uid, [('period_id', '=', this.id)], context=context)
journal_list = []
for journal_period in journal_period_obj.browse(cr,
uid,
journal_period_ids,
context=context):
journal_list.append(journal_period.journal_id.id)
journal_ids = self.pool.get('account.journal')\
.search(cr, uid, [('id', 'not in', journal_list)], context=context)
for journal_id in journal_ids:
journal_period_obj.create(cr,
uid,
{'period_id': this.id,
'journal_id': journal_id,
'state': this.state})

View File

@@ -28,3 +28,8 @@
#
from . import test_account_journal_period_close
checks = [
test_account_journal_period_close,
]

View File

@@ -28,7 +28,7 @@
#
import openerp.tests.common as common
from openerp.osv import orm
from openerp.osv import orm, osv
from datetime import datetime
from psycopg2 import IntegrityError
@@ -99,10 +99,10 @@ def journal_period_draft(self, journal_period_id, context):
context=context)
class TestAccountConstraintChronology(common.TransactionCase):
class TestAccountJournalPeriodClose(common.TransactionCase):
def setUp(self):
super(TestAccountConstraintChronology, self).setUp()
super(TestAccountJournalPeriodClose, self).setUp()
def test_close_period_open_journal(self):
context = {}
@@ -138,7 +138,7 @@ class TestAccountConstraintChronology(common.TransactionCase):
journal_id)
# I check if the exception is correctly raised at create of an account
# move which is linked with a closed journal
self.assertRaises(orm.except_orm,
self.assertRaises(osv.except_osv,
self.registry('account.move').create,
self.cr, self.uid, move_values, context=context)
@@ -203,6 +203,10 @@ class TestAccountConstraintChronology(common.TransactionCase):
create_journal_period(self, period_id, journal_id, context)
# I check if the exception is correctly raised at adding both same
# journal on a period
self.assertRaises(IntegrityError,
create_journal_period,
self, period_id, journal_id, context)
self.cr._default_log_exceptions = False
try:
self.assertRaises(IntegrityError,
create_journal_period,
self, period_id, journal_id, context)
finally:
self.cr._default_log_exceptions = True

View File

@@ -9,7 +9,8 @@
<field name="arch" type="xml">
<xpath expr="//sheet/group" position="after">
<notebook>
<page string="Journals">
<page string="Journals" attrs="{'invisible': [('state', '=', 'done')]}">
<button name="add_all_journals" string="Add all journals" type="object" states="draft"/>
<field name="journal_period_ids">
<tree editable="bottom">
<field name="journal_id" attrs="{'readonly': [('type', '!=', False)]}"/>