Merge lp:~sebastien.beau/e-commerce-addons/oerp6.1-stable-improve-shipping-export into lp:~extra-addons-commiter/e-commerce-addons/oerp6.1-stable

Proposed by Sébastien BEAU - http://www.akretion.com
Status: Work in progress
Proposed branch: lp:~sebastien.beau/e-commerce-addons/oerp6.1-stable-improve-shipping-export
Merge into: lp:~extra-addons-commiter/e-commerce-addons/oerp6.1-stable
Diff against target: 121 lines (+53/-50)
1 file modified
base_sale_multichannels/sale.py (+53/-50)
To merge this branch: bzr merge lp:~sebastien.beau/e-commerce-addons/oerp6.1-stable-improve-shipping-export
Reviewer Review Type Date Requested Status
Guewen Baconnier @ Camptocamp Needs Fixing
Review via email: mp+168291@code.launchpad.net

Description of the change

Improve shipping export by replacing the old try/except by the reporting system. It will help you to debug.
Also export the picking that have empty carrier

To post a comment you must log in.
291. By Sébastien BEAU - http://www.akretion.com

[FIX] fix shipping export, the continue was lost during the merge

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

l.40 s/on error/an error/

When you use a logger, you should not use directly the string substitution like:

    40 + external_session.logger.info("Shipping id %s is skipped as on error already exist"%picking_id)

Instead, you should give the variables as arguments :

    40 + external_session.logger.info("Shipping id %s is skipped as on error already exist", picking_id)

This avoid to process the string substitutions when the logger does not even have to output the line.

You removed the write on `do_not_export` and replaced it by a search in the log reports. Pickings can now be excluded for 2 reasons:

1. they have been excluded by (manually for instance) checking the `do_not_export` field
2. they have a error in the report lines.

For a user, it becomes difficult to find why a picking is not exported. By relying only the field `do_not_export`, with a look on the picking it was obvious that it was not exported.

Opinions?

review: Needs Fixing
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

No changes since 2013-06-18 after Need Fixing request -> I set this in WIP

@Sébastien

Please do the required changes then set it in Needs Review again

Cheers,
Yannick

Unmerged revisions

291. By Sébastien BEAU - http://www.akretion.com

[FIX] fix shipping export, the continue was lost during the merge

290. By Sébastien BEAU - http://www.akretion.com

[FIX] export also the picking that have an empty carrier

289. By Sébastien BEAU - http://www.akretion.com

[IMP] Picking that have already an error in the reporting system are not exported anymore

288. By Sébastien BEAU - http://www.akretion.com

[REF] split shipping export in smaller function and add repporting system

287. By Sébastien BEAU - http://www.akretion.com

[REF] change only indentation for preparing the split of the function

286. By Sébastien BEAU - http://www.akretion.com

