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
=== modified file 'magentoerpconnect/invoice.py'
--- magentoerpconnect/invoice.py 2014-05-26 09:37:00 +0000
+++ magentoerpconnect/invoice.py 2014-07-04 10:03:56 +0000
@@ -176,6 +176,7 @@
176 mail_notification = magento_store.send_invoice_paid_mail176 mail_notification = magento_store.send_invoice_paid_mail
177177
178 lines_info = self._get_lines_info(invoice)178 lines_info = self._get_lines_info(invoice)
179 magento_id = None
179 try:180 try:
180 magento_id = self._export_invoice(magento_order.magento_id,181 magento_id = self._export_invoice(magento_order.magento_id,
181 lines_info,182 lines_info,
@@ -190,18 +191,32 @@
190 'the invoice id.',191 'the invoice id.',
191 magento_order.magento_id)192 magento_order.magento_id)
192 magento_id = self._get_existing_invoice(magento_order)193 magento_id = self._get_existing_invoice(magento_order)
194 if magento_id is None:
195 # In that case, we let the exception bubble up so
196 # the user is informed of the 102 error.
197 # We couldn't find the invoice supposedly existing
198 # so an investigation may be necessary.
199 raise
193 else:200 else:
194 raise201 raise
202 # When the invoice already exists on Magento, it may return
203 # a 102 error (handled above) or return silently without ID
204 if not magento_id:
205 # If Magento returned no ID, try to find the Magento
206 # invoice, but if we don't find it, let consider the job
207 # as done, because Magento did not raised an error
208 magento_id = self._get_existing_invoice(magento_order)
195209
196 self.binder.bind(magento_id, binding_id)210 if magento_id:
211 self.binder.bind(magento_id, binding_id)
197212
198 def _get_existing_invoice(self, magento_order):213 def _get_existing_invoice(self, magento_order):
199 invoices = self.backend_adapter.search_read(214 invoices = self.backend_adapter.search_read(
200 order_id=magento_order.magento_order_id)215 order_id=magento_order.magento_order_id)
201 if not invoices:216 if not invoices:
202 raise217 return
203 if len(invoices) > 1:218 if len(invoices) > 1:
204 raise219 return
205 return invoices[0]['increment_id']220 return invoices[0]['increment_id']
206221
207222
208223
=== modified file 'magentoerpconnect/unit/binder.py'
--- magentoerpconnect/unit/binder.py 2014-05-27 15:23:44 +0000
+++ magentoerpconnect/unit/binder.py 2014-07-04 10:03:56 +0000
@@ -120,6 +120,10 @@
120 context = self.session.context.copy()120 context = self.session.context.copy()
121 context['connector_no_export'] = True121 context['connector_no_export'] = True
122 now_fmt = datetime.now().strftime(DEFAULT_SERVER_DATETIME_FORMAT)122 now_fmt = datetime.now().strftime(DEFAULT_SERVER_DATETIME_FORMAT)
123 assert external_id and binding_id, (
124 "external_id or binding_id missing, "
125 "got: %s, %s" % (external_id, binding_id)
126 )
123 self.environment.model.write(127 self.environment.model.write(
124 self.session.cr,128 self.session.cr,
125 self.session.uid,129 self.session.uid,