← Back to team overview

openerp-connector-community team mailing list archive

Re: module for product mapping on default_code / sku

 

On 04/23/2014 09:14 PM, Jos De Graeve wrote:
> 
> Hello,
> 
> I'm trying to create an extra module that implements binding to existing products in OpenERP based on the products default_code.
> 
> So based on what i saw in the example code, i created a module doing only this:
> 
> http://gitlab.apertoso.be/jos/connector_modules/tree/master/connector_magento_product_bind_ref
> 
> However, after install, i get the following error:
> 
> AssertionError: Several classes found for <class 'openerp.addons.connector.unit.mapper.ImportMapper'> with session <Session db_name: mooddesign, uid: 1>, model name: magento.product.product. Found: set([<class 'openerp.addons.magentoerpconnect.product.ProductImportMapper'>, <class 'openerp.addons.connector_magento_product_bind_ref.product.MyProductImportMapper'>])
> 
> What am i doing wrong ?
> 
> Tnx
> Jos
> 
> 
> 
> Jos De Graeve
> 
> Apertoso business ICT - http://www.apertoso.be/
> Guido Gezellelaan 16 - B-9800 Deinze - Belgium
> 
> Direct: +32 9 381 64 51
> General:+32 9 381 64 50
> Mobile: +32 475 54 68 80
> mail/im/skype: Jos.DeGraeve@xxxxxxxxxxx - apertoso
> 

Hello,

The binding in itself is correct.
Here, you registered your mapper on the @magento backend so when the
connector tries to find the mapper for the products, it finds 2 of them
and can't know which one should be used.

Some alternatives:

If the mapper is specific to one Magento instance (the simplest):
* Register the mapper on your custom backend (@my_magento, ...)

If the mapper should be generic (harder to extend):
* use @magento(replacing=magentoerpconnect.product.ProductImportMapper);
inadvisable because it introduces an incompatibility as soon as 2
concurrent modules both replace the mapper. The risk of incompatibility
can be greatly mitigated when using the next and more recommended technique:
* introduce a sort of hook in the core module: add a @mapping which
calls a new ProductImportBindMapper which responsibility is to define
how a product is linked with existing records, this mapper does nothing
in the core module. Your module can now use
@magento(replacing=magentoerpconnect.product.ProductImportBindMapper).
Thus, it won't totally replace the product mapper, but only the part
concerning how the product is linked to existing records (and if another
module also replaces ProductImportBindMapper, chances are that the
incompatibility would be unavoidable anyway). I'm totally favorable to
merge such hooks which can improve extensibility.

Some additional insights on the extension mechanism here:
http://openerp-connector.com/api/api_backend.html#connector.backend.Backend

I opened a vote to eventually include this mapping in the core module:
https://lists.launchpad.net/openerp-connector-community/msg00332.html

-- 
Guewen Baconnier
Business Solutions Software Developer

Camptocamp SA
PSE A, CH-1015 Lausanne
Phone: +41 21 619 10 39
Office: +41 21 619 10 10
http://www.camptocamp.com/


References