orm.py import_data fails when importing account.fiscal.positions

Bug #430805 reported by Niels Huylebroeck
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Fix Released
Undecided
Yogesh (SerpentCS)

Bug Description

Trying to import following :

ID|name|company_id:id|account_ids/account_src_id:id|account_ids/account_dest_id:id|tax_ids/tax_src_id:id|tax_ids/tax_dest_id:id
fiscal_position_1|Nationaal Regime|base.main_partner||||
fiscal_position_2|Intracommunautair regime|base.main_partner|account_495|account_497|account_tax_49|account_tax_24
fiscal_position_2|Intracommunautair regime|base.main_partner|account_460|account_471|account_tax_49|account_tax_24

(I already hacked client to accept old style names see other bug I reported on client : https://bugs.launchpad.net/openobject-client/+bug/429948 )

Importing this in 5.0.5 (bzr stable) produced following stack trace

[2009-09-16 17:28:32,714] ERROR:web-services:[01]:
[2009-09-16 17:28:32,714] ERROR:web-services:[02]: Environment Information :
[2009-09-16 17:28:32,715] ERROR:web-services:[03]: System : Linux-2.6.24-24-generic-x86_64-with-debian-lenny-sid
[2009-09-16 17:28:32,715] ERROR:web-services:[04]: OS Name : posix
[2009-09-16 17:28:32,715] ERROR:web-services:[05]: Distributor ID: Ubuntu
[2009-09-16 17:28:32,715] ERROR:web-services:[06]: Description: Ubuntu 8.04.3 LTS
[2009-09-16 17:28:32,715] ERROR:web-services:[07]: Release: 8.04
[2009-09-16 17:28:32,715] ERROR:web-services:[08]: Codename: hardy
[2009-09-16 17:28:32,715] ERROR:web-services:[09]: Operating System Release : 2.6.24-24-generic
[2009-09-16 17:28:32,715] ERROR:web-services:[10]: Operating System Version : #1 SMP Tue Aug 18 16:22:17 UTC 2009
[2009-09-16 17:28:32,715] ERROR:web-services:[11]: Operating System Architecture : 64bit
[2009-09-16 17:28:32,715] ERROR:web-services:[12]: Operating System Locale : en_US.UTF8
[2009-09-16 17:28:32,715] ERROR:web-services:[13]: Python Version : 2.5.2
[2009-09-16 17:28:32,716] ERROR:web-services:[14]: OpenERP-Server Version : 5.0.5-bzr
[2009-09-16 17:28:32,716] ERROR:web-services:[15]: Last revision No. & ID : 1846 <email address hidden>
[2009-09-16 17:28:32,716] ERROR:web-services:[16]:
[2009-09-16 17:28:32,716] ERROR:web-services:[17]: Traceback (most recent call last):
[2009-09-16 17:28:32,716] ERROR:web-services:[18]: File "/home/red15/Documents/Werk/OpenERP/bubbles/test-server/bin/osv/osv.py", line 59, in wrapper
[2009-09-16 17:28:32,716] ERROR:web-services:[19]: return f(self, dbname, *args, **kwargs)
[2009-09-16 17:28:32,716] ERROR:web-services:[20]: File "/home/red15/Documents/Werk/OpenERP/bubbles/test-server/bin/osv/osv.py", line 118, in execute
[2009-09-16 17:28:32,716] ERROR:web-services:[21]: res = pool.execute_cr(cr, uid, obj, method, *args, **kw)
[2009-09-16 17:28:32,716] ERROR:web-services:[22]: File "/home/red15/Documents/Werk/OpenERP/bubbles/test-server/bin/osv/osv.py", line 110, in execute_cr
[2009-09-16 17:28:32,716] ERROR:web-services:[23]: return getattr(object, method)(cr, uid, *args, **kw)
[2009-09-16 17:28:32,717] ERROR:web-services:[24]: File "/home/red15/Documents/Werk/OpenERP/bubbles/test-server/bin/osv/orm.py", line 803, in import_data
[2009-09-16 17:28:32,717] ERROR:web-services:[25]: process_liness(self, datas, [], current_module, self._name, fields_def)
[2009-09-16 17:28:32,717] ERROR:web-services:[26]: File "/home/red15/Documents/Werk/OpenERP/bubbles/test-server/bin/osv/orm.py", line 758, in process_liness
[2009-09-16 17:28:32,717] ERROR:web-services:[27]: res = process_liness(self, datas, prefix + [field], current_module, relation_obj._name, newfd, position)
[2009-09-16 17:28:32,717] ERROR:web-services:[28]: File "/home/red15/Documents/Werk/OpenERP/bubbles/test-server/bin/osv/orm.py", line 611, in process_liness
[2009-09-16 17:28:32,717] ERROR:web-services:[29]: if fields_def[field[len(prefix)][:-3]]['type']=='many2many':
[2009-09-16 17:28:32,717] ERROR:web-services:[30]: KeyError: 'tax_src_id'

The fix for this is quite easy :

=== modified file 'bin/osv/orm.py'
--- bin/osv/orm.py 2009-09-15 08:17:44 +0000
+++ bin/osv/orm.py 2009-09-16 15:45:18 +0000
@@ -607,6 +607,8 @@

                 if (len(field)==len(prefix)+1) and field[len(prefix)].endswith(':id'):
                     res_id = False
+ if field[len(prefix)][:-3] not in fields_def:
+ continue # This field does not belong to this prefix !
                     if line[i]:
                         if fields_def[field[len(prefix)][:-3]]['type']=='many2many':
                             res_id = []
@@ -631,7 +633,7 @@
                             id = ir_model_data_obj._get_id(cr, uid, module, xml_id)
                             res_id = ir_model_data_obj.read(cr, uid, [id],
                                     ['res_id'])[0]['res_id']
- row[field[0][:-3]] = res_id or False
+ row[field[len(prefix)][:-3]] = res_id or False
                     continue
                 if (len(field) == len(prefix)+1) and \
                         len(field[len(prefix)].split(':lang=')) == 2:

Part 1 of the fix skips the current field if that field does not belong to the current prefix we're handling
Part 2 fixes a problem with column names not being mapped correctly.

I submit this bug/patch with a warning, it now works for me, do your own import tests please.

Related branches

Revision history for this message
Niels Huylebroeck (red15) wrote :

patch file

Changed in openobject-server:
assignee: nobody → Ysa(Open ERP) (ysa-openerp)
Changed in openobject-server:
status: New → Confirmed
Changed in openobject-server:
status: Confirmed → In Progress
Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) wrote :

Hello Niels,

Thank you for pointing this out.

Fixed by revision 1873 <email address hidden>.

Kindly check it and notify us.

Thanks.

Changed in openobject-server:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.