Hi, I have the following field definition:
product_ids = fields.One2many('product.product', compute='_return_product_ids')
if prod1 prod2 and prod3 are product.product instances, how can I assign products_ids to those prod1, prod2 and prod3?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
Hi, I have the following field definition:
product_ids = fields.One2many('product.product', compute='_return_product_ids')
if prod1 prod2 and prod3 are product.product instances, how can I assign products_ids to those prod1, prod2 and prod3?
You mean returning those products as return values of the product_ids computed function _return_product_ids. First of all a one2many it's not recomended at all for tgis because of the checks against the needed many2one in the relation table used to maintain the parent - child relationship, so better you switch to a many2many computed field.
In the computed function just return the ids of those products in the format of [(6,0,ids)] where ids is the list of those products id. Also note that the compute function only will be called when the record is saved.
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
1
Dec 19
|
8507 | ||
|
0
Jul 22
|
2731 | ||
|
0
Mar 16
|
2318 | ||
|
0
Dec 15
|
2943 | ||
|
0
Mar 15
|
2792 |