Help

1

Problem in Record rule and access control

Avatar
simmi gupta

Hello,
I am using odoo 13 and i am facing problem in writing access control and record rule. Actually i want to change the task assignment to only the users who are followers of the project and that should be for project user, Please help. the access control is Project/User.

头像
丢弃
2 答案
0
Avatar
Setu Consulting
Best Answer

Hello simmi gupta, 

I think you would like to get the only followers list in Assigned to field in project task. 

For this you don't need to write a record rule but you will need to add a domain in the Assigned to field in project.task model.

You will need to inherit task form view and add domain in the field. Put this view in your custom module and upgrade your module. 


<record id="view_task_form2" model="ir.ui.view">

            <field name="name">project.task.form</field>

            <field name="model">project.task</field>

            <field eval="2" name="priority"/>

            <field name="inherit_id" ref="project.view_task_form2"/>

            <field name="arch" type="xml">

<field name="user_id" position="replace">

<field name="user_id" class="o_task_user_field" domain="[('partner_id','in',message_partner_ids)]"  options="{&quot;no_open&quot;: True}"/>

</field>

            </field>

</record>


<record model="ir.ui.view" id="view_task_kanban_inherit">

    <field name="name">project.task.kanban.inherit</field>

    <field name="model">project.task</field>

    <field name="inherit_id" ref="project.view_task_kanban"/>

    <field name="arch" type="xml">

        <xpath expr="//templates" position="before">

            <field name="message_partner_ids" />

        </xpath>

    </field>

</record>

11 注释
头像
丢弃
Avatar
simmi gupta
-

Would you please elaborate it. How should i do it.

Avatar
Setu Consulting
-

I have update answer with example, try it.

Avatar
simmi gupta
-

Thanks, that solution worked for me.

Avatar
simmi gupta
-

Hello the above solution worked in form view. But in system is not able to find message_partner_id in kanban view when assigning user. Any idea?

Avatar
Setu Consulting
-

You will need to inherit the kannan view and add the message_partner_ids in the kannan before template tag.

In the kannan, field must be present if you want to access it. In form view you can access because it's present in the view.

In general, field must be present if you would like to access, doesn't matter if it's invisible or visible.

Avatar
simmi gupta
-

Here is my code to inherit kanban view. Am i doing any mistake.

<record model="ir.ui.view" id="view_task_kanban_inherit">

<field name="name">project.task.kanban.inherit</field>

<field name="model">project.task</field>

<field name="inherit_id" ref="project.view_task_kanban"/>

<field name="arch" type="xml">

<xpath expr="//kanban" position="inside">

<field name="message_partner_ids" invisible="1"/>

</xpath>

</field>

</record>

<record id="quick_create_task_form_inherit" model="ir.ui.view">

<field name="name">project.task.form.quick_create.inherit</field>

<field name="model">project.task</field>

<field name="priority">1000</field>

<field name="inherit_id" ref="project.quick_create_task_form"/>

<field name="arch" type="xml">

<xpath expr="//field[@name='user_id']" position="replace">

<field name="user_id" options="{'no_open': True,'no_create': True}"

domain="[('partner_id', 'in', message_partner_ids)]"/>

</xpath>

</field>

</record>

Avatar
Setu Consulting
-

Change xpath code to this

<xpath expr="//template" position="before">

Avatar
simmi gupta
-

Giving the error below:

ParseError: "Element '<xpath expr="//template">' cannot be located in parent view

Avatar
Setu Consulting
-

I apologize, small typo. use //templates not template.

<xpath expr="//templates" position="before">

Avatar
simmi gupta
-

Still getting error

ParseError: "Error while validating view

Field 'message_partner_ids' used in attributes must be present in view but is missing:

- 'message_partner_ids' in domain="[('partner_id', 'in', message_partner_ids)]"

Avatar
Setu Consulting
-

I hope you have upgraded the module.