Merge lp:~akretion-team/openerp-connector-magento/openerp-connector-magento-base-catalog-export into lp:~openerp-connector-core-editors/openerp-connector-magento/7.0

Proposed by Sébastien BEAU - http://www.akretion.com
Status: Rejected
Rejected by: Sébastien BEAU - http://www.akretion.com
Proposed branch: lp:~akretion-team/openerp-connector-magento/openerp-connector-magento-base-catalog-export
Merge into: lp:~openerp-connector-core-editors/openerp-connector-magento/7.0
Prerequisite: lp:~camptocamp/openerp-connector-magento/7.0-export-dependency+lock
Diff against target: 319 lines (+129/-53)
7 files modified
magentoerpconnect/consumer.py (+16/-0)
magentoerpconnect/product.py (+20/-0)
magentoerpconnect/product_category.py (+35/-1)
magentoerpconnect/product_view.xml (+3/-0)
magentoerpconnect/unit/export_synchronizer.py (+55/-0)
magentoerpconnect_catalog/__init__.py (+0/-1)
magentoerpconnect_catalog/__openerp__.py (+0/-51)
To merge this branch: bzr merge lp:~akretion-team/openerp-connector-magento/openerp-connector-magento-base-catalog-export
Reviewer Review Type Date Requested Status
Sébastien BEAU - http://www.akretion.com Disapprove
Review via email: mp+224104@code.launchpad.net

This proposal supersedes a proposal from 2014-06-18.

Description of the change

This is change done on the existing stable module for being compatible with the magentoerpconnect_catalog and magentoerpconnect_product_variant modules.

Not ready for being merge yet

To post a comment you must log in.
Revision history for this message
Sébastien BEAU - http://www.akretion.com (sebastien.beau) wrote :

This merge have been move on github https://github.com/OCA/connector-magento/pull/4

review: Disapprove

Unmerged revisions

1005. By Sébastien BEAU - http://www.akretion.com

[MERGE] merge lock branch from Guewen, this will prevent job to export twice the same record

1004. By Sébastien BEAU - http://www.akretion.com

[REF] remove magentoerpconnect_catalog as the developpement is manage in a separated branch, will be merged soon

1003. By Sébastien BEAU - http://www.akretion.com

