Skip to content Skip to sidebar Skip to footer

Odoo: How To Search A Parent_id And Its All Child In Product.category

I want to, when the user selected (through Many2one field) a category, I need to find its related parent_id for Brands to add a domain filter on another Many2one field to have rela

Solution 1:

@SDBot, the xml code for this particular model is here...

            <notebook>
                <page string="Order Items">
                    <field name="order_ids">
                        <tree editable="bottom" string="Order Items">
                            <field name="store_id"/>
                            <field name="categry_id"/>
                            <field name="items_id"/>
                            <field name="categ_name"/>
                            <field name="brand_id"/>
                            <field name="unit_id"/>
                            <field name="quantity"/>
                        </tree>
                    </field>
                </page>
            </notebook>

Model where added a field categ_name and a domain in brand_id

class OrderItems(models.Model):
    _name = 'tests.orderitems'
    _description = "Tests Order Items"

    store_id = fields.Many2one('tests.stores', string="Store", ondelete='cascade')
    order_id = fields.Many2one('tests.testsorders')
    categry_id = fields.Many2one('product.category', string="Category",
                                 domain="[['complete_name', 'not like', '%Brands%']]")
    items_id = fields.Many2one('tests.storeitems', string="Item",
                               domain="[['categs_id', '=', categry_id]]")
    categ_name = fields.Char('Category Name', related='categry_id.complete_name')
    brand_id = fields.Many2one('product.category', string="Brand",
                               domain="[('complete_name', 'like', categ_name),('complete_name', '!=', categ_name)]")
    unit_id = fields.Many2one('tests.units', string="Unit")
    quantity = fields.Integer(string="Quantity", required=True, default=1)
    rates = fields.Float(string="Rate", default=0)
    size = fields.Char(string="Size")

Solution 2:

Change your brand_id domain to:

categ_name = fields.char('Category Name', related='categry_id.complete_name')
brand_id = fields.Many2one('product.category', string="Brand",
                           domain="[('complete_name', 'like', categ_name),('complete_name', '!=', categ_name)]")

Here's the preview:

enter image description here


Post a Comment for "Odoo: How To Search A Parent_id And Its All Child In Product.category"