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 on 2014-06-23
Status: Rejected
Rejected by: Sébastien BEAU - http://www.akretion.com on 2014-07-04
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 on 2014-07-04
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.

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 on 2014-06-23

[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 on 2014-06-18

[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 on 2014-06-18

[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
1=== modified file 'magentoerpconnect/consumer.py'
2--- magentoerpconnect/consumer.py 2013-10-09 19:41:58 +0000
3+++ magentoerpconnect/consumer.py 2014-06-23 11:02:24 +0000
4@@ -66,6 +66,22 @@
5 fields=fields)
6
7
8+@on_record_unlink(model_names=_MODEL_NAMES)
9+def delay_unlink_all_bindings(session, model_name, record_id):
10+ """ Delay jobs which delete all the bindings of a record.
11+
12+ In this case, it is called on records of normal models and will delay
13+ the deletion for all the bindings.
14+ """
15+ if session.context.get('connector_no_export'):
16+ return
17+ model = session.pool.get(model_name)
18+ record = model.browse(session.cr, session.uid,
19+ record_id, context=session.context)
20+ for binding in record.magento_bind_ids:
21+ delay_unlink(session, binding._model._name, binding.id)
22+
23+
24 @on_record_unlink(model_names=_BIND_MODEL_NAMES)
25 def delay_unlink(session, model_name, record_id):
26 """ Delay a job which delete a record on Magento.
27
28=== modified file 'magentoerpconnect/product.py'
29--- magentoerpconnect/product.py 2014-06-14 20:30:26 +0000
30+++ magentoerpconnect/product.py 2014-06-23 11:02:24 +0000
31@@ -88,6 +88,18 @@
32 'product_type': fields.selection(_product_type_get,
33 'Magento Product Type',
34 required=True),
35+ 'visibility': fields.selection(
36+ [('1', 'Not Visible Individually'),
37+ ('2', 'Catalog'),
38+ ('3', 'Search'),
39+ ('4', 'Catalog, Search')],
40+ string='Visibility in Magento',
41+ required=True),
42+ 'status': fields.selection(
43+ [('1', 'Enabled'),
44+ ('2', 'Disabled')],
45+ string='Status in Magento',
46+ required=True),
47 'manage_stock': fields.selection(
48 [('use_default', 'Use Default Config'),
49 ('no', 'Do Not Manage Stock'),
50@@ -116,6 +128,8 @@
51 'manage_stock': 'use_default',
52 'backorders': 'use_default',
53 'no_stock_sync': False,
54+ 'visibility': '4',
55+ 'status': '1',
56 }
57
58 _sql_constraints = [
59@@ -205,6 +219,10 @@
60 in self._call('%s.list' % self._magento_model,
61 [filters] if filters else [{}])]
62
63+ def create(self, data):
64+ return self._call('%s.create'% self._magento_model,
65+ [data.pop('product_type'),data.pop('attrset'),data.pop('sku'),data])
66+
67 def read(self, id, storeview_id=None, attributes=None):
68 """ Returns the information of a record
69
70@@ -429,6 +447,8 @@
71 ('type_id', 'product_type'),
72 (normalize_datetime('created_at'), 'created_at'),
73 (normalize_datetime('updated_at'), 'updated_at'),
74+ ('visibility', 'visibility'),
75+ ('status', 'status')
76 ]
77
78 @mapping
79
80=== modified file 'magentoerpconnect/product_category.py'
81--- magentoerpconnect/product_category.py 2014-05-26 09:37:00 +0000
82+++ magentoerpconnect/product_category.py 2014-06-23 11:02:24 +0000
83@@ -25,7 +25,8 @@
84 from openerp.addons.connector.unit.mapper import (mapping,
85 ImportMapper
86 )
87-from openerp.addons.connector.exception import IDMissingInBackend
88+from openerp.addons.connector.exception import (MappingError,
89+ IDMissingInBackend)
90 from .unit.backend_adapter import GenericAdapter
91 from .unit.import_synchronizer import (DelayedBatchImport,
92 MagentoImportSynchronizer,
93@@ -49,6 +50,8 @@
94 required=True,
95 ondelete='cascade'),
96 'description': fields.text('Description', translate=True),
97+ 'is_active': fields.boolean('Active in magento'),
98+ 'include_in_menu': fields.boolean('Include in magento menu'),
99 'magento_parent_id': fields.many2one(
100 'magento.product.category',
101 string='Magento Parent Category',
102@@ -59,6 +62,11 @@
103 string='Magento Child Categories'),
104 }
105
106+ _defaults = {
107+ 'is_active': True,
108+ 'include_in_menu': False,
109+ }
110+
111 _sql_constraints = [
112 ('magento_uniq', 'unique(backend_id, magento_id)',
113 'A product category with same ID on Magento already exists.'),
114@@ -100,6 +108,30 @@
115 else:
116 raise
117
118+ def update_image(self, data):
119+ for name in ['image', 'thumbnail']:
120+ if data.get(name + '_binary'):
121+ img = self._call('%s.create'% 'ol_catalog_category_media',
122+ [data[name], data.pop(name + '_binary')])
123+ if img == 'Error in file creation':
124+ #TODO FIX error management
125+ raise Exception("Image creation: ",
126+ "Magento tried to insert image (%s) but there is "
127+ "no sufficient grants in the folder "
128+ "'media/catalog/category' if it exists" %data[name])
129+ return True
130+
131+ def create(self, data):
132+ self.update_image(data)
133+ return self._call('%s.create'% self._magento_model,
134+ [data['parent_id'],data])
135+
136+ def write(self, id, data, storeview=None):
137+ """ Update records on the external system """
138+ self.update_image(data)
139+ return self._call('%s.update' % self._magento_model,
140+ [int(id), data, storeview])
141+
142 def search(self, filters=None, from_date=None):
143 """ Search records according to some criterias and returns a
144 list of ids
145@@ -217,6 +249,8 @@
146
147 direct = [
148 ('description', 'description'),
149+ ('is_active','is_active'),
150+ ('include_in_menu','include_in_menu')
151 ]
152
153 @mapping
154
155=== modified file 'magentoerpconnect/product_view.xml'
156--- magentoerpconnect/product_view.xml 2014-05-26 09:32:38 +0000
157+++ magentoerpconnect/product_view.xml 2014-06-23 11:02:24 +0000
158@@ -77,7 +77,10 @@
159 <field name="magento_id"/>
160 <field name="created_at" readonly="1"/>
161 <field name="updated_at" readonly="1"/>
162+ <field name="visibility" />
163+ <field name="status" />
164 <field name="product_type" readonly="1"/>
165+ <field name="website_ids" />
166 </group>
167 <group string="Inventory Options">
168 <field name="no_stock_sync"/>
169
170=== modified file 'magentoerpconnect/unit/export_synchronizer.py'
171--- magentoerpconnect/unit/export_synchronizer.py 2014-06-23 11:02:24 +0000
172+++ magentoerpconnect/unit/export_synchronizer.py 2014-06-23 11:02:24 +0000
173@@ -103,6 +103,10 @@
174 """ Return the raw OpenERP data for ``self.binding_id`` """
175 return self.session.browse(self.model._name, self.binding_id)
176
177+ def _after_export(self):
178+ """ Run the after export"""
179+ return
180+
181 def run(self, binding_id, *args, **kwargs):
182 """ Run the synchronization
183
184@@ -128,6 +132,7 @@
185 # The commit will also release the lock acquired on the binding
186 # record
187 self.session.commit()
188+ self._after_export()
189 return result
190
191 def _run(self):
192@@ -366,14 +371,64 @@
193 record = self._update_data(map_record, fields=fields)
194 if not record:
195 return _('Nothing to export.')
196+ # special check on data before export
197+ self._validate_data(record)
198 self._update(record)
199 else:
200 record = self._create_data(map_record, fields=fields)
201 if not record:
202 return _('Nothing to export.')
203 self.magento_id = self._create(record)
204+ self.session.cr.commit()
205 return _('Record exported with ID %s on Magento.') % self.magento_id
206
207+class MagentoTranslationExporter(MagentoExporter):
208+ """ A common flow for the exports record with translation to Magento """
209+
210+ def _get_translatable_field(self, fields):
211+ # find the translatable fields of the model
212+ # Note we consider that a translatable field in Magento
213+ # must be a translatable field in OpenERP and vice-versa
214+ # you can change this behaviour in your own module
215+ all_fields = self.model.fields_get(self.session.cr, self.session.uid,
216+ context=self.session.context)
217+
218+ translatable_fields = [field for field, attrs in all_fields.iteritems()
219+ if attrs.get('translate') and (not fields or field in fields)]
220+ return translatable_fields
221+
222+
223+ def _run(self, fields=None):
224+ default_lang = self.backend_record.default_lang_id
225+ session = self.session
226+ if session.context is None:
227+ session.context = {}
228+ session.context['lang'] = default_lang.code
229+ res = super(MagentoTranslationExporter, self)._run(fields)
230+
231+ storeview_ids = session.search(
232+ 'magento.storeview',
233+ [('backend_id', '=', self.backend_record.id)])
234+ storeviews = session.browse('magento.storeview', storeview_ids)
235+ lang_storeviews = [sv for sv in storeviews
236+ if sv.lang_id and sv.lang_id != default_lang]
237+ if lang_storeviews:
238+ translatable_fields = self._get_translatable_field(fields)
239+ if translatable_fields:
240+ for storeview in lang_storeviews:
241+ session.context['lang'] = storeview.lang_id.code
242+ self.binding_record = self._get_openerp_data()
243+ self._map_data(fields=translatable_fields)
244+ record = self.mapper.data
245+ if not record:
246+ return _('nothing to export.')
247+ # special check on data before export
248+ self._validate_data(record)
249+ binder = self.get_binder_for_model('magento.storeview')
250+ magento_storeview_id = binder.to_backend(storeview.id)
251+ self.backend_adapter.write(self.magento_id, record, magento_storeview_id)
252+ return res
253+
254
255 @job
256 @related_action(action=unwrap_binding)
257
258=== removed directory 'magentoerpconnect_catalog'
259=== removed file 'magentoerpconnect_catalog/__init__.py'
260--- magentoerpconnect_catalog/__init__.py 2013-03-19 15:41:34 +0000
261+++ magentoerpconnect_catalog/__init__.py 1970-01-01 00:00:00 +0000
262@@ -1,1 +0,0 @@
263-# -*- coding: utf-8 -*-
264
265=== removed file 'magentoerpconnect_catalog/__openerp__.py'
266--- magentoerpconnect_catalog/__openerp__.py 2013-03-19 15:41:34 +0000
267+++ magentoerpconnect_catalog/__openerp__.py 1970-01-01 00:00:00 +0000
268@@ -1,51 +0,0 @@
269-# -*- coding: utf-8 -*-
270-##############################################################################
271-#
272-# Author: Guewen Baconnier
273-# Copyright 2013 Camptocamp SA
274-# Copyright 2013 Akretion
275-#
276-# This program is free software: you can redistribute it and/or modify
277-# it under the terms of the GNU Affero General Public License as
278-# published by the Free Software Foundation, either version 3 of the
279-# License, or (at your option) any later version.
280-#
281-# This program is distributed in the hope that it will be useful,
282-# but WITHOUT ANY WARRANTY; without even the implied warranty of
283-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
284-# GNU Affero General Public License for more details.
285-#
286-# You should have received a copy of the GNU Affero General Public License
287-# along with this program. If not, see <http://www.gnu.org/licenses/>.
288-#
289-##############################################################################
290-
291-
292-{'name': 'Magento Connector - Catalog',
293- 'version': '2.0.0',
294- 'category': 'Connector',
295- 'depends': ['magentoerpconnect',
296- 'product_links',
297- 'product_images',
298- ],
299- 'author': 'MagentoERPconnect Core Editors',
300- 'license': 'AGPL-3',
301- 'website': 'https://launchpad.net/magentoerpconnect',
302- 'description': """
303-Magento Connector - Catalog
304-===========================
305-
306-Extension for **Magento Connector**, add management of the product's catalog:
307-
308-* product links
309-* product images
310-* export of products, categories, links and images
311-
312-""",
313- 'images': [],
314- 'demo': [],
315- 'data': [],
316- 'installable': True,
317- 'application': False,
318-}
319-