Skip to content

Commit

Permalink
Merge PR #122 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by simahawk
  • Loading branch information
OCA-git-bot committed Jul 26, 2023
2 parents 049dba9 + 3841bd6 commit 78a0724
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
5 changes: 3 additions & 2 deletions connector_importer/components/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,14 @@ def _load_mapper_options(self):
"""Retrieve mapper options."""
return {"override_existing": self.must_override_existing}

# TODO: make these contexts customizable via recordset settings
def _odoo_default_context(self):
"""Default context to be used in both create and write methods"""
return {
ctx = {
"importer_type_id": self.recordset.import_type_id.id,
"tracking_disable": True,
}
ctx.update(self.work.options.importer.get("ctx", {}))
return ctx

def _odoo_create_context(self):
"""Inject context variables on create, merged by odoorecord handler."""
Expand Down
20 changes: 18 additions & 2 deletions connector_importer/tests/test_record_importer_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ def _get_components(self):

return [PartnerRecordImporter, PartnerMapper]

def _get_importer(self):
def _get_importer(self, options=None):
options = options or {"importer": {}, "mapper": {}}
with self.backend.work_on(
self.record._name,
components_registry=self.comp_registry,
options=DotDict({"importer": {}, "mapper": {}}),
options=DotDict(options),
) as work:
return work.component(usage="record.importer", model_name="res.partner")

Expand Down Expand Up @@ -103,3 +104,18 @@ def test_importer_get_mapper(self):
importer._mapper_name = "fake.partner.mapper"
mapper = importer._get_mapper()
self.assertEqual(mapper._name, "fake.partner.mapper")

def test_importer_context(self):
importer = self._get_importer(
options={"importer": {"ctx": {"key1": 1, "key2": 2}}, "mapper": {}}
)
importer._init_importer(self.recordset)
self.assertEqual(
importer._odoo_create_context(),
{
"importer_type_id": self.recordset.import_type_id.id,
"tracking_disable": True,
"key1": 1,
"key2": 2,
},
)

0 comments on commit 78a0724

Please sign in to comment.