I want to know if it is possible for a Many2many field having the records automatically. I tried different things like a default lambda similar to many2one but Many2many didn't have the records.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Akuntansi
- Inventaris
- PoS
- Project
- MRP
Pertanyaan ini telah diberikan tanda
Try with default method
@api.model
def _get_default_product_variant_ids(self):
return self.env['product.product'].search([('type', '=', 'service')]).ids
product_variant_ids = fields.Many2many('product.product', string='Variants', default=_get_default_product_variant_ids)
Yes this worked! I have a question though, should a leaf or domain be mandatory?
Leaf or domain not mandatory, its all on your requirement what should you want to fill up, this given example to setup default value in which format needs only
@Krishna Bhalala yes that works too! much thanks!
Hi,
Try
product_variant_ids = fields.Many2many(
'product.product',
string='Variants',
default=lambda self: self.env['product.product'].search([('can_be_expensed', '=', True)]).ids
)
It gives me an error
ValueError: Invalid field 'can_be_expensed' in leaf "<osv.ExtendedLeaf: ('can_be_expensed', '=', True) on product_product (ctx: )>"
Change domain as per your requirement,This error is because the field 'can_be_expensed' does not exist on the model.
Menikmati diskusi? Jangan hanya membaca, ikuti!
Buat akun sekarang untuk menikmati fitur eksklufi dan agar terlibat dengan komunitas kami!
DaftarPost Terkait | Replies | Tampilan | Aktivitas | |
---|---|---|---|---|
|
1
Feb 23
|
1749 | ||
|
0
Des 19
|
4154 | ||
|
0
Jan 20
|
3471 | ||
How to track One2many field in Odoo12?
Diselesaikan
|
|
3
Nov 23
|
17269 | |
|
1
Feb 24
|
2059 |