← Back to team overview

c2c-oerpscenario team mailing list archive

[Bug 802168] Re: Crash if last_external_id is 0 - sale.py (with solution to fix this bug)

 

Thanks for the report and the fix.
I applied your fix, revno 425.

** Changed in: magentoerpconnect
       Status: New => Fix Released

-- 
You received this bug notification because you are a member of C2C
OERPScenario, which is subscribed to the OpenERP Project Group.
https://bugs.launchpad.net/bugs/802168

Title:
  Crash if last_external_id is 0 - sale.py (with solution to fix this
  bug)

Status in Magento OpenERP Connector:
  Fix Released

Bug description:
  I think we found a new bug in MagentoErpConnect. 
  If you work with a new installation of OpenERP then you haven’t imported any orders from magento. In case of this there is a bug in sale.py on line 141 in the function „import_shop_orders“:

                  #get last imported order:
                  last_external_id = self.get_last_imported_external_id(cr, 'sale.order', shop.referential_id.id, "sale_order.shop_id=%s and magento_storeview_id=%s" % (shop.id, storeview.id))[1]
                  last_external_id = int(last_external_id.split('-')[0]) <--- It will crash here!!!
                  if last_external_id:
                      ids_or_filter[0]['increment_id'] = {'from': int(last_external_id) + 1, 'to': int(last_external_id) + SALE_ORDER_IMPORT_STEP}
                  else:
                      if SALE_ORDER_MAPPING.get(magento_storeview_id, False):
                          ids_or_filter[0]['increment_id'] = {'lt': SALE_ORDER_MAPPING[magento_storeview_id] + SALE_ORDER_IMPORT_STEP}

  Please check the mark "it will crash here" in the code above. At this
  point MagentoErpConnect will crash, because if they are no orders
  imported, last_external_id is "false".

  You can solve this problem by changing the code:

                  #get last imported order:
                  last_external_id = self.get_last_imported_external_id(cr, 'sale.order', shop.referential_id.id, "sale_order.shop_id=%s and magento_storeview_id=%s" % (shop.id, storeview.id))[1]
                  if last_external_id:
                      last_external_id = int(last_external_id.split('-')[0])                
                      ids_or_filter[0]['increment_id'] = {'from': int(last_external_id) + 1, 'to': int(last_external_id) + SALE_ORDER_IMPORT_STEP}
                  else:
                      if SALE_ORDER_MAPPING.get(magento_storeview_id, False):
                          ids_or_filter[0]['increment_id'] = {'lt': SALE_ORDER_MAPPING[magento_storeview_id] + SALE_ORDER_IMPORT_STEP}

  Thanks to Marc Loewenthal for helping me to solve this bug.

  Br
  Christian

To manage notifications about this bug go to:
https://bugs.launchpad.net/magentoerpconnect/+bug/802168/+subscriptions


References