Skip to content

Commit

Permalink
connector_importer_product: take full control of what are the require…
Browse files Browse the repository at this point in the history
…d_keys

Not forcing required default value if required_keys_ignore_model_required and required_keys are defined in options.mapper.
Adding the new property required_keys_ignore_model_required in order to override the result of required_keys function
  • Loading branch information
Ricardoalso committed Sep 11, 2024
1 parent ec15d21 commit 9811540
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions connector_importer_product/components/product_product/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,27 @@ class ProductProductMapper(Component):

defaults = [("sale_ok", True)]

def required_keys(self, create=False):
"""Return required keys for this mapper.
The importer can use this to determine if a line
has to be skipped.
The recordset will use this to show required fields to users.
"""
req = super().required_keys(create=create)

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

Check warning on line 50 in connector_importer_product/components/product_product/mapper.py

View check run for this annotation

Codecov / codecov/patch

connector_importer_product/components/product_product/mapper.py#L50

Added line #L50 was not covered by tests

return req

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

@mapping
def code(self, record):
"""Ensure there's always a default code.
Expand Down

0 comments on commit 9811540

Please sign in to comment.