Importing Guest-Orders is not possible (KeyError: 'shop_id' in create_onfly_partner on line 387)

Bug #1054059 reported by Erik Miers on 2012-09-21
22
This bug affects 4 people
Affects Status Importance Assigned to Milestone
Magento OpenERP Connector
Fix Released
Undecided
Unassigned

Bug Description

Hi, I'm using oerp6.1-stable (rev 677)

In my magento-shop (1.6.0.0) we have a module (Camiloo) that imports orders from Amazon to Magento.
When I try to import these orders to openERP I get the following error.

Thanks for you help.

Client Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.6/openerp/addons/web/common/http.py", line 180, in dispatch
    response["result"] = method(controller, self, **self.params)
  File "/usr/lib/pymodules/python2.6/openerp/addons/web/controllers/main.py", line 1052, in call_button
    action = self.call_common(req, model, method, args, domain_id, context_id)
  File "/usr/lib/pymodules/python2.6/openerp/addons/web/controllers/main.py", line 996, in call_common
    return self._call_kw(req, model, method, args, {})
  File "/usr/lib/pymodules/python2.6/openerp/addons/web/controllers/main.py", line 1010, in _call_kw
    return getattr(req.session.model(model), method)(*args, **kwargs)
  File "/usr/lib/pymodules/python2.6/openerp/addons/web/common/openerplib/main.py", line 250, in proxy
    args, kw)
  File "/usr/lib/pymodules/python2.6/openerp/addons/web/common/openerplib/main.py", line 117, in proxy
    result = self.connector.send(self.service_name, method, *args)
  File "/usr/lib/pymodules/python2.6/openerp/addons/web/common/http.py", line 608, in send
    raise xmlrpclib.Fault(openerp.tools.exception_to_unicode(e), formatted_info)

Server Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.6/openerp/addons/web/common/http.py", line 593, in send
    return openerp.netsvc.dispatch_rpc(service_name, method, args)
  File "/usr/lib/pymodules/python2.6/openerp/netsvc.py", line 360, in dispatch_rpc
    result = ExportService.getService(service_name).dispatch(method, params)
  File "/usr/lib/pymodules/python2.6/openerp/service/web_services.py", line 586, in dispatch
    res = fn(db, uid, *params)
  File "/usr/lib/pymodules/python2.6/openerp/osv/osv.py", line 167, in execute_kw
    return self.execute(db, uid, obj, method, *args, **kw or {})
  File "/usr/lib/pymodules/python2.6/openerp/osv/osv.py", line 121, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/usr/lib/pymodules/python2.6/openerp/osv/osv.py", line 176, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/usr/lib/pymodules/python2.6/openerp/osv/osv.py", line 164, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/usr/lib/pymodules/python2.6/openerp/addons/base_sale_multichannels/wizard/import_order.py", line 41, in import_order
    self.pool.get('sale.order')._import_one_resource(cr, uid, external_session, wizard.order_number, context=context)
  File "/usr/lib/pymodules/python2.6/openerp/addons/base_external_referentials/external_osv.py", line 638, in _import_one_resource
    res = self._record_one_external_resource(cr, uid, external_session, resources, context=context)
  File "/usr/lib/pymodules/python2.6/openerp/addons/base_external_referentials/decorator.py", line 49, in wrapped
    return func(self, cr, uid, argument, *args, **kwargs)
  File "/usr/lib/pymodules/python2.6/openerp/addons/magentoerpconnect/sale.py", line 432, in _record_one_external_resource
    res = super(sale_order, self)._record_one_external_resource(cr, uid, external_session, resource, defaults=defaults, mapping=mapping, mapping_id=mapping_id, context=context)
  File "/usr/lib/pymodules/python2.6/openerp/addons/base_external_referentials/decorator.py", line 110, in wrapper
    return func(self, cr, uid, external_session, resource, *args, **kwargs)
  File "/usr/lib/pymodules/python2.6/openerp/addons/base_sale_multichannels/sale.py", line 565, in _record_one_external_resource
    order_mapping=mapping[mapping_id], context=context)
  File "/usr/lib/pymodules/python2.6/openerp/addons/base_sale_multichannels/sale.py", line 549, in check_if_order_exist
    context=context)
  File "/usr/lib/pymodules/python2.6/openerp/addons/base_external_referentials/decorator.py", line 49, in wrapped
    return func(self, cr, uid, argument, *args, **kwargs)
  File "/usr/lib/pymodules/python2.6/openerp/addons/magentoerpconnect/sale.py", line 411, in _transform_one_resource
    defaults = self.create_onfly_partner(cr, uid, external_session, resource, mapping, defaults, context=context)
  File "/usr/lib/pymodules/python2.6/openerp/addons/magentoerpconnect/sale.py", line 387, in create_onfly_partner
    shop = self.pool.get('sale.shop').browse(cr, uid, defaults['shop_id'], context=context)
