Odoo:如何在 product.category 中搜索 parent_id 及其所有子代 [英] Odoo: how to search a parent_id and its all child in product.category
问题描述
我想,当用户选择(通过 Many2one 字段)一个类别时,我需要为 Brands
找到其相关的 parent_id
以在另一个 Many2one 上添加域过滤器字段以包含这些品牌的相关子条目.由于我是初学者,我无法做到这一点.
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 related child entries of these Brands. As I am beginner I failed to how to do this.
假设 Many2one 字段 category_id
在这里,用户将从前三个条目中选择一个类别,现在我们知道用户想要添加与电子相关的项目,然后系统应填充 Many2one 字段 brand_id代码>在电子相关品牌(所有/电子/品牌除外)上从以下最后 2 个条目中选择所有/电子.
Suppose Many2one field category_id
here, user will select a category from first three entries, now we know that user wants to add an Electronics related item then system should populate Many2one field brand_id
on Electronics related Brands (except All / Electronics / Brands) to select from below last 2 entries here in All / Electronics.
All / Electronics / Personal Computers
All / Electronics / Personal Computers / Laptop
All / Electronics / Personal Computers / Desktop
...
...
All / Electronics / Brands
All / Electronics / Brands / HP
All / Electronics / Brands / IBM
此模型中有更多品牌(表格数据),例如:
There are more brands in this model (table data) like:
All / Foods / Brands
All / Foods / Brands / Hershey
All / Foods / Brands / Heinz
All / Foods / Brands / Oreo
...
All / Services / Brands
All / Services / Brands / IBM Garages
All / Services / Brands / Telos MNS
All / Services / Brands / Relia Quest
...
我的自定义模型类:
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]]")
brand_id = fields.Many2one('product.category', string="Brand",
domain="[['complete_name', 'like', '%Brands%']]")
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")
请帮忙,我该怎么做.
推荐答案
将您的 Brand_id 域更改为:
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)]")
预览如下:
这篇关于Odoo:如何在 product.category 中搜索 parent_id 及其所有子代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!