itpp-labs/sync-addons

Record mappings

themreza opened this issue · 6 comments

First of all, thank you for creating such a useful module.

I have experience with creating various bi-directional integrations such as product import and export. Sometimes it is necessary to manually create mappings between two records. For example, the product category on Odoo versus on another ecommerce system (given that the names don't match).

What would be the best place for such mappings in Sync Studio?

Links can be used to store the relationship, but the interface for manually creating links is not intuitive.

Does it make sense if I create a Record Mapping tab in the project that looks like this? I'll try to make it create link records under the hood. The interface will have an automatic dropdown for choosing models and records (rather than finding the ID and typing it in).

The reason why I'm asking is to keep it as abstract as possible.

image

Hi @themreza,
maybe you can use sync.param model? E.g, CATEG_OFFICE_FURNITURE with value product_category:13
?

@yelizariev Yes, but that's not so intuitive.

I've come up with an extension on the existing sync.link that allows creating and managing record mappings for any Odoo record.

mapping-demo.mp4

What do you think?

sync.link uses the sys2, ref2, and model fields for Odoo, but the external system only gets sys1 and ref1.

That's why I'm using sys1 to store the field name instead of the name of the external system. It would be nice if there was an extra field for the external model.

Or the alternative is to define the field name mappings in the code section and continue using sys1 as the external system's name.

For external model you can use different relation values in sync.link.
Would you like to make a PR of the mapping feature without adding extra fields?

Sure. Although, now that I've thought about it, it makes more sense to not restrict links on a per-project basis.
I've created two prototypes and I will post the code for both versions.

@yelizariev Am I correct in assuming that demo integrations like Sync Shopify only support a single Shopify instance out of the box?
Since the link relation is generic (e.g. shopify_product), two projects connecting to Shopify might have conflicts if the projects are simply duplicated. If so, it would be helpful to add an optional sync_project_id field to links.

Also, it seems a bit redundant that all Odoo links refer to system 1 as __external__. What do you think about a sync.external.system model that would represent each external system? It could eliminate the need for creating custom relation names for each external system.

This is the modified prototype that is compatible with the current record.set_link method.

extref.mp4
OC_CATEGORY_REL = 'opencart_butopea_category'

def handle_button():
  odoo_website_category = env['product.public.category'].browse(1)
  opencart_category = odoo_website_category.search_links(OC_CATEGORY_REL)
Search links: [('relation', '=', 'opencart_butopea_category'), ('model', '=', 'product.public.category'), ('system1', '=', '__external__'), ('system2', '=', '__odoo__'), ('ref2', 'in', ['1'])] -> sync.link(34,)

@themreza it makes sense to add project_id field to the sync.link model. I even thought that it's already there. Thank you for pointing to the issue!

Also, it seems a bit redundant that all Odoo links refer to system 1 as __external__. What do you think about a sync.external.system model that would represent each external system? It could eliminate the need for creating custom relation names for each external system.

I'd avoid creating a new model. Maybe we could use system1 field as external model value? Anyway, that kind of changes is hard to apply since it may break existing solutions