Merge pull request #27 from acsone/7.0-imp-journal-period-duplicate

[IMP] Prevent to add both same journals on a period when using account_journal_period_close
This commit is contained in:
Nicolas Bessi (nbessi)
2014-09-03 14:42:03 +02:00
2 changed files with 18 additions and 1 deletions

View File

@@ -41,6 +41,11 @@ class AccountJournalPeriod(orm.Model):
store=True, readonly=True)
}
_sql_constraints = [
('journal_period_uniq', 'unique(period_id, journal_id)',
'You can not add same journal in the same period twice.'),
]
def _check(self, cr, uid, ids, context=None):
return True
@@ -71,7 +76,7 @@ class AccountJournalPeriod(orm.Model):
period = self.pool.get('account.period')\
.browse(cr, uid, values['period_id'], context=context)
values.update({'name': (journal.code or journal.name)+':' +
(period.name or '')}),
(period.name or '')})
return super(AccountJournalPeriod, self).create(cr,
uid,
values,

View File

@@ -30,6 +30,7 @@
import openerp.tests.common as common
from openerp.osv import orm
from datetime import datetime
from psycopg2 import IntegrityError
DB = common.DB
ADMIN_USER_ID = common.ADMIN_USER_ID
@@ -194,3 +195,14 @@ class TestAccountConstraintChronology(common.TransactionCase):
jour_per_obj.action_done,
self.cr, self.uid, journal_period_ids,
context=context)
def test_duplicate_journal_period(self):
context = {}
journal_id = self.ref('account.sales_journal')
period_id = self.ref('account.period_1')
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)