0
votes

I need to get value field2 from list values in field1. Field1 is relation many2many with field in another model. I tried to use domain for it but everytime I received error.

class filial_page_products(models.Model):
    gallery_rstamp_products_ids = fields.Many2many('product.template',
                                     'gallery_rstamp_products_rel',
                                     'gallery_rstamp_products_ids', 'filial_page_new_rstamp_products_ids',
                                     'Gallery products')
    default_gallery_product_id =  fields.Many2one('product.template','Default maket', domain="[(default_gallery_product_id, 'in', 'filial_page_gallery_rstamp_products_ids')]")

class product(models.Model):
    _inherit = 'product.template'
    filial_page_gallery_rstamp_products_ids = fields.Many2many('product.template',
                                 'gallery_rstamp_products_rel',
                                 'filial_page_recovery_rstamp_products_ids', 'gallery_rstamp_products_ids',
                                 'Gallery list')
    filial_page_default_maket_product_ids = fields.One2many('pr_filials.filial_page_products',
                                                            'default_gallery_product_id',
                                                            'Linked page products')

How can I use domain to select only those values that are specified in the gallery_rstamp_products_ids field? of course, I can set default_gallery_product_id from all products but I don't like it.

1
Use onchange methodNavi

1 Answers

0
votes

Your domain doesn't look quite right. The left operand should be quoted and the right side should not be quoted (unless it's actually supposed to be evaluated as a string).

domain="[('default_gallery_product_id', 'in', filial_page_gallery_rstamp_products_ids)]"

Note, there's a special format required for filtering against x2many fields (one2many or many2many). You may need to use this (below), however, there have been reports of issues using this in newer versions.

domain="[('default_gallery_product_id', 'in', filial_page_gallery_rstamp_products_ids[0][2])]"

Here's some documentation on domains.