Odoo API constraints


@api.constrains('ir_actions_server_ids')
​def _check_ir_actions_server_ids(self):
​"""
​Constraint to choose actions only for templates
​"""
​for config in self:
​not_temp = config.ir_actions_server_ids.filtered(lambda action: action.model_id.model != "product.template")
​if not_temp:
​raise UserError(_('One of the actions you selected does not relate to product template. Please fix'))

Illustration: Real code example


V.15 migration


Modules

Manifest
__manifest__.py

QWEB import is moved to 'assets' dict

JS import is moved to 'assets' dict

Views

XML
templates rendering

t-raw is deprecated : use t-out

mail data might be prepared using QWEB

Scripts

Python
fields & methods

xmlid_to_res_id is renamed to _xmlid_to_res_id

render_template should define engine

JavaScript

Instead of require: use 'import from'


Check whether model has attribute


if hasattr(MODEL, ATTR):
​# do something 
​pass 

Model - object, e.g. self.env["sale.order"]

Attr - field or method name, e.g. "active", "name_get"


RecordSet Operations


record in recset1 # include
record not in recset1 # not include
recset1 + recset2 # extend
recset1 | recset2 # union
recset1 & recset2 # intersect
recset1 - recset2 # difference


Odoo API constraints



V.15 migration



Check whether model has attribute



RecordSet Operations