Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX][14.0] connector_importer and connector_importer_product: proposition of 'fixes' for additional flexibility #141

Open
wants to merge 3 commits into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions connector_importer/components/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,16 @@
"""
req = dict(self.required)
req.update(self.work.options.mapper.get("required_keys", {}))

if self.required_keys_ignore_mapper:
req = self.work.options.mapper.get("required_keys", {})

Check warning on line 59 in connector_importer/components/mapper.py

View check run for this annotation

Codecov / codecov/patch

connector_importer/components/mapper.py#L59

Added line #L59 was not covered by tests

return req

@property
def required_keys_ignore_mapper(self):
return self.work.options.mapper.get("required_keys_ignore_mapper", False)

translatable = []

def translatable_keys(self, create=False):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@
def odoo_post_write(self, odoo_record, values, orig_values):
self._update_template_attributes(odoo_record, values, orig_values)

def odoo_pre_write(self, odoo_record, values, orig_values):
# When updating product.product records, product_tmpl_id is set to False in values
# if not specified in the import type. But we don't want to set it to False
# as the value already exists in the odoo_record
if (
"product_tmpl_id" not in orig_values
and "product_tmpl_id" in odoo_record._fields
and odoo_record.product_tmpl_id
):
values["product_tmpl_id"] = odoo_record.product_tmpl_id.id

Check warning on line 45 in connector_importer_product/components/product_product/record_handler.py

View check run for this annotation

Codecov / codecov/patch

connector_importer_product/components/product_product/record_handler.py#L45

Added line #L45 was not covered by tests

return super().odoo_pre_write(odoo_record, values, orig_values)

Check warning on line 47 in connector_importer_product/components/product_product/record_handler.py

View check run for this annotation

Codecov / codecov/patch

connector_importer_product/components/product_product/record_handler.py#L47

Added line #L47 was not covered by tests

def odoo_create(self, values, orig_values):
odoo_record = super().odoo_create(values, orig_values)
# Set the external ID for the template if necessary
Expand Down Expand Up @@ -112,6 +125,8 @@
# and B, we cannot import a second variant V2 with attributes A and C
# for instance, attributes have to be the same among all variants of a
# template)
if not attr_values_to_import_ids:
Ricardoalso marked this conversation as resolved.
Show resolved Hide resolved
return

Check warning on line 129 in connector_importer_product/components/product_product/record_handler.py

View check run for this annotation

Codecov / codecov/patch

connector_importer_product/components/product_product/record_handler.py#L129

Added line #L129 was not covered by tests
attr_values_to_import = self.env["product.attribute.value"].browse(
attr_values_to_import_ids
)
Expand Down
Loading