Merge lp:~arthru/prestashoperpconnect/import-product-combinations into lp:prestashoperpconnect

Proposed by arthru
Status: Superseded
Proposed branch: lp:~arthru/prestashoperpconnect/import-product-combinations
Merge into: lp:prestashoperpconnect
Diff against target: 664 lines (+521/-17)
8 files modified
prestashoperpconnect/__init__.py (+1/-0)
prestashoperpconnect/__openerp__.py (+2/-0)
prestashoperpconnect/product.py (+47/-12)
prestashoperpconnect/product_combination.py (+397/-0)
prestashoperpconnect/security/ir.model.access.csv (+3/-1)
prestashoperpconnect/unit/binder.py (+3/-0)
prestashoperpconnect/unit/import_synchronizer.py (+54/-0)
prestashoperpconnect/unit/mapper.py (+14/-4)
To merge this branch: bzr merge lp:~arthru/prestashoperpconnect/import-product-combinations
Reviewer Review Type Date Requested Status
arthru Needs Resubmitting
Guewen Baconnier @ Camptocamp code review Needs Fixing
Review via email: mp+192704@code.launchpad.net

This proposal has been superseded by a proposal from 2013-10-29.

Description of the change

This permits to import a product by combination in prestashop

To post a comment you must log in.
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Good piece of work Arthur,

Some comments:

--

What is a "product combination". At least a few words (in the docstring of the Python module product_combination.py) to explain this concept could be useful.

--

l.44-47, l.217ff. l.226ff (and other places, possibly on methods search, browse, read, create, unlink)

    model = self.session.pool.get('product.product')
    product_ids = model.search(self.session.cr, self.session.uid, [
        ('default_code', '=', code)
    ])

A better idiom is:

    product_ids = self.session.search('product.product', [('default_code', '=', code)])

