Merge lp:~camptocamp/magentoerpconnect/operp6.1-legacy-module-fix1028812 into lp:magentoerpconnect/oerp6.1-oldstable

Proposed by Alexandre Fayolle - camptocamp
Status: Merged
Merged at revision: 651
Proposed branch: lp:~camptocamp/magentoerpconnect/operp6.1-legacy-module-fix1028812
Merge into: lp:magentoerpconnect/oerp6.1-oldstable
Diff against target: 67 lines (+26/-7)
1 file modified
magentoerpconnect/product.py (+26/-7)
To merge this branch: bzr merge lp:~camptocamp/magentoerpconnect/operp6.1-legacy-module-fix1028812
Reviewer Review Type Date Requested Status
Guewen Baconnier @ Camptocamp Approve
MagentoERPConnect core editors Pending
Review via email: mp+116639@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) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'magentoerpconnect/product.py'
2--- magentoerpconnect/product.py 2012-07-05 13:15:15 +0000
3+++ magentoerpconnect/product.py 2012-07-25 12:50:39 +0000
4@@ -1717,15 +1717,23 @@
5 try:
6 product_links = conn.call('product_link.list', [link_type, product.magento_sku])
7 except Exception, e:
8- self.log(cr, uid, product.id, "Error when retrieving the list of links in Magento for product with sku %s and product id %s !" % (product.magento_sku, product.id,))
9- logger.debug("Error when retrieving the list of links in Magento for product with sku %s and product id %s !", product.magento_sku, product.id)
10+ self.log(cr, uid, product.id,
11+ "Error when retrieving the list of links in Magento for "
12+ "product with sku %s and product id %s !" % \
13+ (product.magento_sku, product.id,))
14+ logger.error("Error %s when retrieving the list of links in Magento for "
15+ "product with sku %s and product id %s !",
16+ e, product.magento_sku, product.id)
17
18 for product_link in product_links:
19 ctx = context.copy()
20 ctx['alternative_key'] = product_link['sku']
21- linked_product_id = self.extid_to_oeid(cr, uid, product_link['product_id'], external_referential_id, context=context)
22+ ctx['import_no_new_cr'] = 'True' # otherwise, the product is created in another transaction,
23+ # and the isolation level means we cannot see it in this one,
24+ # resulting in an integrity error on the FK of product_link
25+ linked_product_id = self.extid_to_oeid(cr, uid, product_link['product_id'], external_referential_id, context=ctx)
26 link_data = {
27- 'product_id': product.id,
28+ 'product_id': product.id2,
29 'type': link_type,
30 'linked_product_id': linked_product_id,
31 'sequence': product_link['position'],
32@@ -1744,21 +1752,32 @@
33 return True
34
35 def mag_import_product_links_types(self, cr, uid, ids, link_types, external_referential_id, conn, context=None):
36- if isinstance(ids, (int, long)): ids = [ids]
37+ if isinstance(ids, (int, long)):
38+ ids = [ids]
39 for product in self.browse(cr, uid, ids, context=context):
40 for link_type in link_types:
41 self._mag_import_product_links_type(cr, uid, product, link_type, external_referential_id, conn, context=context)
42 return True
43
44 def mag_import_product_links(self, cr, uid, ids, external_referential_id, conn, context=None):
45+ logger = logging.getLogger('magentoerpconnect')
46 link_types = self.pool.get('external.referential').get_magento_product_link_types(cr, uid, external_referential_id, conn, context=context)
47 local_cr = pooler.get_db(cr.dbname).cursor()
48+ errors = []
49 try:
50 for product_id in ids:
51- self.mag_import_product_links_types(local_cr, uid, [product_id], link_types, external_referential_id, conn, context=context)
52- local_cr.commit()
53+ try:
54+ self.mag_import_product_links_types(local_cr, uid, [product_id], link_types, external_referential_id, conn, context=context)
55+ local_cr.commit()
56+ except Exception, exc:
57+ logger.exception('error during product_links import for product id %s', product_id)
58+ errors.append((product_id, str(exc)))
59 finally:
60 local_cr.close()
61+ if errors:
62+ message = [u'product_id %s: %s' % (product_id, error) for product_id, error in errors]
63+ raise osv.except_osv( _('Error'),
64+ _("Errors during product_links import:\n%s") % u'\n'.join(message))
65 return True
66
67 product_product()