Connectors mailing list archives

connectors@odoo-community.org

Avatar

Re: Odoo Connector, how to fire an on_record_create event

by
Ecosoft Co. Ltd., Kitti Upariphutthiphong
- 07/03/2016 09:31:01
I am using the latest version as Guewen suggested.
* Odoo 8.0: release 8.0.3.3.0:
https://github.com/OCA/connector/commit/646ea58f13ff29c9a5b6846e2fb6f4d8de032c09
I already have the event.py in __init__.py.
So, this event.py file alone with out any others can fire the event?

Thanks!

On Mon, Mar 7, 2016 at 3:27 PM, Kitti U. <kittiu@ecosoft.co.th> wrote:
Hi connector experts,

To understand how Odoo Connector works. I start writing a simple use case to export a record from Odoo.

My code in event.py,

from openerp.addons.connector.event import on_record_create
from .unit.export_synchronizer import export_org

@on_record_create(model_names=['connector.res.org'])
def delay_export_org(session, model_name, record_id, fields=None):
    export_org.delay(session, model_name, record_id)

@on_record_create(model_names=['res.org'])
def create_default_binding(session, model_name, record_id, fields=None):
    obj = session.env[model_name].browse(record_id)
    default_backends = session.env['connector.backend'].search([])

    ic_model_name = 'connector.' + model_name
    for backend in default_backends:
        session.env[ic_model_name].create({
            'backend_id': backend.id,
            'openerp_id': obj.id,
            'exported_record': True
        })

I assume that @on_record_create is the key, when I create a record in model res.org, the above code should run. But it wasn't.

Anywhere else I have to tell connector in order to fire the event?

Thank you,

--
Mobile: +66-(0)8-1841-7480
Your ERP Partner => www.ecosoft.co.th



--
Mobile: +66-(0)8-1841-7480
Your ERP Partner => www.ecosoft.co.th

Reference