Python 如何修复为用户显示的所有产品的树状视图?

Python 如何修复为用户显示的所有产品的树状视图?,python,list,view,tree,odoo,Python,List,View,Tree,Odoo,我创建了一个表来存储一些产品信息 我需要在树中显示产品视图,表单视图。但问题是,产品向所有公司用户展示。我只想向公司用户展示产品。但它也在向其他公司用户展示 型号 class RiceProcurement(models.Model): _name = 'rice.procurement' _description = 'Rice procurement quantity manage table' product_select = fields.Many2one('p

我创建了一个表来存储一些产品信息

我需要在树中显示产品视图,表单视图。但问题是,产品向所有公司用户展示。我只想向公司用户展示产品。但它也在向其他公司用户展示

型号

class RiceProcurement(models.Model):
    _name = 'rice.procurement'
    _description = 'Rice procurement quantity manage table'

    product_select = fields.Many2one('product.template', String='Subsidised Rice', required=True,
                                     domain="[('item_type', '=', 'rice'),"
                                            "('subsidy_type_purchase', '=', 'subsidised'),('uom_id','=',3)]")
    
    product_qty = fields.Float(string='Quantity (in Kg)', digits='Product Unit of Measure', required=True)
    company_id = fields.Many2one('res.company',
                                 string='Company',
                                 required=True,
                                 default=lambda self: self.env.user.company_id.id)
    supplier_id = fields.Many2one('res.partner', string='Supplier', required=True)
    date_approve = fields.Datetime('Confirmation Date', default=lambda self: fields.Datetime.now(),
                                   index=True, copy=False)
    
树视图

<record id="rice_procurement_tree_view" model="ir.ui.view">
        <field name="name">rice.procurement.tree.view</field>
        <field name="model">rice.procurement</field>
        <field name="arch" type="xml">
            <tree string="Rice Procurement" import="0">
                <field name="product_select" domain="[('company_id','=',company_id)]"/>
                <field name="date_approve" string="Date"/>
                <field name="product_qty" sum="Total Quantity"/>
                <field name="company_id" invisible="1"/>
            </tree>
        </field>
    </record>
    <record id="rice_procurement_action" model="ir.actions.act_window">
            <field name="name">Rice procurement</field>
            <field name="res_model">rice.procurement</field>
            <field name="view_mode">tree,form</field>
            <field name="view_mode">list</field>
            <field name="domain">[('company_id','=',company_id)]</field>
    </record>

赖斯。采购。树。视图
大米采购
ir.act.Window

<record id="rice_procurement_tree_view" model="ir.ui.view">
        <field name="name">rice.procurement.tree.view</field>
        <field name="model">rice.procurement</field>
        <field name="arch" type="xml">
            <tree string="Rice Procurement" import="0">
                <field name="product_select" domain="[('company_id','=',company_id)]"/>
                <field name="date_approve" string="Date"/>
                <field name="product_qty" sum="Total Quantity"/>
                <field name="company_id" invisible="1"/>
            </tree>
        </field>
    </record>
    <record id="rice_procurement_action" model="ir.actions.act_window">
            <field name="name">Rice procurement</field>
            <field name="res_model">rice.procurement</field>
            <field name="view_mode">tree,form</field>
            <field name="view_mode">list</field>
            <field name="domain">[('company_id','=',company_id)]</field>
    </record>

大米采购
大米采购
树
列表
[('company_id','=',company_id)]

已存在由ODO添加的记录规则。进入设置->常规设置,如果您在多公司中向下滚动,您可以看到两个选项,一个是通用联系人簿,另一个是通用产品目录

默认情况下,这两个布尔字段将被勾选,在您的情况下,您可以取消勾选公共产品目录

取消勾选后,将在设置->技术->安全->记录规则中显示名为Product multi company的记录规则,该规则最初设置为活动的False

请参阅此文件中的:


最后,我在我的模块中创建了一个角色,现在它开始工作了

在安全文件夹内部创建了一个自定义角色文件来修复此问题

<record id="rice_procurement_company_rule" model="ir.rule">
     <field name="name">Rice Procurement</field>
     <field ref="model_rice_procurement" name="model_id"/>
     <field name="domain_force">[('company_id','in',company_ids)]</field>
     <field name="global" eval="True"/>
</record>

大米采购
[('company_id','in',company_id)]

不清楚你在问什么。您希望每个产品有一个用户吗?您是指当前登录用户还是其他用户?
company\u id
是您的用户吗?你的数据结构是什么样的?@ConnorLow我认为他的项目是多公司的,一家公司的产品会展示给所有公司的所有用户,而他不希望这样?