[英]Odoo record.write() to One2Many
Hope you are well today wherever you are:)希望你今天无论身在何处都好:)
I have one function that makes it possible to retrieve a certain fields from other models, which is using self.env[].search
.我有一个 function 可以从其他模型中检索某些字段,它正在使用self.env[].search
。 I also successfully rewriting the list of result
, but I stumbled upon a confusion where i would like to update
that record into other fields using record.write()
.我也成功地重写了list of result
,但我偶然发现了一个困惑,我想使用record.write()
将该记录update
到其他字段中。
@api.multi
def _my_button(self):
for record in self.env['created.model'].search([]):
record_a = record.mapped('certain_fields') # saving result from certain_fields inside record_a variable
record_b = self.number # A number defined by user in current Odoo <form>
my_new_list = [number * record_b for number in record_a] # rewriting record_a values
record.write({'destination_field': my_new_list}) #trying to put my_new_list to other fields
It's practically working when i change my_new_list
to integer for testing purpose, but i couldn't get it work because dictionary doesn't seems to accept my_new_list
.当我出于测试目的将 my_new_list 更改为my_new_list
时,它实际上可以正常工作,但我无法正常工作,因为字典似乎不接受my_new_list
。
Is there any way or alternative to write my_new_list
within record.write()
?有什么方法或替代方法可以在record.write()
中写入my_new_list
吗?
The value of the destination_field
field should be a list of triplet destination_field
字段的值应该是三元组的列表
For example:例如:
(0, 0, values) (0, 0, 值)
adds a new record created from the providedvalue
dict.添加从提供的value
字典创建的新记录。
Try the following:尝试以下操作:
my_new_list = [(0, 0, {'final_qty': number * record_b}) for number in record_a]
record.write({'product_lines': my_new_list})
field_name
is the field inside the One2Many field used to store number * record_b
value field_name
是One2Many字段里面的字段,用来存储number * record_b
的值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.