[IMP] Prevent to add both same journals on a period

This commit is contained in:
Adrien Peiffer
2014-08-21 15:53:48 +02:00
parent 525d9db11c
commit 9340f0c86c
2 changed files with 23 additions and 0 deletions

View File

@@ -72,6 +72,18 @@ class AccountJournalPeriod(orm.Model):
.browse(cr, uid, values['period_id'], context=context)
values.update({'name': (journal.code or journal.name)+':' +
(period.name or '')}),
if values.get('period_id') and values.get('journal_id'):
journal_period_duplicate_ids = self\
.search(cr, uid, [('period_id', '=',
values.get('period_id')),
('journal_id', '=',
values.get('journal_id'))],
context=context)
if (journal_period_duplicate_ids):
raise orm.except_orm(_('error'),
_('You can not add 2 times'
' the same journal in'
' same period.'))
return super(AccountJournalPeriod, self).create(cr,
uid,
values,

View File

@@ -194,3 +194,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(orm.except_orm,
create_journal_period,
self, period_id, journal_id, context)