class ActivityEvent(models.Model): _name = 'activity.event' _inherit = 'event.event' _rec_name = 'test_field' # 字段 test_field = fields.Char(string="字段名稱") # 多對多的關聯表 employee_ids = fields.Many2many('files.employee', 'activity_event_files_employee_rel', string='與會員工') event_type_id = fields.Many2one( 'activity.type', string='Category', readonly=False, states={'done': [('readonly', True)]}, oldname='type')
例:_order =「create_date desc」:根據建立時間降序排列。可指定多個字段。
不指定desc默認升序排列;不指定_order默認id升序排列。git
格式:: _constraints = [(method, 'error message', [field1, ...]), ...]
method檢查方法。返回True | False
error message:不符合檢查條件時(方法返回False)彈出的錯誤信息
[field1, ...]:字段名列表,這些字段的值會出如今錯誤消息中。sql
_sql_constraints:數據庫約束。數據庫
例:_sql_constraints = [ ('number_uniq', 'unique(number, code)', 'error message') ]
會在數據庫添加約束:
CONSTRAINT number_uniq UNIQUE(number, code)dom
格式:_inherit = '父類 _name'函數
格式:_inherits = {'父類 _name': '關聯字段'}字體
例:state = fields.Selection([('draft', 'Draft'),('confirm', 'Confirmed'),('cancel', 'Cancelled')], string='Status')
其中,關聯字段,關聯表/中間表可不填,中間表缺省爲:表1_表2_relui
例:sale_order = fields.One2many("sale.order", "contract_id",string="銷售訂單", domain=[('state','=','sale')])日誌
例:amount = fields.Float(string="金額總計", compute=‘_compute_amount’,store=True)
_compute_amount爲計算函數。code
如下代碼表示:company_id引用hr.payroll.advice中company_id對象
advice_id = fields.Many2one('hr.payroll.advice', string='Bank Advice')company_id = fields.Many2one('res.company', related='advice_id.company_id', string='Company', store=True)