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
=== modified file 'magentoerpconnect/product.py'
--- magentoerpconnect/product.py 2012-07-05 13:15:15 +0000
+++ magentoerpconnect/product.py 2012-07-25 12:50:39 +0000
@@ -1717,15 +1717,23 @@
1717 try:1717 try:
1718 product_links = conn.call('product_link.list', [link_type, product.magento_sku])1718 product_links = conn.call('product_link.list', [link_type, product.magento_sku])
1719 except Exception, e:1719 except Exception, e:
1720 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,))1720 self.log(cr, uid, product.id,
1721 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)1721 "Error when retrieving the list of links in Magento for "
1722 "product with sku %s and product id %s !" % \
1723 (product.magento_sku, product.id,))
1724 logger.error("Error %s when retrieving the list of links in Magento for "
1725 "product with sku %s and product id %s !",
1726 e, product.magento_sku, product.id)
17221727
1723 for product_link in product_links:1728 for product_link in product_links:
1724 ctx = context.copy()1729 ctx = context.copy()
1725 ctx['alternative_key'] = product_link['sku']1730 ctx['alternative_key'] = product_link['sku']
1726 linked_product_id = self.extid_to_oeid(cr, uid, product_link['product_id'], external_referential_id, context=context)1731 ctx['import_no_new_cr'] = 'True' # otherwise, the product is created in another transaction,
1732 # and the isolation level means we cannot see it in this one,
1733 # resulting in an integrity error on the FK of product_link
1734 linked_product_id = self.extid_to_oeid(cr, uid, product_link['product_id'], external_referential_id, context=ctx)
1727 link_data = {1735 link_data = {
1728 'product_id': product.id,1736 'product_id': product.id2,
1729 'type': link_type,1737 'type': link_type,
1730 'linked_product_id': linked_product_id,1738 'linked_product_id': linked_product_id,
1731 'sequence': product_link['position'],1739 'sequence': product_link['position'],
@@ -1744,21 +1752,32 @@
1744 return True1752 return True
17451753
1746 def mag_import_product_links_types(self, cr, uid, ids, link_types, external_referential_id, conn, context=None):1754 def mag_import_product_links_types(self, cr, uid, ids, link_types, external_referential_id, conn, context=None):
1747 if isinstance(ids, (int, long)): ids = [ids]1755 if isinstance(ids, (int, long)):
1756 ids = [ids]
1748 for product in self.browse(cr, uid, ids, context=context):1757 for product in self.browse(cr, uid, ids, context=context):
1749 for link_type in link_types:1758 for link_type in link_types:
1750 self._mag_import_product_links_type(cr, uid, product, link_type, external_referential_id, conn, context=context)1759 self._mag_import_product_links_type(cr, uid, product, link_type, external_referential_id, conn, context=context)
1751 return True1760 return True
17521761
1753 def mag_import_product_links(self, cr, uid, ids, external_referential_id, conn, context=None):1762 def mag_import_product_links(self, cr, uid, ids, external_referential_id, conn, context=None):
1763 logger = logging.getLogger('magentoerpconnect')
1754 link_types = self.pool.get('external.referential').get_magento_product_link_types(cr, uid, external_referential_id, conn, context=context)1764 link_types = self.pool.get('external.referential').get_magento_product_link_types(cr, uid, external_referential_id, conn, context=context)
1755 local_cr = pooler.get_db(cr.dbname).cursor()1765 local_cr = pooler.get_db(cr.dbname).cursor()
1766 errors = []
1756 try:1767 try:
1757 for product_id in ids:1768 for product_id in ids:
1758 self.mag_import_product_links_types(local_cr, uid, [product_id], link_types, external_referential_id, conn, context=context)1769 try:
1759 local_cr.commit()1770 self.mag_import_product_links_types(local_cr, uid, [product_id], link_types, external_referential_id, conn, context=context)
1771 local_cr.commit()
1772 except Exception, exc:
1773 logger.exception('error during product_links import for product id %s', product_id)
1774 errors.append((product_id, str(exc)))
1760 finally:1775 finally:
1761 local_cr.close()1776 local_cr.close()
1777 if errors:
1778 message = [u'product_id %s: %s' % (product_id, error) for product_id, error in errors]
1779 raise osv.except_osv( _('Error'),
1780 _("Errors during product_links import:\n%s") % u'\n'.join(message))
1762 return True1781 return True
17631782
1764product_product()1783product_product()