[IMP] commit work done by Augustin Cisterne-Kaas <email address hidden>, David Beal <email address hidden> Chafique Delli <email address hidden> and myself. This have been extracted from working branch on catalog export. Add the delay_unlink_all_binding, add fields visibility/status at the import. Add backendAdapter method, no refactor have been done yet

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'magentoerpconnect/consumer.py'
--- magentoerpconnect/consumer.py 2013-10-09 19:41:58 +0000
+++ magentoerpconnect/consumer.py 2014-06-23 11:02:24 +0000
@@ -66,6 +66,22 @@
66 fields=fields)66 fields=fields)
6767
6868
69@on_record_unlink(model_names=_MODEL_NAMES)
70def delay_unlink_all_bindings(session, model_name, record_id):
71 """ Delay jobs which delete all the bindings of a record.
72
73 In this case, it is called on records of normal models and will delay
74 the deletion for all the bindings.
75 """
76 if session.context.get('connector_no_export'):
77 return
78 model = session.pool.get(model_name)
79 record = model.browse(session.cr, session.uid,
80 record_id, context=session.context)
81 for binding in record.magento_bind_ids:
82 delay_unlink(session, binding._model._name, binding.id)
83
84
69@on_record_unlink(model_names=_BIND_MODEL_NAMES)85@on_record_unlink(model_names=_BIND_MODEL_NAMES)
70def delay_unlink(session, model_name, record_id):86def delay_unlink(session, model_name, record_id):
71 """ Delay a job which delete a record on Magento.87 """ Delay a job which delete a record on Magento.
7288
=== modified file 'magentoerpconnect/product.py'
--- magentoerpconnect/product.py 2014-06-14 20:30:26 +0000
+++ magentoerpconnect/product.py 2014-06-23 11:02:24 +0000
@@ -88,6 +88,18 @@
88 'product_type': fields.selection(_product_type_get,88 'product_type': fields.selection(_product_type_get,
89 'Magento Product Type',89 'Magento Product Type',
90 required=True),90 required=True),
91 'visibility': fields.selection(
92 [('1', 'Not Visible Individually'),
93 ('2', 'Catalog'),
94 ('3', 'Search'),
95 ('4', 'Catalog, Search')],
96 string='Visibility in Magento',
97 required=True),
98 'status': fields.selection(
99 [('1', 'Enabled'),
100 ('2', 'Disabled')],
101 string='Status in Magento',
102 required=True),
91 'manage_stock': fields.selection(103 'manage_stock': fields.selection(
92 [('use_default', 'Use Default Config'),104 [('use_default', 'Use Default Config'),
93 ('no', 'Do Not Manage Stock'),105 ('no', 'Do Not Manage Stock'),
@@ -116,6 +128,8 @@
116 'manage_stock': 'use_default',128 'manage_stock': 'use_default',
117 'backorders': 'use_default',129 'backorders': 'use_default',
118 'no_stock_sync': False,130 'no_stock_sync': False,
131 'visibility': '4',
132 'status': '1',
119 }133 }
120134
121 _sql_constraints = [135 _sql_constraints = [
@@ -205,6 +219,10 @@
205 in self._call('%s.list' % self._magento_model,219 in self._call('%s.list' % self._magento_model,
206 [filters] if filters else [{}])]220 [filters] if filters else [{}])]
207221
222 def create(self, data):
223 return self._call('%s.create'% self._magento_model,
224 [data.pop('product_type'),data.pop('attrset'),data.pop('sku'),data])
225
208 def read(self, id, storeview_id=None, attributes=None):226 def read(self, id, storeview_id=None, attributes=None):
209 """ Returns the information of a record227 """ Returns the information of a record
210228
@@ -429,6 +447,8 @@
429 ('type_id', 'product_type'),447 ('type_id', 'product_type'),
430 (normalize_datetime('created_at'), 'created_at'),448 (normalize_datetime('created_at'), 'created_at'),
431 (normalize_datetime('updated_at'), 'updated_at'),449 (normalize_datetime('updated_at'), 'updated_at'),
450 ('visibility', 'visibility'),
451 ('status', 'status')
432 ]452 ]
433453
434 @mapping454 @mapping
435455
=== modified file 'magentoerpconnect/product_category.py'
--- magentoerpconnect/product_category.py 2014-05-26 09:37:00 +0000
+++ magentoerpconnect/product_category.py 2014-06-23 11:02:24 +0000
@@ -25,7 +25,8 @@
25from openerp.addons.connector.unit.mapper import (mapping,25from openerp.addons.connector.unit.mapper import (mapping,
26 ImportMapper26 ImportMapper
27 )27 )
28from openerp.addons.connector.exception import IDMissingInBackend28from openerp.addons.connector.exception import (MappingError,
29 IDMissingInBackend)
29from .unit.backend_adapter import GenericAdapter30from .unit.backend_adapter import GenericAdapter
30from .unit.import_synchronizer import (DelayedBatchImport,31from .unit.import_synchronizer import (DelayedBatchImport,
31 MagentoImportSynchronizer,32 MagentoImportSynchronizer,
@@ -49,6 +50,8 @@
49 required=True,50 required=True,
50 ondelete='cascade'),51 ondelete='cascade'),
51 'description': fields.text('Description', translate=True),52 'description': fields.text('Description', translate=True),
53 'is_active': fields.boolean('Active in magento'),
54 'include_in_menu': fields.boolean('Include in magento menu'),
52 'magento_parent_id': fields.many2one(55 'magento_parent_id': fields.many2one(
53 'magento.product.category',56 'magento.product.category',
54 string='Magento Parent Category',57 string='Magento Parent Category',
@@ -59,6 +62,11 @@
59 string='Magento Child Categories'),62 string='Magento Child Categories'),
60 }63 }
6164
65 _defaults = {
66 'is_active': True,
67 'include_in_menu': False,
68 }
69
62 _sql_constraints = [70 _sql_constraints = [
63 ('magento_uniq', 'unique(backend_id, magento_id)',71 ('magento_uniq', 'unique(backend_id, magento_id)',
64 'A product category with same ID on Magento already exists.'),72 'A product category with same ID on Magento already exists.'),
@@ -100,6 +108,30 @@
100 else:108 else:
101 raise109 raise
102110
111 def update_image(self, data):
112 for name in ['image', 'thumbnail']:
113 if data.get(name + '_binary'):
114 img = self._call('%s.create'% 'ol_catalog_category_media',
115 [data[name], data.pop(name + '_binary')])
116 if img == 'Error in file creation':
117 #TODO FIX error management
118 raise Exception("Image creation: ",
119 "Magento tried to insert image (%s) but there is "
120 "no sufficient grants in the folder "
121 "'media/catalog/category' if it exists" %data[name])
122 return True
123
124 def create(self, data):
125 self.update_image(data)
126 return self._call('%s.create'% self._magento_model,
127 [data['parent_id'],data])
128
129 def write(self, id, data, storeview=None):
130 """ Update records on the external system """
131 self.update_image(data)
132 return self._call('%s.update' % self._magento_model,
133 [int(id), data, storeview])
134
103 def search(self, filters=None, from_date=None):135 def search(self, filters=None, from_date=None):
104 """ Search records according to some criterias and returns a136 """ Search records according to some criterias and returns a
105 list of ids137 list of ids
@@ -217,6 +249,8 @@
217249
218 direct = [250 direct = [
219 ('description', 'description'),251 ('description', 'description'),
252 ('is_active','is_active'),
253 ('include_in_menu','include_in_menu')
220 ]254 ]
221255
222 @mapping256 @mapping
223257
=== modified file 'magentoerpconnect/product_view.xml'
--- magentoerpconnect/product_view.xml 2014-05-26 09:32:38 +0000
+++ magentoerpconnect/product_view.xml 2014-06-23 11:02:24 +0000
@@ -77,7 +77,10 @@
77 <field name="magento_id"/>77 <field name="magento_id"/>
78 <field name="created_at" readonly="1"/>78 <field name="created_at" readonly="1"/>
79 <field name="updated_at" readonly="1"/>79 <field name="updated_at" readonly="1"/>
80 <field name="visibility" />
81 <field name="status" />
80 <field name="product_type" readonly="1"/>82 <field name="product_type" readonly="1"/>
83 <field name="website_ids" />
81 </group>84 </group>
82 <group string="Inventory Options">85 <group string="Inventory Options">
83 <field name="no_stock_sync"/>86 <field name="no_stock_sync"/>
8487
=== modified file 'magentoerpconnect/unit/export_synchronizer.py'
--- magentoerpconnect/unit/export_synchronizer.py 2014-06-23 11:02:24 +0000
+++ magentoerpconnect/unit/export_synchronizer.py 2014-06-23 11:02:24 +0000
@@ -103,6 +103,10 @@
103 """ Return the raw OpenERP data for ``self.binding_id`` """103 """ Return the raw OpenERP data for ``self.binding_id`` """
104 return self.session.browse(self.model._name, self.binding_id)104 return self.session.browse(self.model._name, self.binding_id)
105105
106 def _after_export(self):
107 """ Run the after export"""
108 return
109
106 def run(self, binding_id, *args, **kwargs):110 def run(self, binding_id, *args, **kwargs):
107 """ Run the synchronization111 """ Run the synchronization
108112
@@ -128,6 +132,7 @@
128 # The commit will also release the lock acquired on the binding132 # The commit will also release the lock acquired on the binding
129 # record133 # record
130 self.session.commit()134 self.session.commit()
135 self._after_export()
131 return result136 return result
132137
133 def _run(self):138 def _run(self):
@@ -366,14 +371,64 @@
366 record = self._update_data(map_record, fields=fields)371 record = self._update_data(map_record, fields=fields)
367 if not record:372 if not record:
368 return _('Nothing to export.')373 return _('Nothing to export.')
374 # special check on data before export
375 self._validate_data(record)
369 self._update(record)376 self._update(record)
370 else:377 else:
371 record = self._create_data(map_record, fields=fields)378 record = self._create_data(map_record, fields=fields)
372 if not record:379 if not record:
373 return _('Nothing to export.')380 return _('Nothing to export.')
374 self.magento_id = self._create(record)381 self.magento_id = self._create(record)
382 self.session.cr.commit()
375 return _('Record exported with ID %s on Magento.') % self.magento_id383 return _('Record exported with ID %s on Magento.') % self.magento_id
376384
385class MagentoTranslationExporter(MagentoExporter):
386 """ A common flow for the exports record with translation to Magento """
387
388 def _get_translatable_field(self, fields):
389 # find the translatable fields of the model
390 # Note we consider that a translatable field in Magento
391 # must be a translatable field in OpenERP and vice-versa
392 # you can change this behaviour in your own module
393 all_fields = self.model.fields_get(self.session.cr, self.session.uid,
394 context=self.session.context)
395
396 translatable_fields = [field for field, attrs in all_fields.iteritems()
397 if attrs.get('translate') and (not fields or field in fields)]
398 return translatable_fields
399
400
401 def _run(self, fields=None):
402 default_lang = self.backend_record.default_lang_id
403 session = self.session
404 if session.context is None:
405 session.context = {}
406 session.context['lang'] = default_lang.code
407 res = super(MagentoTranslationExporter, self)._run(fields)
408
409 storeview_ids = session.search(
410 'magento.storeview',
411 [('backend_id', '=', self.backend_record.id)])
412 storeviews = session.browse('magento.storeview', storeview_ids)
413 lang_storeviews = [sv for sv in storeviews
414 if sv.lang_id and sv.lang_id != default_lang]
415 if lang_storeviews:
416 translatable_fields = self._get_translatable_field(fields)
417 if translatable_fields:
418 for storeview in lang_storeviews:
419 session.context['lang'] = storeview.lang_id.code
420 self.binding_record = self._get_openerp_data()
421 self._map_data(fields=translatable_fields)
422 record = self.mapper.data
423 if not record:
424 return _('nothing to export.')
425 # special check on data before export
426 self._validate_data(record)
427 binder = self.get_binder_for_model('magento.storeview')
428 magento_storeview_id = binder.to_backend(storeview.id)
429 self.backend_adapter.write(self.magento_id, record, magento_storeview_id)
430 return res
431
377432
378@job433@job
379@related_action(action=unwrap_binding)434@related_action(action=unwrap_binding)
380435
=== removed directory 'magentoerpconnect_catalog'
=== removed file 'magentoerpconnect_catalog/__init__.py'
--- magentoerpconnect_catalog/__init__.py 2013-03-19 15:41:34 +0000
+++ magentoerpconnect_catalog/__init__.py 1970-01-01 00:00:00 +0000
@@ -1,1 +0,0 @@
1# -*- coding: utf-8 -*-
20
=== removed file 'magentoerpconnect_catalog/__openerp__.py'
--- magentoerpconnect_catalog/__openerp__.py 2013-03-19 15:41:34 +0000
+++ magentoerpconnect_catalog/__openerp__.py 1970-01-01 00:00:00 +0000
@@ -1,51 +0,0 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Guewen Baconnier
5# Copyright 2013 Camptocamp SA
6# Copyright 2013 Akretion
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU Affero General Public License as
10# published by the Free Software Foundation, either version 3 of the
11# License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21##############################################################################
22
23
24{'name': 'Magento Connector - Catalog',
25 'version': '2.0.0',
26 'category': 'Connector',
27 'depends': ['magentoerpconnect',
28 'product_links',
29 'product_images',
30 ],
31 'author': 'MagentoERPconnect Core Editors',
32 'license': 'AGPL-3',
33 'website': 'https://launchpad.net/magentoerpconnect',
34 'description': """
35Magento Connector - Catalog
36===========================
37
38Extension for **Magento Connector**, add management of the product's catalog:
39
40* product links
41* product images
42* export of products, categories, links and images
43
44""",
45 'images': [],
46 'demo': [],
47 'data': [],
48 'installable': True,
49 'application': False,
50}
51