Creating an Odoo Meeting object from an Opportunity in a Python Automated Action

In Odoo you can create objects from an automated action, with a bit of Python code. But creating a Meeting was a bit tricky.

env['calendar.event'].create({
    'name': 'Outward flight: {0}'.format(record.display_name),
    'start_date': record.flight_outward_date,
    'stop_date': record.flight_outward_date,
    'allday': True,
})

The first you would try, is to create the required fields, like name and the obvious ones like start_date and stop_date. But this will not work, as other field depend on start/stop fields. Even though there are normally set by on_change handlers automatically, this only happend in formulars, but not when you create a Meeting in Python.

env['calendar.event'].create({
    'name': 'Outward flight: {0}'.format(record.display_name),
    'start_date': record.flight_outward_date,
    'start': datetime.datetime.combine(record.flight_outward_date, datetime.time.min),
    'stop_date': record.flight_outward_date,
    'stop': datetime.datetime.combine(record.flight_outward_date, datetime.time.max),
    'allday': True,
})

The trick is, that you also need to fill in the start and stop fields, as you can see above. The correct code i just took from Meeting code in Odoo. Generally said, when ever a simple create fails because of mising fields, check for on_change handlers in the code, as in Python and with the API you need to do extra work here.

With the Python code above, i created an automated action, which creates a Meeting from a crm.lead field when i move the lead from New to Quallified.

By @MrTango in
Tags :