Reputation: 354
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
. 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()
.
@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
.
Is there any way or alternative to write my_new_list
within record.write()
?
Upvotes: 0
Views: 1478
Reputation: 26688
The value of the destination_field
field should be a list of triplet
For example:
(0, 0, values)
adds a new record created from the providedvalue
dict.
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
Upvotes: 1