mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
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:
@@ -36,3 +36,23 @@ class AccountPeriod(orm.Model):
|
|||||||
'journal_period_ids': fields.one2many('account.journal.period',
|
'journal_period_ids': fields.one2many('account.journal.period',
|
||||||
'period_id', 'Journal states'),
|
'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})
|
||||||
|
|||||||
@@ -28,3 +28,8 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
from . import test_account_journal_period_close
|
from . import test_account_journal_period_close
|
||||||
|
|
||||||
|
|
||||||
|
checks = [
|
||||||
|
test_account_journal_period_close,
|
||||||
|
]
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
import openerp.tests.common as common
|
import openerp.tests.common as common
|
||||||
from openerp.osv import orm
|
from openerp.osv import orm, osv
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from psycopg2 import IntegrityError
|
from psycopg2 import IntegrityError
|
||||||
|
|
||||||
@@ -99,10 +99,10 @@ def journal_period_draft(self, journal_period_id, context):
|
|||||||
context=context)
|
context=context)
|
||||||
|
|
||||||
|
|
||||||
class TestAccountConstraintChronology(common.TransactionCase):
|
class TestAccountJournalPeriodClose(common.TransactionCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestAccountConstraintChronology, self).setUp()
|
super(TestAccountJournalPeriodClose, self).setUp()
|
||||||
|
|
||||||
def test_close_period_open_journal(self):
|
def test_close_period_open_journal(self):
|
||||||
context = {}
|
context = {}
|
||||||
@@ -138,7 +138,7 @@ class TestAccountConstraintChronology(common.TransactionCase):
|
|||||||
journal_id)
|
journal_id)
|
||||||
# I check if the exception is correctly raised at create of an account
|
# I check if the exception is correctly raised at create of an account
|
||||||
# move which is linked with a closed journal
|
# move which is linked with a closed journal
|
||||||
self.assertRaises(orm.except_orm,
|
self.assertRaises(osv.except_osv,
|
||||||
self.registry('account.move').create,
|
self.registry('account.move').create,
|
||||||
self.cr, self.uid, move_values, context=context)
|
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)
|
create_journal_period(self, period_id, journal_id, context)
|
||||||
# I check if the exception is correctly raised at adding both same
|
# I check if the exception is correctly raised at adding both same
|
||||||
# journal on a period
|
# journal on a period
|
||||||
self.assertRaises(IntegrityError,
|
self.cr._default_log_exceptions = False
|
||||||
create_journal_period,
|
try:
|
||||||
self, period_id, journal_id, context)
|
self.assertRaises(IntegrityError,
|
||||||
|
create_journal_period,
|
||||||
|
self, period_id, journal_id, context)
|
||||||
|
finally:
|
||||||
|
self.cr._default_log_exceptions = True
|
||||||
|
|||||||
@@ -9,7 +9,8 @@
|
|||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<xpath expr="//sheet/group" position="after">
|
<xpath expr="//sheet/group" position="after">
|
||||||
<notebook>
|
<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">
|
<field name="journal_period_ids">
|
||||||
<tree editable="bottom">
|
<tree editable="bottom">
|
||||||
<field name="journal_id" attrs="{'readonly': [('type', '!=', False)]}"/>
|
<field name="journal_id" attrs="{'readonly': [('type', '!=', False)]}"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user