(side note on the alignment: "Arguments on first line forbidden when not using vertical alignment", source http://www.python.org/dev/peps/pep-0008/#indentation)

--

l.134
"unidecode" is to add in the "external_dependencies" in __openerp__.py

--

l.212 (and each time you use the unwrap keyword argument of to_openerp())

Please use the keyword when calling a keyword argument, so instead of

    attribute_id = option_binder.to_openerp(
        option_value['id_attribute_group'], True)

Use

    attribute_id = option_binder.to_openerp(
        option_value['id_attribute_group'], unwrap=True)

--
l.264, l.302, l.453

Instead of:

  type(main_product[attribute]) is list

Use:

  isinstance(main_product[attribute], list)

--
l.306-321:
suggestion (as you want): externalize the part which get the option value in another ConnectorUnit, allowing to customize the way the options values are get.

--
l.599
    if len(combinations) == 0:
=>
    if not combinations:

--

Thanks!

review: Needs Fixing (code review)
278. By arthru

Add a comment on product_combination

279. By arthru

Clean calls to the pool using the session API

280. By arthru

Add unidecode to the external dependencies

281. By arthru

Explicitly set the unwrap keywrod when used in binder.to_openerp

282. By arthru

Use isinstance instead of type comparisons

Revision history for this message
arthru (arthru) wrote :

I made most of the changes. Thanks a lot for these advice, I'll try to apply them in the code that already exist !

review: Needs Resubmitting
283. By arthru

Fix the dependency on unidecode

284. By arthru

Fix a search call

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'prestashoperpconnect/__init__.py'
--- prestashoperpconnect/__init__.py 2013-08-12 17:37:07 +0000
+++ prestashoperpconnect/__init__.py 2013-10-29 09:24:05 +0000
@@ -27,6 +27,7 @@
27import prestashop_model27import prestashop_model
28import partner28import partner
29import product29import product
30import product_combination
30import sale31import sale
31import setting32import setting
32import delivery33import delivery
3334
=== modified file 'prestashoperpconnect/__openerp__.py'
--- prestashoperpconnect/__openerp__.py 2013-10-08 14:32:58 +0000
+++ prestashoperpconnect/__openerp__.py 2013-10-29 09:24:05 +0000
@@ -32,7 +32,9 @@
32 "product_m2mcategories",32 "product_m2mcategories",
33 "connector_ecommerce",33 "connector_ecommerce",
34 "product_images",34 "product_images",
35 "product_custom_attributes",
35 ],36 ],
37 "external_dependencies": ["unidecode"],
36 "author": "PrestashopERPconnect Core Editors",38 "author": "PrestashopERPconnect Core Editors",
37 "description": """This module connects OpenERP and Prestashop.39 "description": """This module connects OpenERP and Prestashop.
3840
3941
=== modified file 'prestashoperpconnect/product.py'
--- prestashoperpconnect/product.py 2013-10-25 12:39:24 +0000
+++ prestashoperpconnect/product.py 2013-10-29 09:24:05 +0000
@@ -203,6 +203,24 @@
203 return {'date_upd': datetime.datetime.now()}203 return {'date_upd': datetime.datetime.now()}
204 return {'date_upd': record['date_upd']}204 return {'date_upd': record['date_upd']}
205205
206 def has_combinations(self, record):
207 combinations = record.get('associations', {}).get(
208 'combinations', {}).get('combinations', [])
209 return len(combinations) != 0
210
211 @mapping
212 def attribute_set_id(self, record):
213 if self.has_combinations(record) and 'attribute_set_id' in record:
214 return {'attribute_set_id': record['attribute_set_id']}
215 return {}
216
217 def _product_code_exists(self, code):
218 model = self.session.pool.get('product.product')
219 product_ids = model.search(self.session.cr, self.session.uid, [
220 ('default_code', '=', code)
221 ])
222 return len(product_ids) > 0
223
206 @mapping224 @mapping
207 def image(self, record):225 def image(self, record):
208 if record['id_default_image']['value'] == '':226 if record['id_default_image']['value'] == '':
@@ -216,9 +234,17 @@
216234
217 @mapping235 @mapping
218 def default_code(self, record):236 def default_code(self, record):
219 if record.get('reference'):237 if not record.get('reference'):
220 return {'default_code': record.get('reference')}238 return {}
221 return {}239 code = record.get('reference')
240 if not self._product_code_exists(code):
241 return {'default_code': code}
242 i = 1
243 current_code = '%s_%d' % (code, i)
244 while self._product_code_exists(current_code):
245 i += 1
246 current_code = '%s_%d' % (code, i)
247 return {'default_code': current_code}
222248
223 @mapping249 @mapping
224 def active(self, record):250 def active(self, record):
@@ -226,7 +252,11 @@
226252
227 @mapping253 @mapping
228 def sale_ok(self, record):254 def sale_ok(self, record):
229 return {'sale_ok': record['available_for_order'] == '1'}255 # if this product has combinations, we do not want to sell this product,
256 # but its combinations (so sale_ok = False in that case).
257 sale_ok = (record['available_for_order'] == '1'
258 and not self.has_combinations(record))
259 return {'sale_ok': sale_ok}
230260
231 @mapping261 @mapping
232 def categ_id(self, record):262 def categ_id(self, record):
@@ -286,10 +316,14 @@
286316
287 @mapping317 @mapping
288 def type(self, record):318 def type(self, record):
289 product_type = {"type": 'product'}319 # If the product has combinations, this main product is not a real
290 if record['type']['value'] and record['type']['value'] == 'virtual':320 # product. So it is set to a 'service' kind of product. Should better be
291 product_type = {"type": 'consu'}321 # a 'virtual' product... but it does not exist...
292 return product_type322 # The same if the product is a virtual one in prestashop.
323 if ((record['type']['value'] and record['type']['value'] == 'virtual')
324 or self.has_combinations(record)):
325 return {"type": 'service'}
326 return {"type": 'product'}
293327
294328
295class product_product(orm.Model):329class product_product(orm.Model):
@@ -328,10 +362,6 @@
328 'always_available': fields.boolean(362 'always_available': fields.boolean(
329 'Active',363 'Active',
330 help='if check, this object is always available'),364 help='if check, this object is always available'),
331 'sale_ok': fields.boolean(
332 'For sale',
333 help='see parent field'
334 ),
335 'quantity': fields.float(365 'quantity': fields.float(
336 'Computed Quantity',366 'Computed Quantity',
337 help="Last computed quantity to send on Prestashop."367 help="Last computed quantity to send on Prestashop."
@@ -363,6 +393,11 @@
363 translate=True,393 translate=True,
364 required=True,394 required=True,
365 ),395 ),
396 'combinations_ids': fields.one2many(
397 'prestashop.product.combination',
398 'main_product_id',
399 string='Combinations'
400 ),
366 }401 }
367402
368 _sql_constraints = [403 _sql_constraints = [
369404
=== added file 'prestashoperpconnect/product_combination.py'
--- prestashoperpconnect/product_combination.py 1970-01-01 00:00:00 +0000
+++ prestashoperpconnect/product_combination.py 2013-10-29 09:24:05 +0000
@@ -0,0 +1,397 @@
1'''
2A product combination is a product with different attributes in prestashop.
3In prestashop, we can sell a product or a combination of a product with some
4attributes.
5
6For example, for the iPod product we can found in demo data, it has some
7combinations with different colors and different storage size.
8
9We map that in OpenERP to a product.product with an attribute.set defined for
10the main product.
11'''
12
13from unidecode import unidecode
14
15from openerp.osv import fields, orm
16from backend import prestashop
17from .unit.backend_adapter import GenericAdapter
18from .unit.import_synchronizer import PrestashopImportSynchronizer
19from .unit.import_synchronizer import TranslatableRecordImport
20from .unit.mapper import PrestashopImportMapper
21from openerp.addons.connector.unit.backend_adapter import BackendAdapter
22from openerp.addons.connector.unit.mapper import mapping
23
24
25class product_product(orm.Model):
26 _inherit = 'product.product'
27
28 _columns = {
29 'prestashop_combinations_bind_ids': fields.one2many(
30 'prestashop.product.combination',
31 'openerp_id',
32 string='PrestaShop Bindings (combinations)'
33 ),
34 }
35
36
37class prestashop_product_combination(orm.Model):
38 _name = 'prestashop.product.combination'
39 _inherit = 'prestashop.binding'
40 _inherits = {'product.product': 'openerp_id'}
41
42 _columns = {
43 'openerp_id': fields.many2one(
44 'product.product',
45 string='Product',
46 required=True,
47 ondelete='cascade'
48 ),
49 'main_product_id': fields.many2one(
50 'prestashop.product.product',
51 string='Main product',
52 required=True,
53 ondelete='cascade'
54 ),
55 }
56
57
58@prestashop
59class ProductCombinationAdapter(GenericAdapter):
60 _model_name = 'prestashop.product.combination'
61 _prestashop_model = 'combinations'
62
63
64@prestashop
65class ProductCombinationRecordImport(PrestashopImportSynchronizer):
66 _model_name = 'prestashop.product.combination'
67
68 def _import_dependencies(self):
69 record = self.prestashop_record
70 option_values = record.get('associations', {}).get(
71 'product_option_values', {}).get('product_option_value', [])
72 if not isinstance(option_values, list):
73 option_values = [option_values]
74 for option_value in option_values:
75 backend_adapter = self.get_connector_unit_for_model(
76 BackendAdapter,
77 'prestashop.product.combination.option.value'
78 )
79 option_value = backend_adapter.read(option_value['id'])
80 self._check_dependency(
81 option_value['id_attribute_group'],
82 'prestashop.product.combination.option',
83 )
84
85 self.check_location(option_value)
86
87 def check_location(self, option_value):
88 option_binder = self.get_binder_for_model(
89 'prestashop.product.combination.option')
90 attribute_id = option_binder.to_openerp(
91 option_value['id_attribute_group'], unwrap=True)
92 product = self.mapper.main_product(self.prestashop_record)
93 attribute_group_id = product.attribute_set_id.attribute_group_ids[0].id
94
95 attribute_location_ids = self.session.search(
96 'attribute.location',
97 [
98 ('attribute_id', '=', attribute_id),
99 ('attribute_group_id', '=', attribute_group_id)
100 ]
101 )
102 if not attribute_location_ids:
103 self.session.create(
104 'attribute.location',
105 {
106 'attribute_id': attribute_id,
107 'attribute_group_id': attribute_group_id,
108 }
109 )
110
111
112@prestashop
113class ProductCombinationMapper(PrestashopImportMapper):
114 _model_name = 'prestashop.product.combination'
115
116 direct = [
117 ('weight', 'weight'),
118 ('wholesale_price', 'standard_price'),
119 ('price', 'lst_price'),
120 ]
121
122 from_main = [
123 'name',
124 'categ_id',
125 'categ_ids',
126 'taxes_ids',
127 'type',
128 'company_id',
129 ]
130
131 @mapping
132 def from_main_product(self, record):
133 main_product = self.main_product(record)
134 result = {}
135 for attribute in self.from_main:
136 if attribute not in main_product:
137 continue
138 if hasattr(main_product[attribute], 'id'):
139 result[attribute] = main_product[attribute].id
140 elif isinstance(main_product[attribute]), list):
141 ids = []
142 for element in main_product[attribute]:
143 ids.append(element.id)
144 result[attribute] = [(6, 0, ids)]
145 else:
146 result[attribute] = main_product[attribute]
147 return result
148
149 def main_product(self, record):
150 if hasattr(self, '_main_product'):
151 return self._main_product
152 product_id = self.get_main_product_id(record)
153 self._main_product = self.session.browse(
154 'prestashop.product.product',
155 product_id
156 )
157 return self._main_product
158
159 def get_main_product_id(self, record):
160 product_binder = self.get_binder_for_model(
161 'prestashop.product.product')
162 return product_binder.to_openerp(record['id_product'])
163
164 @mapping
165 def attribute_set_id(self, record):
166 product = self.main_product(record)
167 if 'attribute_set_id' in product:
168 return {'attribute_set_id': product.attribute_set_id.id}
169 return {}
170
171 @mapping
172 def attributes_values(self, record):
173 option_values = record['associations']['product_option_values'][
174 'product_option_value']
175 if isinstance(option_values, dict):
176 option_values = [option_values]
177
178 results = {}
179 for option_value in option_values:
180
181 option_value_binder = self.get_binder_for_model(
182 'prestashop.product.combination.option.value')
183 option_value_openerp_id = option_value_binder.to_openerp(
184 option_value['id'])
185
186 option_value_object = self.session.browse(
187 'prestashop.product.combination.option.value',
188 option_value_openerp_id
189 )
190 field_name = option_value_object.attribute_id.name
191 results[field_name] = option_value_object.id
192 return results
193
194 @mapping
195 def main_product_id(self, record):
196 return {'main_product_id': self.get_main_product_id(record)}
197
198 def _product_code_exists(self, code):
199 product_ids = self.session.search('product.product',
200 [('default_code', '=', code)])
201 return len(product_ids) > 0
202
203 @mapping
204 def default_code(self, record):
205 if not record.get('reference'):
206 return {}
207 code = record.get('reference')
208 if not self._product_code_exists(code):
209 return {'default_code': code}
210 i = 1
211 current_code = '%s_%d' % (code, i)
212 while self._product_code_exists(current_code):
213 i += 1
214 current_code = '%s_%d' % (code, i)
215 return {'default_code': current_code}
216
217 ##@mapping
218 ##def active(self, record):
219 ## return {'always_available': bool(int(record['active']))}
220
221 ##@mapping
222 ##def sale_ok(self, record):
223 ## return {'sale_ok': record['available_for_order'] == '1'}
224
225 @mapping
226 def backend_id(self, record):
227 return {'backend_id': self.backend_record.id}
228
229 @mapping
230 def ean13(self, record):
231 if record['ean13'] == '0':
232 return {}
233 return {'ean13': record['ean13']}
234
235
236class attribute_attribute(orm.Model):
237 _inherit = 'attribute.attribute'
238
239 _columns = {
240 'prestashop_bind_ids': fields.one2many(
241 'prestashop.product.combination.option',
242 'openerp_id',
243 string='PrestaShop Bindings (combinations)'
244 ),
245 }
246
247
248class prestashop_product_combination_option(orm.Model):
249 _name = 'prestashop.product.combination.option'
250 _inherit = 'prestashop.binding'
251 _inherits = {'attribute.attribute': 'openerp_id'}
252
253 _columns = {
254 'openerp_id': fields.many2one(
255 'attribute.attribute',
256 string='Attribute',
257 required=True,
258 ondelete='cascade'
259 ),
260 }
261
262
263@prestashop
264class ProductCombinationOptionAdapter(GenericAdapter):
265 _model_name = 'prestashop.product.combination.option'
266 _prestashop_model = 'product_options'
267
268
269@prestashop
270class ProductCombinationOptionRecordImport(PrestashopImportSynchronizer):
271 _model_name = 'prestashop.product.combination.option'
272
273 def _import_values(self):
274 record = self.prestashop_record
275 option_values = record.get('associations', {}).get(
276 'product_option_values', {}).get('product_option_value', [])
277 if not isinstance(option_values, list):
278 option_values = [option_values]
279 for option_value in option_values:
280 self._check_dependency(
281 option_value['id'],
282 'prestashop.product.combination.option.value'
283 )
284
285 def run(self, ext_id):
286 super(ProductCombinationOptionRecordImport, self).run(ext_id)
287
288 self._import_values()
289
290
291@prestashop
292class ProductCombinationOptionMapper(PrestashopImportMapper):
293 _model_name = 'prestashop.product.combination.option'
294
295 @mapping
296 def attribute_type(self, record):
297 return {'attribute_type': 'select'}
298
299 @mapping
300 def model_id(self, record):
301 ids = self.session.search('ir.model',
302 [('model', '=', 'product.product')])
303 assert len(ids) == 1
304 return {'model_id': ids[0], 'model': 'product.product'}
305
306 @mapping
307 def backend_id(self, record):
308 return {'backend_id': self.backend_record.id}
309
310 @mapping
311 def name(self, record):
312 name = None
313 if 'language' in record['name']:
314 language_binder = self.get_binder_for_model('prestashop.res.lang')
315 languages = record['name']['language']
316 if not isinstance(languages, list):
317 languages = [languages]
318 for lang in languages:
319 erp_language_id = language_binder.to_openerp(
320 lang['attrs']['id'])
321 erp_lang = self.session.read(
322 'prestashop.res.lang',
323 erp_language_id,
324 )
325 if erp_lang['code'] == 'en_US':
326 name = lang['value']
327 break
328 if name is None:
329 name = languages[0]['value']
330 else:
331 name = record['name']
332 field_name = 'x_' + unidecode(name.replace(' ', ''))
333 return {'name': field_name, 'field_description': name}
334
335
336class attribute_option(orm.Model):
337 _inherit = 'attribute.option'
338
339 _columns = {
340 'prestashop_bind_ids': fields.one2many(
341 'prestashop.product.combination.option.value',
342 'openerp_id',
343 string='PrestaShop Bindings'
344 ),
345 }
346
347
348class prestashop_product_combination_option_value(orm.Model):
349 _name = 'prestashop.product.combination.option.value'
350 _inherit = 'prestashop.binding'
351 _inherits = {'attribute.option': 'openerp_id'}
352
353 _columns = {
354 'openerp_id': fields.many2one(
355 'attribute.option',
356 string='Attribute',
357 required=True,
358 ondelete='cascade'
359 ),
360 }
361
362
363@prestashop
364class ProductCombinationOptionValueAdapter(GenericAdapter):
365 _model_name = 'prestashop.product.combination.option.value'
366 _prestashop_model = 'product_option_values'
367
368
369@prestashop
370class ProductCombinationOptionValueRecordImport(TranslatableRecordImport):
371 _model_name = 'prestashop.product.combination.option.value'
372
373 _translatable_fields = {
374 'prestashop.product.combination.option.value': ['name'],
375 }
376
377
378@prestashop
379class ProductCombinationOptionValueMapper(PrestashopImportMapper):
380 _model_name = 'prestashop.product.combination.option.value'
381
382 direct = [
383 ('name', 'name'),
384 ('position', 'sequence'),
385 ]
386
387 @mapping
388 def attribute_id(self, record):
389 binder = self.get_binder_for_model(
390 'prestashop.product.combination.option')
391 attribute_id = binder.to_openerp(record['id_attribute_group'],
392 unwrap=True)
393 return {'attribute_id': attribute_id}
394
395 @mapping
396 def backend_id(self, record):
397 return {'backend_id': self.backend_record.id}
0398
=== modified file 'prestashoperpconnect/security/ir.model.access.csv'
--- prestashoperpconnect/security/ir.model.access.csv 2013-08-13 08:22:25 +0000
+++ prestashoperpconnect/security/ir.model.access.csv 2013-10-29 09:24:05 +0000
@@ -20,4 +20,6 @@
20access_prestashop_product_category_full,Full access on prestashop.product.category,model_prestashop_product_category,connector.group_connector_manager,1,1,1,120access_prestashop_product_category_full,Full access on prestashop.product.category,model_prestashop_product_category,connector.group_connector_manager,1,1,1,1
21access_prestashop_product_image_full,Full access on prestashop.product.image,model_prestashop_product_image,connector.group_connector_manager,1,1,1,121access_prestashop_product_image_full,Full access on prestashop.product.image,model_prestashop_product_image,connector.group_connector_manager,1,1,1,1
22access_prestashop_product_product_full,Full access on prestashop.product.product,model_prestashop_product_product,connector.group_connector_manager,1,1,1,122access_prestashop_product_product_full,Full access on prestashop.product.product,model_prestashop_product_product,connector.group_connector_manager,1,1,1,1
2323access_prestashop_product_combination_full,Full access on prestashop.product.combination,model_prestashop_product_combination,connector.group_connector_manager,1,1,1,1
24access_prestashop_product_combination_option_full,Full access on prestashop.product.combination.option,model_prestashop_product_combination_option,connector.group_connector_manager,1,1,1,1
25access_prestashop_product_combination_option_value_full,Full access on prestashop.product.combination.option.value,model_prestashop_product_combination_option_value,connector.group_connector_manager,1,1,1,1
2426
=== modified file 'prestashoperpconnect/unit/binder.py'
--- prestashoperpconnect/unit/binder.py 2013-07-12 13:35:45 +0000
+++ prestashoperpconnect/unit/binder.py 2013-10-29 09:24:05 +0000
@@ -51,6 +51,9 @@
51 'prestashop.product.category',51 'prestashop.product.category',
52 'prestashop.product.image',52 'prestashop.product.image',
53 'prestashop.product.product',53 'prestashop.product.product',
54 'prestashop.product.combination',
55 'prestashop.product.combination.option',
56 'prestashop.product.combination.option.value',
54 'prestashop.sale.order',57 'prestashop.sale.order',
55 'prestashop.sale.order.state',58 'prestashop.sale.order.state',
56 'prestashop.delivery.carrier',59 'prestashop.delivery.carrier',
5760
=== modified file 'prestashoperpconnect/unit/import_synchronizer.py'
--- prestashoperpconnect/unit/import_synchronizer.py 2013-10-25 12:40:37 +0000
+++ prestashoperpconnect/unit/import_synchronizer.py 2013-10-29 09:24:05 +0000
@@ -531,6 +531,20 @@
531531
532 prestashop_record = self._get_prestashop_data()532 prestashop_record = self._get_prestashop_data()
533 associations = prestashop_record.get('associations', {})533 associations = prestashop_record.get('associations', {})
534
535 combinations = associations.get('combinations', {}).get(
536 'combinations', {})
537 if not isinstance(combinations, list):
538 combinations = [combinations]
539 for combination in combinations:
540 if 'id' in combination:
541 import_record(
542 self.session,
543 'prestashop.product.combination',
544 self.backend_record.id,
545 combination['id']
546 )
547
534 images = associations.get('images', {}).get('image', {})548 images = associations.get('images', {}).get('image', {})
535 if not isinstance(images, list):549 if not isinstance(images, list):
536 images = [images]550 images = [images]
@@ -546,11 +560,51 @@
546 )560 )
547561
548 def _import_dependencies(self):562 def _import_dependencies(self):
563 self._import_default_category()
564 self._import_categories()
565 self._import_attribute_set()
566
567 def _import_attribute_set(self):
568 record = self.prestashop_record
569
570 combinations = record.get('associations', {}).get(
571 'combinations', {}).get('combinations', [])
572 if len(combinations) == 0:
573 return
574
575 splitted_record = self._split_per_language(self.prestashop_record)
576 if self._default_language in splitted_record:
577 name = splitted_record[self._default_language]['name']
578 else:
579 name = splitted_record.values()[0]['name']
580
581 product_model_id = self.get_product_model_id()
582 attribute_group = {
583 'model_id': product_model_id,
584 'name': 'Combinations options',
585 'sequence': 0,
586 }
587 attribute_set = {
588 'model_id': product_model_id,
589 'name': name + ' Options',
590 'attribute_group_ids': [(0, 0, attribute_group)],
591 }
592 attribute_set_id = self.session.create('attribute.set', attribute_set)
593 self.prestashop_record['attribute_set_id'] = attribute_set_id
594
595 def get_product_model_id(self):
596 ids = model.search('ir.model', [('model', '=', 'product.product')])
597 assert len(ids) == 1
598 return ids[0]
599
600 def _import_default_category(self):
549 record = self.prestashop_record601 record = self.prestashop_record
550 if int(record['id_category_default']):602 if int(record['id_category_default']):
551 self._check_dependency(record['id_category_default'],603 self._check_dependency(record['id_category_default'],
552 'prestashop.product.category')604 'prestashop.product.category')
553605
606 def _import_categories(self):
607 record = self.prestashop_record
554 associations = record.get('associations', {})608 associations = record.get('associations', {})
555 categories = associations.get('categories', {}).get('category', [])609 categories = associations.get('categories', {}).get('category', [])
556 if not isinstance(categories, list):610 if not isinstance(categories, list):
557611
=== modified file 'prestashoperpconnect/unit/mapper.py'
--- prestashoperpconnect/unit/mapper.py 2013-10-25 12:41:52 +0000
+++ prestashoperpconnect/unit/mapper.py 2013-10-29 09:24:05 +0000
@@ -419,10 +419,20 @@
419419
420 @mapping420 @mapping
421 def product_id(self, record):421 def product_id(self, record):
422 return {'product_id': self.get_openerp_id(422 if ('product_attribute_id' in record and
423 'prestashop.product.product',423 record['product_attribute_id'] != '0'):
424 record['product_id']424 combination_binder = self.get_binder_for_model(
425 )}425 'prestashop.product.combination')
426 product_id = combination_binder.to_openerp(
427 record['product_attribute_id'],
428 unwrap=True
429 )
430 else:
431 product_id = self.get_openerp_id(
432 'prestashop.product.product',
433 record['product_id']
434 )
435 return {'product_id': product_id}
426436
427 @mapping437 @mapping
428 def backend_id(self, record):438 def backend_id(self, record):