Rucha (Open ERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-account-fix-journal-code-rpa into 
lp:openobject-addons.

Requested reviews:
  qdp (OpenERP) (qdp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-account-fix-journal-code-rpa/+merge/83942

Fixed the problem of wrong journal code generation,

The error: 

IntegrityError: duplicate key value violates unique constraint 
"account_journal_code_company_uniq" 

is generated when we already have bank journals created,
e.g by the generation of res.partner.bank
and we execute wizard "Generate Chart of Accounts from a Chart Template" 

the problem is this wizard doesn't take into account already created bank 
journals and its code,

to test:
1. install account module first
2. create a bank account
3. Install l10n_be
4. Run wizard "Generate Chart of Accounts from a Chart Template" 

proposed code fixes this problem,

Thanks

-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-account-fix-journal-code-rpa/+merge/83942
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-account-fix-journal-code-rpa.
=== modified file 'account/account.py'
--- account/account.py	2011-11-25 17:49:08 +0000
+++ account/account.py	2011-11-30 13:36:35 +0000
@@ -3135,6 +3135,19 @@
                     break
                 else:
                     current_num += 1
+
+            # we need to loop again to find next number for journal code 
+            # because we can't rely on the value current_num as,
+            # its possible that we already have bank journals created (e.g. by the creation of res.partner.bank) 
+            # and the next number for account code might have been already used before for journal
+            journal_count = 1
+            while True:
+                journal_code = _('BNK') + str(journal_count)
+                ids = obj_journal.search(cr, uid, [('code', '=', journal_code)], context=context)
+                if not ids:
+                    break
+                journal_count += 1
+
             vals = {
                 'name': tmp,
                 'currency_id': line.currency_id and line.currency_id.id or False,
@@ -3150,7 +3163,7 @@
             #create the bank journal
             vals_journal = {
                 'name': vals['name'],
-                'code': _('BNK') + str(current_num),
+                'code': journal_code,
                 'type': line.account_type == 'cash' and 'cash' or 'bank',
                 'company_id': company_id,
                 'analytic_journal_id': False,

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to