KeyError: 'shop_id'

Related branches

Hi all,

am seeing this exception when trying to import standard Magento guest orders. To me it seems to be a more generic problem, not related to orders being imported into Magento previously.

Willi Kreißl (6-willx-h) wrote :

Hey Guys!

I have the same exeption when importing guest orders.

In debug mode I checked whats wrong.
In create_onfly_partner the variable "defaults" is empty when it is a guest order and it tries to read "shop_id" from it in line 387 (defaults['shop_id'])
Line: shop = self.pool.get('sale.shop').browse(cr, uid, defaults['shop_id'], context=context)

Trace:
Server Traceback (most recent call last):
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\openerp\addons\web\common\http.py", line 593, in send
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\.\openerp\netsvc.py", line 360, in dispatch_rpc
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\.\openerp\service\web_services.py", line 586, in dispatch
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\.\openerp\osv\osv.py", line 167, in execute_kw
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\.\openerp\osv\osv.py", line 121, in wrapper
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\.\openerp\osv\osv.py", line 176, in execute
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\.\openerp\osv\osv.py", line 164, in execute_cr
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\openerp\addons\base_external_referentials\report.py", line 343, in retry
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\openerp\addons\base_external_referentials\decorator.py", line 49, in wrapped
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\openerp\addons\magentoerpconnect\sale.py", line 432, in _record_one_external_resource
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\openerp\addons\base_external_referentials\decorator.py", line 130, in wrapper
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\openerp\addons\base_sale_multichannels\sale.py", line 565, in _record_one_external_resource
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\openerp\addons\base_sale_multichannels\sale.py", line 549, in check_if_order_exist
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\openerp\addons\base_external_referentials\decorator.py", line 49, in wrapped
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\openerp\addons\magentoerpconnect\sale.py", line 411, in _transform_one_resource
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\openerp\addons\magentoerpconnect\sale.py", line 387, in create_onfly_partner
KeyError: 'shop_id'

Any idea why defaults is empty?

Changed in magentoerpconnect:
status: New → Confirmed
Willi Kreißl (6-willx-h) wrote :

I've tried to add the shop_id manually before it is reading defaults by adding defaults['shop_id'] = 1 in sale.py on line 382.

Looks like this:
if not defaults: defaults={}
defaults['shop_id'] = 1
local_defaults = defaults.copy()

Now the function create_onfly_partner() works but it throws in another function an exception now:

Server Traceback (most recent call last):
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\openerp\addons\web\common\http.py", line 593, in send
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\.\openerp\netsvc.py", line 360, in dispatch_rpc
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\.\openerp\service\web_services.py", line 586, in dispatch
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\.\openerp\osv\osv.py", line 167, in execute_kw
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\.\openerp\osv\osv.py", line 121, in wrapper
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\.\openerp\osv\osv.py", line 176, in execute
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\.\openerp\osv\osv.py", line 164, in execute_cr
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\openerp\addons\base_external_referentials\report.py", line 343, in retry
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\openerp\addons\base_external_referentials\decorator.py", line 49, in wrapped
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\openerp\addons\magentoerpconnect\sale.py", line 435, in _record_one_external_resource
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\openerp\addons\base_external_referentials\decorator.py", line 130, in wrapper
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\openerp\addons\base_sale_multichannels\sale.py", line 565, in _record_one_external_resource
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\openerp\addons\base_sale_multichannels\sale.py", line 549, in check_if_order_exist
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\openerp\addons\base_external_referentials\decorator.py", line 49, in wrapped
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\openerp\addons\magentoerpconnect\sale.py", line 414, in _transform_one_resource
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\openerp\addons\magentoerpconnect\sale.py", line 392, in create_onfly_partner
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\openerp\addons\base_external_referentials\external_osv.py", line 686, in _record_one_external_resource
  File "C:\Program Files (x86)\OpenERP 6.1-20120816-233414\Server\server\openerp\addons\base_external_referentials\external_osv.py", line 1379, in _transform_one_resource
  File "<string>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

This happens when defaults['shop_id'] is manually set.

summary: - cannot import orders made on amazon
+ Importing Guest-Orders is not possible
summary: - Importing Guest-Orders is not possible
+ Importing Guest-Orders is not possible (KeyError: 'shop_id' in
+ create_onfly_partner on line 387)
Erik Miers (p949b) wrote :

Any news on this one ?
workaround ?

Edgar (r-christ) wrote :

The same here, any solutions?

Willi Kreißl (6-willx-h) wrote :

At the moment a did not find any usable solution that worked always fine and I think I'll give this connector up soon...
After fixing this bug there will be so much more bugs, it is not usable in a productive environment at the moment.

@Willi: hope this is just a temporary down, I do feel the same sometimes. Nevertheless, it seems like you had a go at it, what did you actually try to fix it, and what did not work well?

