How to change the XML code so that if the signed in user is the assignee user in a certain activity then the "mark done" button should appear to the mentioned user, if the signed in user NOT the assignee user the "mark done" button disappear.
the Activity.xml file that I think should change
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project
- MRP
This question has been flagged
Hi,
you can try to add this to your button:
attrs="{'invisible': [('user_id', '!=', uid)]}"
Hope it helps!
Hello aws hokan, Jason Vu provided sample code for such operation as you didn't provide you code snippet earlier.
Try this
attrs="{'invisible': [('activity_assignee_id', '!=', uid)]}"
upgrade module and clear browser cache as sometimes the cache prevents from changes made in xml/js file.
Hello Aws Hokan,
We can achieve this by defining a new Boolean field and we have to compute it's value based on our condition. Now, We'll use this field in the attrs of the "mark done" button.
Please find code in comment.
Kindly let us know if you face any issue.
Hope it will be helpful to you.
Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari
Please find code here :-
You can use below code.
# python code:
from odoo import api, fields, models
class MailActivity(models.Model):
_inherit = "mail.activity"
display_mark_done = fields.Boolean(compute="_compute_display_mark_done")
@api.depends("user_id")
def _compute_display_mark_done(self):
for rec in self:
rec.display_mark_done = self.env.user.id == rec.user_id.id
<!--xml code:-->
<!--We'll user 'display_mark_done' field in the attrs of 'mark as done' button like below.-->
<!--please make sure that the priority is set to 100 so that other views can't override our view.-->
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="mail_activity_view_form_popup_inherited" model="ir.ui.view">
<field name="name">mail.activity</field>
<field name="model">mail.activity</field>
<field name="priority" eval="100"/>
<field name="inherit_id" ref="mail.mail_activity_view_form_popup"/>
<field name="arch" type="xml">
<xpath expr="//button[@name='action_done']" position="attributes">
<!--other domains are coming from base view and we don't want to override it-->
<attribute name="attrs">
{'invisible': ['|', '|',
('display_mark_done', '=', False),
('activity_category', 'in', ['meeting', 'tax_report']),
('chaining_type', '=', 'trigger')]}
</attribute>
</xpath>
</field>
</record>
</odoo>
Hi
You will need to add a condition to the visibility of the button based on the current user's role as the assignee. Use the attrs attribute to define the condition.
Thank You
Hi
Please try the code given below,
<button name="action_mark_done" string="Mark Done" type="object"
attrs="{'invisible': [('user_id', '!=', uid)]}"/>
Hope it helps
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up
Thanks Jason for response but i tried as you suggest but not working. the code appear as the following :
<button class="o_Activity_toolButton o_Activity_markDoneButton btn btn-link btn-primary pt-0 ps-0"
t-att-title="activityView.markDoneText" t-ref="markDoneButton" t-on-click="activityView.onClickMarkDoneButton" attrs="{'invisible': [('user_id', '!=', uid)]}"
>
<i class="fa fa-check"/> Mark Done
</button>
Thank you all for replay. I tried the mentioned solution but still face the same result.
I think that the condition is true but the parameters are false ( the assignee Id and the singed in user id)