savoirfairelinux-openerp team mailing list archive
-
savoirfairelinux-openerp team
-
Mailing list archive
-
Message #00140
lp:~sebastien.beau/e-commerce-addons/oerp6.1-stable-improve-shipping-export into lp:e-commerce-addons/oerp6.1-stable
Sébastien BEAU - http://www.akretion.com has proposed merging lp:~sebastien.beau/e-commerce-addons/oerp6.1-stable-improve-shipping-export into lp:e-commerce-addons/oerp6.1-stable.
Requested reviews:
extra-addons-commiter (extra-addons-commiter)
For more details, see:
https://code.launchpad.net/~sebastien.beau/e-commerce-addons/oerp6.1-stable-improve-shipping-export/+merge/168291
Improve stock export by adding reporting. Easier to debug.
--
https://code.launchpad.net/~sebastien.beau/e-commerce-addons/oerp6.1-stable-improve-shipping-export/+merge/168291
Your team extra-addons-commiter is requested to review the proposed merge of lp:~sebastien.beau/e-commerce-addons/oerp6.1-stable-improve-shipping-export into lp:e-commerce-addons/oerp6.1-stable.
=== modified file 'base_sale_multichannels/sale.py'
--- base_sale_multichannels/sale.py 2013-06-08 20:04:37 +0000
+++ base_sale_multichannels/sale.py 2013-06-09 15:22:24 +0000
@@ -410,7 +410,8 @@
AND stock_picking.type = 'out'
AND NOT stock_picking.do_not_export
AND (NOT delivery_carrier.export_needs_tracking
- OR stock_picking.carrier_tracking_ref IS NOT NULL)
+ OR stock_picking.carrier_tracking_ref IS NOT NULL
+ OR delivery_carrier IS NULL)
GROUP BY stock_picking.id,
sale_order.id,
delivery_carrier.export_needs_tracking,
@@ -422,56 +423,57 @@
return query, params
def export_shipping(self, cr, uid, ids, context):
+ for shop in self.browse(cr, uid, ids):
+ external_session = ExternalSession(shop.referential_id, shop)
+ self._export_shipping_for_shop(cr, uid, external_session, context=context)
+ return True
+
+ @open_report
+ def _export_shipping_for_shop(self, cr, uid, external_session, context=None):
+ shop = external_session.sync_from_object
+ cr.execute(*self._export_shipping_query(
+ cr, uid, shop, context=context))
+ results = cr.dictfetchall()
+ if not results:
+ external_session.logger.info("There is no shipping to export for the shop '%s' to the external referential", shop.name)
+ return True
+ external_session.logger.info("Start to export %s picking for the shop'%s"%(len(results), shop.name))
+ for result in results:
+ picking_id = result['picking_id']
+ has_error = self.pool.get('external.report.line').search(cr, uid, [
+ ['report_id.action', '=', '_export_shipping_for_shop'],
+ ['res_id', '=', picking_id],
+ ], context=context)
+ if has_error:
+ external_session.logger.info("Shipping id %s is skipped as on error already exist"%picking_id)
+ if result["picking_number"] == 1:
+ picking_type = 'complete'
+ else:
+ picking_type = 'partial'
+ self._export_one_shipping(cr, uid, external_session, picking_id, picking_type, context=context)
+ return True
+
+ @catch_error_in_report
+ def _export_one_shipping(self, cr, uid, external_session, picking_id, picking_type, context=None):
+ shop = external_session.sync_from_object
+ if context is None:
+ context = {}
+ ctx = context.copy()
+ ctx['conn_obj'] = external_session.connection
picking_obj = self.pool.get('stock.picking')
- for shop in self.browse(cr, uid, ids):
- cr.execute(*self._export_shipping_query(
- cr, uid, shop, context=context))
- results = cr.dictfetchall()
- if not results:
- _logger.info("There is no shipping to export for the shop '%s' to the external referential", shop.name)
- continue
- context['conn_obj'] = shop.referential_id.external_connection()
-
-
- picking_cr = pooler.get_db(cr.dbname).cursor()
- try:
- for result in results:
- picking_id = result['picking_id']
-
- if result["picking_number"] == 1:
- picking_type = 'complete'
- else:
- picking_type = 'partial'
-
- ext_shipping_id = False
- try:
- ext_shipping_id = picking_obj.create_ext_shipping(
- picking_cr, uid, picking_id, picking_type,
- shop.referential_id.id, context)
- except ExternalShippingCreateError, e:
- # when the creation has failed on the external
- # referential and we know that we can never
- # create it, we flag it as do_not_export
- # ExternalShippingCreateError raising has to be
- # correctly handled by create_ext_shipping()
- picking_obj.write(
- picking_cr, uid,
- picking_id,
- {'do_not_export': True},
- context=context)
-
- if ext_shipping_id:
- picking_obj.create_external_id_vals(
- picking_cr,
- uid,
- picking_id,
- ext_shipping_id,
- shop.referential_id.id,
- context=context)
- _logger.info("Successfully creating shipping with OpenERP id %s and ext id %s in external sale system", result["picking_id"], ext_shipping_id)
- picking_cr.commit()
- finally:
- picking_cr.close()
+ ext_shipping_id = False
+ ext_shipping_id = picking_obj.create_ext_shipping(
+ cr, uid, picking_id, picking_type,
+ shop.referential_id.id, ctx)
+ if ext_shipping_id:
+ picking_obj.create_external_id_vals(
+ cr,
+ uid,
+ picking_id,
+ ext_shipping_id,
+ shop.referential_id.id,
+ context=ctx)
+ external_session.logger.info("Successfully creating shipping with OpenERP id %s and ext id %s in external sale system", picking_id, ext_shipping_id)
return True
def export_invoices(self, cr, uid, ids, context=None):
Follow ups