[REF] start refactoring the picking export ofr adding reporting system. First step remove try/except no other code change

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'base_sale_multichannels/sale.py'
2--- base_sale_multichannels/sale.py 2013-06-08 20:04:37 +0000
3+++ base_sale_multichannels/sale.py 2013-06-10 14:05:46 +0000
4@@ -410,7 +410,8 @@
5 AND stock_picking.type = 'out'
6 AND NOT stock_picking.do_not_export
7 AND (NOT delivery_carrier.export_needs_tracking
8- OR stock_picking.carrier_tracking_ref IS NOT NULL)
9+ OR stock_picking.carrier_tracking_ref IS NOT NULL
10+ OR delivery_carrier IS NULL)
11 GROUP BY stock_picking.id,
12 sale_order.id,
13 delivery_carrier.export_needs_tracking,
14@@ -422,56 +423,58 @@
15 return query, params
16
17 def export_shipping(self, cr, uid, ids, context):
18+ for shop in self.browse(cr, uid, ids):
19+ external_session = ExternalSession(shop.referential_id, shop)
20+ self._export_shipping_for_shop(cr, uid, external_session, context=context)
21+ return True
22+
23+ @open_report
24+ def _export_shipping_for_shop(self, cr, uid, external_session, context=None):
25+ shop = external_session.sync_from_object
26+ cr.execute(*self._export_shipping_query(
27+ cr, uid, shop, context=context))
28+ results = cr.dictfetchall()
29+ if not results:
30+ external_session.logger.info("There is no shipping to export for the shop '%s' to the external referential", shop.name)
31+ return True
32+ external_session.logger.info("Start to export %s picking for the shop'%s"%(len(results), shop.name))
33+ for result in results:
34+ picking_id = result['picking_id']
35+ has_error = self.pool.get('external.report.line').search(cr, uid, [
36+ ['report_id.action', '=', '_export_shipping_for_shop'],
37+ ['res_id', '=', picking_id],
38+ ], context=context)
39+ if has_error:
40+ external_session.logger.info("Shipping id %s is skipped as on error already exist"%picking_id)
41+ continue
42+ if result["picking_number"] == 1:
43+ picking_type = 'complete'
44+ else:
45+ picking_type = 'partial'
46+ self._export_one_shipping(cr, uid, external_session, picking_id, picking_type, context=context)
47+ return True
48+
49+ @catch_error_in_report
50+ def _export_one_shipping(self, cr, uid, external_session, picking_id, picking_type, context=None):
51+ shop = external_session.sync_from_object
52+ if context is None:
53+ context = {}
54+ ctx = context.copy()
55+ ctx['conn_obj'] = external_session.connection
56 picking_obj = self.pool.get('stock.picking')
57- for shop in self.browse(cr, uid, ids):
58- cr.execute(*self._export_shipping_query(
59- cr, uid, shop, context=context))
60- results = cr.dictfetchall()
61- if not results:
62- _logger.info("There is no shipping to export for the shop '%s' to the external referential", shop.name)
63- continue
64- context['conn_obj'] = shop.referential_id.external_connection()
65-
66-
67- picking_cr = pooler.get_db(cr.dbname).cursor()
68- try:
69- for result in results:
70- picking_id = result['picking_id']
71-
72- if result["picking_number"] == 1:
73- picking_type = 'complete'
74- else:
75- picking_type = 'partial'
76-
77- ext_shipping_id = False
78- try:
79- ext_shipping_id = picking_obj.create_ext_shipping(
80- picking_cr, uid, picking_id, picking_type,
81- shop.referential_id.id, context)
82- except ExternalShippingCreateError, e:
83- # when the creation has failed on the external
84- # referential and we know that we can never
85- # create it, we flag it as do_not_export
86- # ExternalShippingCreateError raising has to be
87- # correctly handled by create_ext_shipping()
88- picking_obj.write(
89- picking_cr, uid,
90- picking_id,
91- {'do_not_export': True},
92- context=context)
93-
94- if ext_shipping_id:
95- picking_obj.create_external_id_vals(
96- picking_cr,
97- uid,
98- picking_id,
99- ext_shipping_id,
100- shop.referential_id.id,
101- context=context)
102- _logger.info("Successfully creating shipping with OpenERP id %s and ext id %s in external sale system", result["picking_id"], ext_shipping_id)
103- picking_cr.commit()
104- finally:
105- picking_cr.close()
106+ ext_shipping_id = False
107+ ext_shipping_id = picking_obj.create_ext_shipping(
108+ cr, uid, picking_id, picking_type,
109+ shop.referential_id.id, ctx)
110+ if ext_shipping_id:
111+ picking_obj.create_external_id_vals(
112+ cr,
113+ uid,
114+ picking_id,
115+ ext_shipping_id,
116+ shop.referential_id.id,
117+ context=ctx)
118+ external_session.logger.info("Successfully creating shipping with OpenERP id %s and ext id %s in external sale system", picking_id, ext_shipping_id)
119 return True
120
121 def export_invoices(self, cr, uid, ids, context=None):