Merge lp:~camptocamp/openerp-connector-magento/7.0-export-invoice-no-id-1337778 into lp:~openerp-connector-core-editors/openerp-connector-magento/7.0

Proposed by Guewen Baconnier @ Camptocamp
Status: Rejected
Rejected by: Guewen Baconnier @ Camptocamp
Proposed branch: lp:~camptocamp/openerp-connector-magento/7.0-export-invoice-no-id-1337778
Merge into: lp:~openerp-connector-core-editors/openerp-connector-magento/7.0
Diff against target: 63 lines (+23/-4)
2 files modified
magentoerpconnect/invoice.py (+19/-4)
magentoerpconnect/unit/binder.py (+4/-0)
To merge this branch: bzr merge lp:~camptocamp/openerp-connector-magento/7.0-export-invoice-no-id-1337778
Reviewer Review Type Date Requested Status
OpenERP Connector Core Editors Pending
Review via email: mp+225628@code.launchpad.net

Description of the change

To post a comment you must log in.
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Unmerged revisions

1007. By Guewen Baconnier @ Camptocamp

When Magento returns no ID when we create an invoice, try to get the invoice's ID otherwise, just consider the job as done, but do not bind with a None ID

1006. By Guewen Baconnier @ Camptocamp

Prevent Binder to bind when external or binding id is missing

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'magentoerpconnect/invoice.py'
2--- magentoerpconnect/invoice.py 2014-05-26 09:37:00 +0000
3+++ magentoerpconnect/invoice.py 2014-07-04 10:03:56 +0000
4@@ -176,6 +176,7 @@
5 mail_notification = magento_store.send_invoice_paid_mail
6
7 lines_info = self._get_lines_info(invoice)
8+ magento_id = None
9 try:
10 magento_id = self._export_invoice(magento_order.magento_id,
11 lines_info,
12@@ -190,18 +191,32 @@
13 'the invoice id.',
14 magento_order.magento_id)
15 magento_id = self._get_existing_invoice(magento_order)
16+ if magento_id is None:
17+ # In that case, we let the exception bubble up so
18+ # the user is informed of the 102 error.
19+ # We couldn't find the invoice supposedly existing
20+ # so an investigation may be necessary.
21+ raise
22 else:
23 raise
24+ # When the invoice already exists on Magento, it may return
25+ # a 102 error (handled above) or return silently without ID
26+ if not magento_id:
27+ # If Magento returned no ID, try to find the Magento
28+ # invoice, but if we don't find it, let consider the job
29+ # as done, because Magento did not raised an error
30+ magento_id = self._get_existing_invoice(magento_order)
31
32- self.binder.bind(magento_id, binding_id)
33+ if magento_id:
34+ self.binder.bind(magento_id, binding_id)
35
36 def _get_existing_invoice(self, magento_order):
37 invoices = self.backend_adapter.search_read(
38- order_id=magento_order.magento_order_id)
39+ order_id=magento_order.magento_order_id)
40 if not invoices:
41- raise
42+ return
43 if len(invoices) > 1:
44- raise
45+ return
46 return invoices[0]['increment_id']
47
48
49
50=== modified file 'magentoerpconnect/unit/binder.py'
51--- magentoerpconnect/unit/binder.py 2014-05-27 15:23:44 +0000
52+++ magentoerpconnect/unit/binder.py 2014-07-04 10:03:56 +0000
53@@ -120,6 +120,10 @@
54 context = self.session.context.copy()
55 context['connector_no_export'] = True
56 now_fmt = datetime.now().strftime(DEFAULT_SERVER_DATETIME_FORMAT)
57+ assert external_id and binding_id, (
58+ "external_id or binding_id missing, "
59+ "got: %s, %s" % (external_id, binding_id)
60+ )
61 self.environment.model.write(
62 self.session.cr,
63 self.session.uid,