Search code examples
xmlodooodoo-12

Odoo Salesperson Orders restrict


i want that the salesperson only will see the order he created not every order i want to limit that to the record he created

'''

<record model="ir.module.category" id="module_category_flexipharmacy">
        <field name="name">Flexipharmacy</field>
        <field name="description">Select if salesperson or owner.</field>

    </record>

    <record id="group_flexipharmacy_salesperson" model="res.groups">
        <field name="name">Salesperson</field>
        <field name="category_id" ref="module_category_flexipharmacy"/>
    </record>

    <record model="ir.rule" id="salesperson_view">
        <field name="name">Salesperson own order</field>
        <field name="model_id" ref="model_pos_order"/>
        <field name="domain_force">[('user_id', '=', 'user.id')]</field>
        <field name="groups" eval="[(4, ref('group_flexipharmacy_salesperson'))]"/>
    </record>

'''

now after doing this i am not getting any record in my pos orders all are hidden

this is the "user_id" which is in the python part:-

user_id = fields.Many2one( comodel_name='res.users', string='Salesperson', help="Person who uses the cash register. It can be a reliever, a student or an interim employee.", default=lambda self: self.env.uid, states={'done': [('readonly', True)], 'invoiced': [('readonly', True)]}, )


Solution

  • <record model="ir.rule" id="salesperson_view">
        <field name="name">Salesperson own order</field>
        <field name="model_id" ref="model_pos_order"/>
        <field name="domain_force">[('user_id', '=', user.id)]</field>
        <field name="groups" eval="[(4, ref('group_flexipharmacy_salesperson'))]"/>
    </record>