← Back to team overview

openerp-connector-community team mailing list archive

Re: Help me understand jobs and backend ids

 

On 01/18/2015 04:37 PM, Ron wrote:
> Hello,
> 
> I have trouble understanding the whole passing of the backend_id to jobs.
> Jobs of course need context, or an environment, to run in. 
> Typical code I found:
> 
>     product = session.browse(model_name, record_id)
>     backend_id = product.backend_id.id <http://product.backend_id.id>
>     env = get_environment(session, model_name, backend_id)
> 
> Now, does this mean the product model is extended with a many2one
> backend_id? Does this mean the backend_id in the product should be
> set to a specific backend before forking the job? This would be troublesome
> when multiple connectors are in use concurrently
> 
> I do not understand how this is supposed to work. Can someone
> enlighten me?
> 
> Thanks,
> Ron Arts
> 

Hi,

There is no outright rules.

You could add a backend_id field on product.product, but as you say, it
will not be compatible with multiple connectors or multiple backends.

I can give you my recommendation though. This is what you can read here
by the way: http://odoo-connector.com/guides/code_overview.html#bindings

If you want to bind products with your external backend, create a new
models which "_inherits" product.product, example:

class MagentoProductProduct(orm.Model):
    _name = 'magento.product.product'
    _inherits = {'product.product': 'openerp_id'}

This model have at least 3 fields: backend_id (many2one to the backend),
openerp_id (many2one to the product), xxx_id (contains the ID on the
external system), then you can have additional fields such as a
synchronization date, or fields that are only valid for this product and
that backend. The advantage of the model with _inherits is that when you
browse it, you have all the values of the product in the record too.

Then, a 'magento.product.product' has to be created to trigger the
export of the product, examples of use cases:
* the user has to choose which products have to be exported, so it
manually creates the 'magento.product.product' record (one2many field on
the product's view)
* the connector always exports all the records to the backend, so you
may want to override 'create()' in order to automatically create the
binding record.

You can find that in the Magento Connector if you want to see it concretely.



-- 
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