Skip to content

Commit

Permalink
fix conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
PierrickBrun committed Apr 17, 2018
2 parents 33f682c + f115574 commit abc95a6
Show file tree
Hide file tree
Showing 6 changed files with 1,013 additions and 2,588 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ def _update(self, binding, data):
if modified:
super(ProductAttributePriceImporter, self)._update(binding, data)

def _import_dependencies(self):
product_id = self.magento_record['product_id']
if product_id:
self._import_dependency(product_id, 'magento.product.product')

def run(self, magento_record, force=False):
self.magento_record = magento_record
return super(ProductAttributePriceImporter, self).run(
Expand Down Expand Up @@ -86,5 +81,4 @@ def value_id(self, record):
value = record.get('magento_value').odoo_id
return {
'value_id': value.id,
'magento_value_id': record.get('magento_value').id,
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def odoo_id(self, record):

value = self.env['product.attribute.value'].search(
[('name', '=', record['label']),
('attribute_id', '=', record['magento_attribute'].odoo_id)],
('attribute_id', '=', record['magento_attribute'].odoo_id.id)],
limit=1
)
if value:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ProductImporter(Component):
def _update(self, binding, data):
""" Update an OpenERP record """
if binding._name == 'magento.product.product':
if binding.product_tmpl_id.magento_bind_ids:
if binding.product_tmpl_id.attribute_line_ids:
for tmpl_field in self.env['product.template']._fields.keys():
# Do not raise error when key is missing
data.pop(tmpl_field, False)
Expand Down
89 changes: 45 additions & 44 deletions connector_magento_configurable/models/product_template/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def _prepare_attr_lines(self, binding, magento_attributes):
vals = self._prepare_attribute_vals(attribute)
if vals:
line = self.env['product.attribute.line'].search([
('attribute_id', '=', vals.get('attribute_id')),
('product_tmpl_id', '=', binding.odoo_id.id)
('attribute_id.id', '=', vals.get('attribute_id')),
('product_tmpl_id.id', '=', binding.odoo_id.id)
])
if line:
attribute_line_vals.append((1, line.id, vals))
Expand All @@ -88,52 +88,53 @@ def _prepare_attr_lines(self, binding, magento_attributes):
return attribute_line_vals

def _after_import(self, binding):
attrs = self.backend_adapter.list_attributes(binding.external_id)
if binding.variant_managed_by_magento:
attrs = self.backend_adapter.list_attributes(binding.external_id)

attr_importer = self.component(
usage='record.importer',
model_name='magento.product.attribute')
attr_importer = self.component(
usage='record.importer',
model_name='magento.product.attribute')

for attribute in attrs:
attr_importer.run(attribute)

lines = self._prepare_attr_lines(binding, attrs)
binding.write({'attribute_line_ids': lines})

value_binder = self.binder_for('magento.product.attribute.value')
product_binder = self.binder_for('magento.product.product')

variants = self.backend_adapter.list_variants(binding.external_id)
for variant in variants:
attribute_value_ids = []
self._import_dependency(
variant['entity_id'], 'magento.product.product')
product = product_binder.to_internal(
variant['entity_id'], unwrap=True)
for attribute in attrs:
if variant.get(attribute['attribute_code']):
value = value_binder.to_internal(
variant[attribute['attribute_code']],
unwrap=True)
if not value:
raise MappingError(
"The attribute value with "
"magento id %s is not imported." %
variant[attribute['attribute_code']])
attribute_value_ids.append(value.id)
vals = {'attribute_value_ids': [(6, 0, attribute_value_ids)]}
template = product.product_tmpl_id
if template.id != binding.odoo_id.id:
vals['product_tmpl_id'] = binding.odoo_id.id
product.write(vals)
if not template.product_variant_ids:
template.unlink()
else:
attr_importer.run(attribute)

lines = self._prepare_attr_lines(binding, attrs)
binding.write({'attribute_line_ids': lines})

value_binder = self.binder_for('magento.product.attribute.value')
product_binder = self.binder_for('magento.product.product')

variants = self.backend_adapter.list_variants(binding.external_id)
for variant in variants:
attribute_value_ids = []
self._import_dependency(
variant['entity_id'], 'magento.product.product')
product = product_binder.to_internal(
variant['entity_id'], unwrap=True)
for attribute in attrs:
if variant.get(attribute['attribute_code']):
value = value_binder.to_internal(
variant[attribute['attribute_code']],
unwrap=True)
if not value:
raise MappingError(
"The attribute value with "
"magento id %s is not imported." %
variant[attribute['attribute_code']])
attribute_value_ids.append(value.id)
vals = {'attribute_value_ids': [(6, 0, attribute_value_ids)]}
template = product.product_tmpl_id
if template.id != binding.odoo_id.id:
raise MappingError(
"The template for the product {} (sku {})"
" has many variants".format(
product.default_code, variant['sku']))
vals['product_tmpl_id'] = binding.odoo_id.id
product.write(vals)
if not template.product_variant_ids:
template.unlink()
else:
if template.id != binding.odoo_id.id:
raise MappingError(
"The template for the product {} (sku {})"
" has many variants".format(
product.default_code, variant['sku']))
super(TemplateImporter, self)._after_import(binding)

def run(self, external_id, force=True):
Expand Down
12 changes: 3 additions & 9 deletions connector_magento_configurable/tests/test_import_configurable.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,14 @@ def test_import_product_configurable_links(self):
self.env['magento.product.template'].import_record(
self.backend, '408'
)

template_model = self.env['magento.product.template']
templates = template_model.search([('backend_id', '=', backend_id),
('external_id', '=', '408')])
self.assertEqual(len(templates), 1)

# the configurable importer takes a magento.product.product
# as parameter instead of an sku
self.env['magento.product.template'].import_record(
self.backend, templates
)

tmpl_id = templates[0].id
variants = template_model.search([('backend_id', '=', backend_id),
tmpl_id = templates[0].odoo_id.id
product_model = self.env['magento.product.product']
variants = product_model.search([('backend_id', '=', backend_id),
('product_tmpl_id', '=', tmpl_id)])
self.assertEqual(len(variants), 15)

Expand Down

0 comments on commit abc95a6

Please sign in to comment.