Merge lp:~camptocamp/magentoerpconnect/oerp61-oldstable-import-partners-pagination-2013-02-12 into lp:magentoerpconnect/oerp6.1-oldstable

Proposed by Yannick Vaucher @ Camptocamp
Status: Merged
Merged at revision: 666
Proposed branch: lp:~camptocamp/magentoerpconnect/oerp61-oldstable-import-partners-pagination-2013-02-12
Merge into: lp:magentoerpconnect/oerp6.1-oldstable
Diff against target: 62 lines (+24/-5)
1 file modified
magentoerpconnect/sale.py (+24/-5)
To merge this branch: bzr merge lp:~camptocamp/magentoerpconnect/oerp61-oldstable-import-partners-pagination-2013-02-12
Reviewer Review Type Date Requested Status
Guewen Baconnier @ Camptocamp Approve
Alexandre Fayolle - camptocamp code review, no test Approve
Review via email: mp+147986@code.launchpad.net

Description of the change

Improve partner import using ol_customer.search before using customer.list in order to paginate the request.

To post a comment you must log in.
Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

l. 28: use xrange instead of range, and you can probably avoid the creation of this list by iterating directly on the xrange object in the for loop line 31.

review: Needs Fixing (code review, no test)
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

BTW the local variable name customer_groups is a little bit misleading because Magento has a notion of 'customer groups'. customer_chunks would maybe be better. (I propose that just because the MP is already in Needs Fixing).

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

Ok tanks for the reviews. I'll improve that

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

Ok this is now improved

Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) :
review: Approve (code review, no test)
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/sale.py'
--- magentoerpconnect/sale.py 2013-01-10 06:48:02 +0000
+++ magentoerpconnect/sale.py 2013-02-14 13:02:20 +0000
@@ -1,4 +1,4 @@
1# -*- encoding: utf-8 -*-1# -*- coding: utf-8 -*-
2#########################################################################2#########################################################################
3# #3# #
4#########################################################################4#########################################################################
@@ -49,13 +49,33 @@
49 'cancel': 'canceled',49 'cancel': 'canceled',
50 'waiting_date': 'holded'}50 'waiting_date': 'holded'}
51SALE_ORDER_IMPORT_STEP = 20051SALE_ORDER_IMPORT_STEP = 200
52PARTNER_IMPORT_STEP = 400
5253
5354
54class external_shop_group(magerp_osv.magerp_osv):55class external_shop_group(magerp_osv.magerp_osv):
55 _inherit = 'external.shop.group'56 _inherit = 'external.shop.group'
5657
57 @staticmethod58 @staticmethod
58 def _get_magento_partners(connection, from_date=False, website_id=False):59 def _get_magento_partners(connection, filters, delta=PARTNER_IMPORT_STEP):
60 """
61 Get customer using pagination, we get all ids
62 then ask customer info per chunk of ids
63 this to avoid memory and timing issues on Magento server
64
65 :param connection: connection data to magento
66 :param filters: filter terms for partner search
67 :param delta: size of groups to import
68 """
69 customer_ids = connection.call('ol_customer.search', filters)
70
71 data = []
72 for i in xrange(0, len(customer_ids), delta):
73 filters = [{'customer_id': {'in': customer_ids[i:i+delta]}}]
74 data += connection.call('customer.list', filters)
75 return data
76
77 @staticmethod
78 def _get_magento_partners_update(connection, from_date=False, website_id=False):
59 """79 """
60 Get data from magento of new and updated customers since a specific_date80 Get data from magento of new and updated customers since a specific_date
6181
@@ -75,8 +95,7 @@
75 else:95 else:
76 filters = [{'website_id': {'eq': website_id}}]96 filters = [{'website_id': {'eq': website_id}}]
7797
78 data = connection.call('customer.list', filters)98 return external_shop_group._get_magento_partners(connection, filters)
79 return data
8099
81 def _import_partners(self, cr, uid, group, context=None):100 def _import_partners(self, cr, uid, group, context=None):
82 """101 """
@@ -103,7 +122,7 @@
103122
104 # Get partners from magento which where created or updated123 # Get partners from magento which where created or updated
105 # since last import124 # since last import
106 data = self._get_magento_partners(connection, from_date, website_id)125 data = self._get_magento_partners_update(connection, from_date, website_id)
107126
108 data.sort(key=lambda customer: customer['updated_at'] or customer['created_at'])127 data.sort(key=lambda customer: customer['updated_at'] or customer['created_at'])
109128