odoo之模块继承

本文详细介绍了Odoo中模块的继承机制,包括in-place继承、视图和数据的继承,以及其他如原型继承、代理继承、mixin类集成模型等方法。在in-place继承中,可以直接在原有模型上进行修改和扩展。对于视图和数据的继承,可以通过指定视图的外部标识符进行修改,而数据修改则使用ID进行更新或创建。文章还探讨了更复杂的XPath表达式用于视图定位,以及如何继承Python方法和Web控制器。
摘要由CSDN通过智能技术生成
  1. 在被继承模块的同级文件夹中创建继承模块的文件夹
  2. 创建__init__.py__manifest__.py
  3. __manifest__.py中depends属性中加上被继承的模块名'depends': ['module_name'],

in-place继承

in-place继承实际上就是对已有模型的引用并在原处做修改。

  1. 在py文件里定义类,使用_inherit属性即可,_inherit = 'module_name'
  2. 这种继承会获得原有模型的所有属性,如果想更改已有字段、属性甚至方法,直接在此模型里重写即可,如果想添加新的字段、属性和方法,直接在此模型写即可。
  3. 这种继承中所做的所有更改都会作用在原有模型上。

视图和数据的继承

视图的继承与修改
  1. 添加inherit_id属性,inherit_id记录字段通过 ref 属性指向继承视图的外部标识符,<field name="inherit_id" ref="module_name.view_name" />ref可以将指定视图的外部标识符转换成数据库里的id。
  2. 定位节点的方法有三种,官方文档是这样讲的:

There are three types of element locators for matching a target
element:

  1. An xpath element with an expr attribute. expr is an XPath expression applied to the current arch, the first node it finds is the match
  2. a field element with a name attribute, matches the first field with thesame name. All other attributes are ignored during matching
  3. any other element: the first element with the same name and identical attributes(ignoring position and version attributes) is matched

(1) 最简单的方法就是第二种——使用唯一标识属性,也就是field中的name字段。
在arch里定义:

<field na
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值