odoo 关于many2many 和one2many

many2many

(0,0,{values}) 根据values里面的信息新建一个记录。

(1,ID,{values})更新id=ID的记录(写入values里面的数据)

(2,ID) 删除id=ID的数据(调用unlink方法,删除数据以及整个主从数据链接关系)

(3,ID) 切断主从数据的链接关系但是不删除这个数据

(4,ID) 为id=ID的数据添加主从链接关系。

(5) 删除所有的从数据的链接关系就是向所有的从数据调用(3,ID)

(6,0,[IDs]) 用IDs里面的记录替换原来的记录(就是先执行(5)再执行循环IDs执行(4,ID))

例子[(6, 0, [8, 5, 6, 4])] 设置 many2many to ids [8, 5, 6, 4]

one2many

(0, 0,{ values })根据values里面的信息新建一个记录。

(1,ID,{values}) 更新id=ID的记录(对id=ID的执行write 写入values里面的数据)

(2,ID) 删除id=ID的数据(调用unlink方法,删除数据以及整个主从数据链接关系)

转载原文链接:https://my.oschina.net/u/138005/blog/3001427

https://blog.csdn.net/weixin_34258782/article/details/91977303

One2many and Many2many use a special “commands” format to manipulate the set of records stored in/associated with the field.

One2many和Many2many使用特殊的“命令”格式来操纵存储在字段中/与字段相关联的记录集。

This format is a list of triplets executed sequentially, where each triplet is a command to execute on the set of records. Not all commands apply in all situations. Possible commands are:

此格式是按顺序执行的三元组列表,其中每个三元组是在记录集上执行的命令。 并非所有命令都适用于所有情况。 可能的命令是:

(0, _, values)

adds a new record created from the provided value dict.

添加从提供的值dict创建的新记录。

(1, id, values)

updates an existing record of id id with the values in values. Can not be used in create().

使用值中的值更新 id id的现有记录。 不能在create()中使用。

(2, id, _)

removes the record of id id from the set, then deletes it (from the database). Can not be used in create().

从集合中删除 id id的记录,然后删除它(从数据库中)。 不能在create()中使用。

(3, id, _)

removes the record of id id from the set, but does not delete it. Can not be used on One2many. Can not be used in create().

从集合中删除 id id的记录,但不删除它。 不能在One2many上使用。 不能在create()中使用。

(4, id, _)

adds an existing record of id id to the set. Can not be used on One2many.

将id id的现有记录添加到集合中。 不能在One2many上使用。

(5, _, _)

removes all records from the set, equivalent to using the command 3on every record explicitly. Can not be used on One2many. Can not be used in create().

从集合中删除所有记录,相当于在每条记录中明确使用命令3。 不能在One2many上使用。 不能在create()中使用。

(6, _, ids)

replaces all existing records in the set by the ids list, equivalent to using the command 5 followed by a command 4 for each id in ids.

替换ids列表中集合中的所有现有记录,相当于使用命令5,后跟命令4,用于id中的每个id。

 

Values marked as _ in the list above are ignored and can be anything, generally 0 or False.

上面列表中标记为_的值将被忽略,可以是任何值,通常为0或False。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Odoo中,可以通过Many2one字段给Many2many字段传递值。这可以通过使用Odoo的特殊语法和API来实现。 具体方法如下: 1. 在Many2one字段对应的模型中,添加一个Many2many字段,用于存储传递的值。例如,我们在模型A中添加一个Many2many字段,用于存储传递给模型B的值。 ```python class ModelA(models.Model): _name = 'model.a' name = fields.Char(string='Name') value_ids = fields.Many2many(comodel_name='model.b', string='Values') ``` 2. 在Many2one字段对应的模板中,添加一个Many2many字段的下拉菜单,用于选择传递的值。这可以通过使用Odoo的特殊语法和API来实现。例如,我们在模板中添加一个下拉菜单,用于选择传递给模型B的值。 ```xml <field name="value_ids" widget="many2many_tags"/> ``` 3. 在Many2one字段对应的模型中,添加一个按钮,用于触发传递操作。按钮的onClick方法中,通过API获取Many2many字段的值,并将其传递给Many2one字段对应的记录中。例如,我们在模型A中添加一个按钮,用于触发传递操作。 ```python @api.multi def transfer_values(self): for record in self: values = record.value_ids.ids record.other_model_id.write({'many2many_field': [(6, 0, values)]}) ``` 在上述代码中,我们通过API获取Many2many字段的值,并将其传递给Many2one字段对应的记录中。 通过上述方法,我们可以实现Many2one字段给Many2many字段传递值的操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值