授权继承的视图继承
模型继承时,使用授权继承方式,也称代理继承,即应用这样的代码:
1 | book_id = fields.Many2one('training.book', string="书籍", delegate=True) |
在写Form视图继承时,容易忽略的一点是在代码中加入一句:
1 | <field name="mode">primary</field> |
这样在Form视图中才可以正常显示。
官方解释:
- View matching
- if a view is requested by (model, type), the view with the right model and type, mode=primary and the lowest priority is matched
- when a view is requested by id, if its mode is not primary its closest parent with mode primary is matched
视图继承中position='move’的用法
直接贴代码:
1 | <record id="view_training_book_copy_form" model="ir.ui.view"> |
year
字段定义在view_training_book_form
视图中,通过position='move'
可以将移动到ISBN字段后面,即可以自定义位置。
官方解释:
the position move can be used as a direct child of a spec with a inside, replace, after or before position attribute to move a node.
1 | <xpath expr="//@target" position="after"> |