diff --git a/account_journal_period_close/model/account_period.py b/account_journal_period_close/model/account_period.py index 72902209e..191d63b8b 100644 --- a/account_journal_period_close/model/account_period.py +++ b/account_journal_period_close/model/account_period.py @@ -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}) diff --git a/account_journal_period_close/tests/__init__.py b/account_journal_period_close/tests/__init__.py index d503a5aa8..1d4899c26 100644 --- a/account_journal_period_close/tests/__init__.py +++ b/account_journal_period_close/tests/__init__.py @@ -28,3 +28,8 @@ # from . import test_account_journal_period_close + + +checks = [ + test_account_journal_period_close, +] diff --git a/account_journal_period_close/tests/test_account_journal_period_close.py b/account_journal_period_close/tests/test_account_journal_period_close.py index 0e3a6dd05..fe93d013e 100644 --- a/account_journal_period_close/tests/test_account_journal_period_close.py +++ b/account_journal_period_close/tests/test_account_journal_period_close.py @@ -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 diff --git a/account_journal_period_close/view/account_period_view.xml b/account_journal_period_close/view/account_period_view.xml index 199ed0f4f..8e4b8ea69 100644 --- a/account_journal_period_close/view/account_period_view.xml +++ b/account_journal_period_close/view/account_period_view.xml @@ -9,7 +9,8 @@ - + +