Here are some Helpfull stuff while doing operations on one2many fields:
(0, 0, { values }) link to a new record that needs to be created with the given values dictionary
(1, ID, { values }) update the linked record with id = ID (write values on it)
(2, ID) remove and delete the linked record with id = ID (calls unlink on ID, that will delete the object completely, and the link to it as well)
(3, ID) cut the link to the linked record with id = ID (delete the relationship between the two objects but does not delete the target object itself)
(4, ID) link to existing record with id = ID (adds a relationship)
(5) unlink all (like using (3,ID) for all linked records)
(6, 0, [IDs]) replace the list of linked IDs (like using (5) then (4,ID) for each ID in the list of IDs)
One2many和Many2many使用一种特殊的“命令”格式来操作存储在/与字段关联的一组记录。
(0, _, values)
adds a new record created from the provided value dict
(1, id, values)
用“values”中的值更新id“id”的现有记录。不能在[' create() ']中使用
(2, id, _)
从集合中删除id ' id '的记录,然后(从数据库中)删除它。不能在[' create() ']中使用
(3, id, _)
从集合中删除id ' id '的记录,但不删除它。不能用于[' One2many ']
(4, id, _)
将id ' id '的现有记录添加到集合中。不能在[' One2many ']上使用。
(5, _, _)
从集合中删除所有记录,相当于显式地在每个记录上使用命令“3”。不能用于[' One2many ']
(6, _, ids)
替换ids列表中集合中的所有现有记录,相当于对ids中的每个id使用命令5后面跟着命令4。
_一般代表 0 或者 False
重写删除方法记得最后加
super(类名, self).unlink()
查找类似的,加%,
#('child_ids', '=', False)
# 没有一级科目
domain="[('child_ids', '=', False), '|', ('code', 'like', '6001%'), ('code', 'like', '6051%')]"
遇到增加限制_sql_constraints后日志报提示信息,得手动去数据库中运行,前提是对应的字段不能为null
ALTER TABLE "monomer_statements_cost_line" ADD CONSTRAINT "monomer_statements_cost_line_unique_company_account" UNIQUE(company_id, account_id)
网友评论