Merge lp:~stephane-openerp/magentoerpconnect/certification_for_openerp into lp:magentoerpconnect/oerp5.0-stable
- certification_for_openerp
- Merge into magentoerpconnect
Proposed by
Raphaël Valyi - http://www.akretion.com
Status: | Merged |
---|---|
Merged at revision: | 340 |
Proposed branch: | lp:~stephane-openerp/magentoerpconnect/certification_for_openerp |
Merge into: | lp:magentoerpconnect/oerp5.0-stable |
Diff against target: |
482 lines (+116/-153) 6 files modified
delivery.py (+2/-2) magerp_core.py (+3/-1) magerp_osv.py (+11/-4) product.py (+34/-13) product_images.py (+48/-60) sale.py (+18/-73) |
To merge this branch: | bzr merge lp:~stephane-openerp/magentoerpconnect/certification_for_openerp |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
MagentoERPConnect core editors | Pending | ||
Review via email: mp+33579@code.launchpad.net |
Commit message
Description of the change
see diff
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file '__init__.py' (properties changed: +x to -x) |
2 | === modified file '__terp__.py' (properties changed: +x to -x) |
3 | === modified file 'delivery.py' |
4 | --- delivery.py 2010-08-13 11:42:42 +0000 |
5 | +++ delivery.py 2010-08-24 19:54:41 +0000 |
6 | @@ -31,9 +31,9 @@ |
7 | } |
8 | |
9 | def check_ext_carrier_reference(self, cr, uid, id, magento_incrementid, ctx): |
10 | - conn = ctx.get('conn_obj', False) |
11 | + conn = ctx and ctx.get('conn_obj', False) or False |
12 | mag_carrier = conn.call('sales_order_shipment.getCarriers', [magento_incrementid]) |
13 | - carrier = self.read(cr, uid, id, ['magento_code', 'name'],ctx) |
14 | + carrier = self.read(cr, uid, id, ['magento_code', 'name'], context=ctx) |
15 | if not carrier['magento_code'] in mag_carrier.keys(): |
16 | raise osv.except_osv(_("Error"), _("The carrier %s don't have a magento_code valid!! Indeed the value %s is not in the magento carrier list %s" %(carrier['name'], carrier['magento_code'], mag_carrier.keys()))) |
17 | return True |
18 | |
19 | === modified file 'magerp_core.py' (properties changed: +x to -x) |
20 | --- magerp_core.py 2010-08-19 14:43:01 +0000 |
21 | +++ magerp_core.py 2010-08-24 19:54:41 +0000 |
22 | @@ -23,6 +23,8 @@ |
23 | import magerp_osv |
24 | from base_external_referentials import external_osv |
25 | |
26 | +import tools |
27 | + |
28 | DEBUG = True |
29 | TIMEOUT = 2 |
30 | |
31 | @@ -54,7 +56,7 @@ |
32 | |
33 | return False |
34 | |
35 | - def core_sync(self, cr, uid, ids, ctx={}): |
36 | + def core_sync(self, cr, uid, ids, ctx=None): |
37 | instances = self.browse(cr, uid, ids, ctx) |
38 | filter = [] |
39 | for inst in instances: |
40 | |
41 | === modified file 'magerp_core_view.xml' (properties changed: +x to -x) |
42 | === modified file 'magerp_data.xml' (properties changed: +x to -x) |
43 | === modified file 'magerp_menu.xml' (properties changed: +x to -x) |
44 | === modified file 'magerp_osv.py' (properties changed: +x to -x) |
45 | --- magerp_osv.py 2010-06-24 17:16:02 +0000 |
46 | +++ magerp_osv.py 2010-08-24 19:54:41 +0000 |
47 | @@ -204,7 +204,11 @@ |
48 | subject[key] = True |
49 | return subject |
50 | |
51 | - def mage_import_base(self,cr,uid,conn, external_referential_id, defaults={}, context={}): |
52 | + def mage_import_base(self,cr,uid,conn, external_referential_id, defaults=None, context=None): |
53 | + if context is None: |
54 | + context = {} |
55 | + if defaults is None: |
56 | + defaults = {} |
57 | if not 'ids_or_filter' in context.keys(): |
58 | context['ids_or_filter'] = [] |
59 | result = {'create_ids': [], 'write_ids': []} |
60 | @@ -237,12 +241,15 @@ |
61 | |
62 | return result |
63 | |
64 | - def get_external_data(self, cr, uid, conn, external_referential_id, defaults={}, context={}): |
65 | + def get_external_data(self, cr, uid, conn, external_referential_id, defaults=None, context=None): |
66 | """Constructs data using WS or other synch protocols and then call ext_import on it""" |
67 | return self.mage_import_base(cr, uid, conn, external_referential_id, defaults, context)#TODO refactor mage_import_base calls to this interface |
68 | |
69 | #TODO deprecated, remove use |
70 | - def mage_import(self, cr, uid, ids_or_filter, conn, instance, debug=False, defaults={}, *attrs): |
71 | + def mage_import(self, cr, uid, ids_or_filter, conn, instance, debug=False, defaults=None, *attrs): |
72 | + if defaults is None: |
73 | + defaults = {} |
74 | + |
75 | if self._LIST_METHOD: |
76 | magento_records = conn.call(self._LIST_METHOD, ids_or_filter) |
77 | if attrs: |
78 | @@ -253,7 +260,7 @@ |
79 | raise osv.except_osv(_('Undefined List method !'), _("list method is undefined for this object!")) |
80 | |
81 | #TODO deprecated, remove use |
82 | - def get_all_mage_ids(self, cr, uid, ids=[], instance=False): |
83 | + def get_all_mage_ids(self, cr, uid, ids, instance=False): |
84 | search_param = [] |
85 | if instance: |
86 | search_param = [('referential_id', '=', instance)] |
87 | |
88 | === modified file 'partner.py' (properties changed: +x to -x) |
89 | === modified file 'partner_view.xml' (properties changed: +x to -x) |
90 | === modified file 'product.py' (properties changed: +x to -x) |
91 | --- product.py 2010-08-13 03:02:55 +0000 |
92 | +++ product.py 2010-08-24 19:54:41 +0000 |
93 | @@ -84,7 +84,7 @@ |
94 | 'level':lambda * a:1 |
95 | } |
96 | |
97 | - def write(self, cr, uid, ids, vals, ctx={}): |
98 | + def write(self, cr, uid, ids, vals, ctx=None): |
99 | if not 'magerp_stamp' in vals.keys(): |
100 | vals['magerp_stamp'] = time.strftime('%Y-%m-%d %H:%M:%S') |
101 | return super(product_category, self).write(cr, uid, ids, vals, ctx) |
102 | @@ -109,7 +109,7 @@ |
103 | _description = "Attributes of products" |
104 | _rec_name = "attribute_code" |
105 | |
106 | - def _get_group(self, cr, uid, ids, prop, unknow_none, context): |
107 | + def _get_group(self, cr, uid, ids, prop, unknow_none, context=None): |
108 | res = {} |
109 | for attribute in self.browse(cr, uid, ids, context): |
110 | res[attribute.id] = self.pool.get('magerp.product_attribute_groups').extid_to_oeid(cr, uid, attribute.group_id, attribute.referential_id.id) |
111 | @@ -232,8 +232,12 @@ |
112 | else: |
113 | return False |
114 | |
115 | - def write(self, cr, uid, ids, vals, context={}): |
116 | + def write(self, cr, uid, ids, vals, context=None): |
117 | """Will recreate the mapping attributes, beware if you customized some!""" |
118 | + |
119 | + if context is None: |
120 | + context = {} |
121 | + |
122 | if type(ids) == int: |
123 | ids = [ids] |
124 | result = super(magerp_product_attributes, self).write(cr, uid, ids, vals, context) |
125 | @@ -255,8 +259,10 @@ |
126 | self.create_mapping (cr, uid, self._type_conversion[all_vals.get('frontend_input', False)], field_ids, field_name, referential_id, model_id, all_vals, id) |
127 | return result |
128 | |
129 | - def create(self, cr, uid, vals, context={}): |
130 | + def create(self, cr, uid, vals, context=None): |
131 | """Will create product.product new fields accordingly to Magento product custom attributes and also create mappings for them""" |
132 | + if context is None: |
133 | + context = {} |
134 | if not vals['attribute_code'] in self._no_create_list: |
135 | field_name = "x_magerp_" + vals['attribute_code'] |
136 | vals['field_name'] = field_name |
137 | @@ -369,9 +375,11 @@ |
138 | 'referential_id':fields.many2one('external.referential', 'Magento Instance', readonly=True), |
139 | } |
140 | |
141 | - def data_to_save(self, cr, uid, vals_list, update=False, context={}): |
142 | + def data_to_save(self, cr, uid, vals_list, update=False, context=None): |
143 | """This method will take data from vals and use context to create record""" |
144 | |
145 | + if context is None: |
146 | + context = {} |
147 | to_remove_ids = [] |
148 | if update: |
149 | to_remove_ids = self.search(cr, uid, [('attribute_id', '=', context['attribute_id'])]) |
150 | @@ -457,12 +465,12 @@ |
151 | menu_vals['action'] = 'ir.actions.act_window,'+str(action_id) |
152 | self.pool.get('ir.ui.menu').create(cr, uid, menu_vals, context) |
153 | |
154 | - def write(self, cr, uid, ids, vals, context={}): |
155 | + def write(self, cr, uid, ids, vals, context=None): |
156 | res = super(magerp_product_attribute_set, self).write(cr, uid, ids, vals, context) |
157 | self.create_product_menu(cr, uid, ids, vals, context) |
158 | return res |
159 | |
160 | - def create(self, cr, uid, vals, context={}): |
161 | + def create(self, cr, uid, vals, context=None): |
162 | id = super(magerp_product_attribute_set, self).create(cr, uid, vals, context) |
163 | self.create_product_menu(cr, uid, id, vals, context) |
164 | return id |
165 | @@ -573,7 +581,7 @@ |
166 | class product_product(magerp_osv.magerp_osv): |
167 | _inherit = "product.product" |
168 | |
169 | - def _product_type_get(self, cr, uid, context={}): |
170 | + def _product_type_get(self, cr, uid, context=None): |
171 | ids = self.pool.get('magerp.product_product_type').search(cr, uid, [], order='id') |
172 | product_types = self.pool.get('magerp.product_product_type').read(cr, uid, ids, ['product_type','name'], context=context) |
173 | return [(pt['product_type'], pt['name']) for pt in product_types] |
174 | @@ -597,7 +605,7 @@ |
175 | #and will have a nice default vaule anyway, that's why we avoid making them mandatory in the product view |
176 | _magento_fake_mandatory_attrs = ['created_at', 'updated_at', 'has_options', 'required_options', 'model'] |
177 | |
178 | - def write(self, cr, uid, ids, vals, context={}): |
179 | + def write(self, cr, uid, ids, vals, context=None): |
180 | if vals.get('referential_id', False): |
181 | instance = vals['referential_id'] |
182 | #Filter the keys to be changes |
183 | @@ -645,7 +653,7 @@ |
184 | tier_vals['website_id'] = self.pool.get('external.shop.group').mage_to_oe(cr, uid, int(each['website_id']), instance) |
185 | tp_obj.create(cr, uid, tier_vals) |
186 | |
187 | - def create(self, cr, uid, vals, context={}): |
188 | + def create(self, cr, uid, vals, context=None): |
189 | tier_price = False |
190 | if vals.get('referential_id', False): |
191 | instance = vals['referential_id'] |
192 | @@ -660,7 +668,7 @@ |
193 | #Perform other operations |
194 | return crid |
195 | |
196 | - def unlink(self, cr, uid, ids, context={}): |
197 | + def unlink(self, cr, uid, ids, context=None): |
198 | #if product is mapped to magento, not delete it |
199 | not_delete = False |
200 | sale_obj = self.pool.get('sale.shop') |
201 | @@ -755,7 +763,11 @@ |
202 | xml+="</notebook>" |
203 | return xml |
204 | |
205 | - def fields_view_get(self, cr, uid, view_id=None, view_type='form', context={}, toolbar=False, submenu=False): |
206 | + def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): |
207 | + |
208 | + if context is None: |
209 | + context = {} |
210 | + |
211 | result = super(osv.osv, self).fields_view_get(cr, uid, view_id,view_type,context,toolbar=toolbar) |
212 | if view_type == 'form': |
213 | if context.get('set', False): |
214 | @@ -831,7 +843,16 @@ |
215 | self.write(cr, uid, oe_id, {'magento_sku': sku}) |
216 | return res |
217 | |
218 | - def ext_export(self, cr, uid, ids, external_referential_ids=[], defaults={}, context={}): |
219 | + def ext_export(self, cr, uid, ids, external_referential_ids=None, defaults=None, context=None): |
220 | + if context is None: |
221 | + context = {} |
222 | + |
223 | + if defaults is None: |
224 | + defaults = {} |
225 | + |
226 | + if external_referential_ids is None: |
227 | + external_referential_ids = [] |
228 | + |
229 | result = {'create_ids':[], 'write_ids':[]} |
230 | |
231 | ids = self.search(cr, uid, [('id', 'in', ids), ('magento_exportable', '=', True)]) #restrict export to only exportable products |
232 | |
233 | === modified file 'product_images.py' |
234 | --- product_images.py 2010-06-29 11:59:10 +0000 |
235 | +++ product_images.py 2010-08-24 19:54:41 +0000 |
236 | @@ -47,70 +47,58 @@ |
237 | } |
238 | |
239 | def get_changed_ids(self, cr, uid, start_date=False): |
240 | - if start_date: |
241 | - crids = self.pool.get('product.images').search(cr, uid, [('create_date', '>=', start_date)]) |
242 | - wrids = self.pool.get('product.images').search(cr, uid, [('write_date', '>=', start_date)]) |
243 | - for each in crids: |
244 | - if not each in wrids: |
245 | - wrids.append(each) |
246 | - return wrids #return one list of ids |
247 | - else: |
248 | - ids = self.pool.get('product.images').search(cr, uid, []) |
249 | - return ids |
250 | + proxy = self.pool.get('product.images') |
251 | + domain = start_date and ['|', ('create_date', '>=', start_date), ('write_date', '>=', start_date)] or [] |
252 | + return proxy.search(cr, uid, domain) |
253 | |
254 | - def update_remote_images(self, cr, uid, ids, context={}): |
255 | + def update_remote_images(self, cr, uid, ids, context=None): |
256 | + if context is None: |
257 | + context = {} |
258 | logger = netsvc.Logger() |
259 | conn = context.get('conn_obj', False) |
260 | - if conn: |
261 | - for each in self.browse(cr, uid, ids): |
262 | - if each.product_id.magento_exportable: |
263 | - if each.mage_file: #If update |
264 | - types = [] |
265 | - if each.small_image: |
266 | - types.append('small_image') |
267 | - if each.base_image: |
268 | - types.append('image') |
269 | - if each.thumbnail: |
270 | - types.append('thumbnail') |
271 | - result = conn.call('catalog_product_attribute_media.update', |
272 | - [each.product_id.magento_sku, |
273 | - each.mage_file, |
274 | - {'label':each.name, |
275 | - 'exclude':each.exclude, |
276 | - 'types':types, |
277 | - } |
278 | - ]) |
279 | - #self.write(cr, uid, each.id, {'mage_file':result}) |
280 | - else: |
281 | - if each.product_id.magento_sku: |
282 | - logger.notifyChannel('ext synchro', netsvc.LOG_INFO, "Sending %s's image: %s" %(each.product_id.name, each.product_id.magento_sku)) |
283 | - result = conn.call('catalog_product_attribute_media.create', |
284 | - [each.product_id.magento_sku, |
285 | - {'file':{ |
286 | - 'content':self.get_image(cr, uid, each.id), |
287 | - 'mime':each.filename and mimetypes.guess_type(each.filename)[0] or 'image/jpeg', |
288 | - } |
289 | - } |
290 | - ]) |
291 | - self.write(cr, uid, each.id, {'mage_file':result}) |
292 | - types = [] |
293 | - if each.small_image: |
294 | - types.append('small_image') |
295 | - if each.base_image: |
296 | - types.append('image') |
297 | - if each.thumbnail: |
298 | - types.append('thumbnail') |
299 | - new_result = conn.call('catalog_product_attribute_media.update', |
300 | - [each.product_id.magento_sku, |
301 | - result, |
302 | - {'label':each.name, |
303 | - 'exclude':each.exclude, |
304 | - 'types':types, |
305 | + if not conn: |
306 | + return False |
307 | + |
308 | + def detect_types(image): |
309 | + types = [] |
310 | + if image.small_image: |
311 | + types.append('small_image') |
312 | + if image.base_image: |
313 | + types.append('image') |
314 | + if image.thumbnail: |
315 | + types.append('thumbnail') |
316 | + return types |
317 | + |
318 | + def update_image(content, image): |
319 | + result = conn.call('catalog_product_attribute_media.update', |
320 | + [image.product_id.magento_sku, |
321 | + content, |
322 | + {'label':image.name, |
323 | + 'exclude':image.exclude, |
324 | + 'types':detect_types(image), |
325 | + } |
326 | + ]) |
327 | + return result |
328 | + |
329 | + for each in self.browse(cr, uid, ids, context=context): |
330 | + if not each.product_id.magento_exportable: |
331 | + continue |
332 | + |
333 | + if each.mage_file: #If update |
334 | + result = update_image(each.mage_file, each) |
335 | + else: |
336 | + if each.product_id.magento_sku: |
337 | + logger.notifyChannel('ext synchro', netsvc.LOG_INFO, "Sending %s's image: %s" %(each.product_id.name, each.product_id.magento_sku)) |
338 | + result = conn.call('catalog_product_attribute_media.create', |
339 | + [each.product_id.magento_sku, |
340 | + {'file':{ |
341 | + 'content':self.get_image(cr, uid, each.id), |
342 | + 'mime':each.filename and mimetypes.guess_type(each.filename)[0] or 'image/jpeg', |
343 | } |
344 | - ]) |
345 | - #self.write(cr, uid, each.id, {'mage_file':new_result}) |
346 | - else: |
347 | - return False |
348 | + } |
349 | + ]) |
350 | + self.write(cr, uid, each.id, {'mage_file':result}) |
351 | + result = update_image(result, each) |
352 | return True |
353 | |
354 | product_images() |
355 | |
356 | === modified file 'product_view.xml' (properties changed: +x to -x) |
357 | === modified file 'sale.py' (properties changed: +x to -x) |
358 | --- sale.py 2010-07-16 15:57:40 +0000 |
359 | +++ sale.py 2010-08-24 19:54:41 +0000 |
360 | @@ -139,90 +139,35 @@ |
361 | |
362 | |
363 | |
364 | + def _sale_shop(self, cr, uid, callback, context=None): |
365 | + proxy = self.pool.get('sale.shop') |
366 | + domain = [ ('magento_shop', '=', True), ('auto_import', '=', True) ] |
367 | + |
368 | + ids = proxy.search(cr, uid, domain, context=context) |
369 | + if ids: |
370 | + callback(cr, uid, ids, context=context) |
371 | + |
372 | + tools.debug(callback) |
373 | + tools.debug(ids) |
374 | + |
375 | # Schedules functions ============ # |
376 | def run_import_orders_scheduler(self, cr, uid, context=None): |
377 | - if context == None: |
378 | - context = {} |
379 | - sale_obj = self.pool.get('sale.shop') |
380 | - search_params = [ |
381 | - ('magento_shop', '=', True), |
382 | - ('auto_import', '=', True), |
383 | - ] |
384 | - shops_ids = sale_obj.search(cr, uid, search_params) |
385 | - if shops_ids: |
386 | - self.import_orders(cr, uid, shops_ids, context) |
387 | - if DEBUG: |
388 | - print "run_import_orders_scheduler: %s" % shops_ids |
389 | + self._sale_shop(cr, uid, self.import_orders, context=context) |
390 | |
391 | def run_update_orders_scheduler(self, cr, uid, context=None): |
392 | - if context == None: |
393 | - context = {} |
394 | - sale_obj = self.pool.get('sale.shop') |
395 | - search_params = [ |
396 | - ('magento_shop', '=', True), |
397 | - ('auto_import', '=', True), |
398 | - ] |
399 | - shops_ids = sale_obj.search(cr, uid, search_params) |
400 | - if shops_ids: |
401 | - self.update_orders(cr, uid, shops_ids, context) |
402 | - if DEBUG: |
403 | - print "run_update_orders_scheduler: %s" % shops_ids |
404 | + self._sale_shop(cr, uid, self.update_orders, context=context) |
405 | |
406 | def run_export_catalog_scheduler(self, cr, uid, context=None): |
407 | - if context == None: |
408 | - context = {} |
409 | - sale_obj = self.pool.get('sale.shop') |
410 | - search_params = [ |
411 | - ('magento_shop', '=', True), |
412 | - ('auto_import', '=', True), |
413 | - ] |
414 | - shops_ids = sale_obj.search(cr, uid, search_params) |
415 | - if shops_ids: |
416 | - self.export_catalog(cr, uid, shops_ids, context) |
417 | - if DEBUG: |
418 | - print "run_export_catalog_scheduler: %s" % shops_ids |
419 | + self._sale_shop(cr, uid, self.export_catalog, context=context) |
420 | |
421 | def run_export_stock_levels_scheduler(self, cr, uid, context=None): |
422 | - if context == None: |
423 | - context = {} |
424 | - sale_obj = self.pool.get('sale.shop') |
425 | - search_params = [ |
426 | - ('magento_shop', '=', True), |
427 | - ('auto_import', '=', True), |
428 | - ] |
429 | - shops_ids = sale_obj.search(cr, uid, search_params) |
430 | - if shops_ids: |
431 | - self.export_inventory(cr, uid, shops_ids, context) |
432 | - if DEBUG: |
433 | - print "run_export_stock_levels_scheduler: %s" % shops_ids |
434 | + self._sale_shop(cr, uid, self.export_inventory, context=context) |
435 | |
436 | def run_update_images_scheduler(self, cr, uid, context=None): |
437 | - if context == None: |
438 | - context = {} |
439 | - sale_obj = self.pool.get('sale.shop') |
440 | - search_params = [ |
441 | - ('magento_shop', '=', True), |
442 | - ('auto_import', '=', True), |
443 | - ] |
444 | - shops_ids = sale_obj.search(cr, uid, search_params) |
445 | - if shops_ids: |
446 | - self.export_images(cr, uid, shops_ids, context) |
447 | - if DEBUG: |
448 | - print "run_update_images_scheduler: %s" % shops_ids |
449 | + self._sale_shop(cr, uid, self.export_images, context=context) |
450 | |
451 | def run_export_shipping_scheduler(self, cr, uid, context=None): |
452 | - if context == None: |
453 | - context = {} |
454 | - sale_obj = self.pool.get('sale.shop') |
455 | - search_params = [ |
456 | - ('magento_shop', '=', True), |
457 | - ('auto_import', '=', True), |
458 | - ] |
459 | - shops_ids = sale_obj.search(cr, uid, search_params) |
460 | - if shops_ids: |
461 | - self.export_shipping(cr, uid, shops_ids, context) |
462 | - if DEBUG: |
463 | - print "run_export_shipping_scheduler: %s" % shops_ids |
464 | + self._sale_shop(cr, uid, self.export_shipping, context=context) |
465 | |
466 | sale_shop() |
467 | |
468 | @@ -235,7 +180,7 @@ |
469 | 'magento_storeview_id': fields.many2one('magerp.storeviews', 'Magento Store View'), |
470 | } |
471 | |
472 | - def _auto_init(self, cr, context={}): |
473 | + def _auto_init(self, cr, context=None): |
474 | cr.execute("ALTER TABLE sale_order_line ALTER COLUMN discount TYPE numeric(16,6);") |
475 | cr.execute("ALTER TABLE account_invoice_line ALTER COLUMN discount TYPE numeric(16,6);") |
476 | super(sale_order, self)._auto_init(cr, context) |
477 | |
478 | === modified file 'security/ir.model.access.csv' (properties changed: +x to -x) |
479 | === modified file 'settings/external.mapping.template.csv' (properties changed: +x to -x) |
480 | === modified file 'settings/external.mappinglines.template.csv' (properties changed: +x to -x) |
481 | === modified file 'settings/external.referential.type.csv' (properties changed: +x to -x) |
482 | === modified file 'settings/magerp_product_product_type.xml' (properties changed: +x to -x) |