Regards

Kristofer

Joshua Jan(SHINEIT) (joshuajan) wrote :

hello all ,
     I have try to fix it. This is the patch.
     Regards
Joshua

Hi Joshua,

good work! Can you make it into a set of proper branches for the respective projects? You can then propose each of the branches for review by the core developers.

Cheers,
Stefan.

Hi Stefan,
     Thanks for you advice. I have already make two proper for this bug.
Cheers,
Joshua

Hi Joshua, thanks for preparing the branches. Hopefully they will be merged soon.

Erik Miers (p949b) wrote :

Hi Joshua, thanks for your patch.

I tried it out, but now I'm presented with this MappingError:

Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.6/openerp/addons/base_external_referentials/decorator.py", line 130, in wrapper
    response = func(self, import_cr, uid, external_session, resource, *args, **kwargs)
  File "/usr/lib/pymodules/python2.6/openerp/addons/base_sale_multichannels/sale.py", line 571, in _record_one_external_resource
    defaults=defaults, mapping=mapping, mapping_id=mapping_id, context=context)
  File "/usr/lib/pymodules/python2.6/openerp/addons/base_external_referentials/external_osv.py", line 686, in _record_one_external_resource
    vals = self._transform_one_resource(cr, uid, external_session, 'from_external_to_openerp', resource, mapping=mapping, mapping_id=mapping_id, defaults=defaults, context=context)
  File "/usr/lib/pymodules/python2.6/openerp/addons/base_external_referentials/decorator.py", line 49, in wrapped
    return func(self, cr, uid, argument, *args, **kwargs)
  File "/usr/lib/pymodules/python2.6/openerp/addons/magentoerpconnect/sale.py", line 417, in _transform_one_resource
    previous_result=previous_result, defaults=defaults, context=context)
  File "/usr/lib/pymodules/python2.6/openerp/addons/base_external_referentials/external_osv.py", line 1409, in _transform_one_resource
    vals = self._transform_sub_mapping(cr, uid, external_session, convertion_type, resource, vals, sub_mapping_list, mapping, mapping_id, mapping_line_filter_ids=mapping_line_filter_ids, defaults=defaults, context=context)
  File "/usr/lib/pymodules/python2.6/openerp/addons/base_external_referentials/external_osv.py", line 1582, in _transform_sub_mapping
    lines = sub_mapping_obj._transform_resources(*transform_args, **transform_kwargs)
  File "/usr/lib/pymodules/python2.6/openerp/addons/base_external_referentials/external_osv.py", line 1301, in _transform_resources
    previous_result=result, defaults=defaults, context=context))
  File "/usr/lib/pymodules/python2.6/openerp/addons/base_sale_multichannels/sale.py", line 881, in _transform_one_resource
    previous_result=previous_result, defaults=defaults, context=context)
  File "/usr/lib/pymodules/python2.6/openerp/addons/base_external_referentials/external_osv.py", line 1383, in _transform_one_resource
    raise MappingError(e, mapping_line['name'], self._name)
MappingError: u'the mapping line : price for the object sale.order.line have an error : float() argument must be a string or a number'

Any ideas on that?

Erik Miers (p949b) wrote :

Ok, I solved this Mapping Error.

The problem is, that the field "base_row_total_incl_tax" is null (None) for all order-items which I have imported from Amazon to my Magento store. But this field is required for the particular ma mapping-function for the "price" field on Sale Order Line

Which is this:

result=[
('price_unit_tax_included', (float(resource['base_row_total_incl_tax']))/float(resource['qty_ordered'])),
('price_unit_tax_excluded', (float(resource['base_row_total']))/float(resource['qty_ordered'])),
('tax_rate', float(resource['base_row_total']) and (float(resource['base_row_total_incl_tax'])/float(resource['base_row_total'])-1)),
]

So two approaches to solve this:

First:
 Change the mapping function to don't use "base_row_total_incl_tax" like this:

result=[
('price_unit_tax_included', float(resource['price_incl_tax'])),
('price_unit_tax_excluded', (float(resource['base_row_total']))/float(resource['qty_ordered'])),
('tax_rate', float(resource['base_row_total']) and ((float(resource['price_incl_tax'])*float(resource['qty_ordered']))/float(resource['base_row_total'])-1)),
]

I don't know if this is save for all use-cases, so someone should have a look at it.

Second:
 Change Magento code to automatically calculate base_row_total_incl_tax on every order (from Amazon) created.
But I haven't looked into the code, yet. So I don't know where to actually do this.
And you would also have to change all previously created orders in the database.

Hope this helps anyone.

Hi this bug have been fix some time ago here was the patch http://bazaar.launchpad.net/~magentoerpconnect-core-editors/magentoerpconnect/oerp6.1-stable/revision/676.2.36

Thanks for reporting the bug. I close it

Changed in magentoerpconnect:
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers