Skip to content

Commit

Permalink
[FIX] small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
PierrickBrun committed Mar 15, 2018
1 parent b3051c4 commit 33f682c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,18 @@ def attribute_id(self, record):
'attribute_id': record['magento_attribute'].odoo_id.id,
'magento_attribute_id': record['magento_attribute'].id,
}

@mapping
def odoo_id(self, record):
""" Will bind the value on a existing one
with the same name and attribute """
if not record['magento_attribute']:
return

value = self.env['product.attribute.value'].search(
[('name', '=', record['label']),
('attribute_id', '=', record['magento_attribute'].odoo_id)],
limit=1
)
if value:
return {'odoo_id': value.id}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ def _update(self, binding, data):
if binding._name == 'magento.product.product':
if binding.product_tmpl_id.magento_bind_ids:
for tmpl_field in self.env['product.template']._fields.keys():
data.pop(tmpl_field)
# Do not raise error when key is missing
data.pop(tmpl_field, False)
return super(ProductImporter, self)._update(binding, data)
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ def _after_import(self, binding):
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']))
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

0 comments on commit 33f682c

Please sign in to comment.