Reputation: 10189
I've installed the module project
, which creates the rule with the XML ID task_visibility_rule
. Now I want to make inactive this rule, from my own module. The problem is that the rule was declared inside a <data noupdate="1">
tag, so, any XML record which updates that rule is doing nothing.
So I'm trying to modify the rule and set it as noupdate="0"
, to after that be able to make it inactive:
<!-- Find the corresponding "to be inherited record" with noupdate="1" -->
<function name="write" model="ir.model.data">
<function name="search" model="ir.model.data">
<value eval="[('module', '=', 'project'), ('name', '=', 'task_visibility_rule')]"/>
</function>
<!-- Set noupdate to False -->
<value eval="{'noupdate': False}"/>
</function>
<!-- Finish the job, disabling the existing rule -->
<record model="ir.rule" id="project.task_visibility_rule">
<field name="model_id" ref="project.model_project_task"/>
<field name="active" eval="False"/>
</record>
<!-- Optional, if you want to set noupdate to True again -->
<function name="write" model="ir.model.data">
<function name="search" model="ir.model.data">
<value eval="[('module', '=', 'project'), ('name', '=', 'task_visibility_rule')]"/>
</function>
<!--Set noupdate to True-->
<value eval="{'noupdate': True}"/>
</function>
I've tried above code with no success. I've also tried to remove the rule through XML and re-create it with the attribute active
set to False:
<delete id="project.task_visibility_rule" model="ir.rule"/>
<record model="ir.rule" id="project.task_visibility_rule">
<field name="name">Project/Task: employees: follow required for follower-only projects</field>
<field name="model_id" ref="model_project_task"/>
<field name="domain_force">[
'|',
('project_id.privacy_visibility', '!=', 'followers'),
'|',
('project_id.message_partner_ids', 'in', [user.partner_id.id]),
'|',
('message_partner_ids', 'in', [user.partner_id.id]),
# to subscribe check access to the record, follower is not enough at creation
('user_id', '=', user.id)
]</field>
<field name="groups" eval="[(4,ref('base.group_user'))]"/>
<field name="active" eval="False"/>
</record>
But it seems that the rule isn't even removed as it remains with the same database ID.
Then I've tried to call my own Python function from the XML and do the modifications I want through Python code:
<function name="disable_project_task_visibility_rule" model="project.task"/>
And in project.task
model I have:
@api.model
def disable_project_task_visibility_rule(self):
rule = self.env.ref('project.task_visibility_rule')
return rule.write(
{'active': False, },
)
But no success. I would like to know if someone has a better idea than this or can tell me why none of my solutions posted here are working.
Upvotes: 4
Views: 2775
Reputation: 85
try this code and try the following :
<data noupdate="0">
<record model="ir.rule" id="project.task_visibility_rule">
<field name="name">Project/Task: employees: follow required for follower-only projects</field>
<field name="model_id" ref="model_project_task"/>
<field name="domain_force">[
'|',
('project_id.privacy_visibility', '!=', 'followers'),
'|',
('project_id.message_partner_ids', 'in', [user.partner_id.id]),
'|',
('message_partner_ids', 'in', [user.partner_id.id]),
# to subscribe check access to the record, follower is not enough at creation
('user_id', '=', user.id)
]</field>
<field name="groups" eval="[(4,ref('base.group_user'))]"/>
<field name="active" eval="False"/>
</record>
</data>
when you wanna update your module replace -u
by -i
like this :
./odoo-bin --addons-path=addons,../custom/addons/ -u your_module
./odoo-bin --addons-path=addons,../custom/addons/ -i your_module
it works fine for me, hope it helps.
Upvotes: 1