Reputation: 9670
I want to show a message when I have follower in the document and they are not users of Odoo. So I created two computed fields, one for the message and another one to check if the message should be shown.
class SaleOrder(models.Model):
_inherit = 'sale.order'
@api.multi
@api.depends('message_follower_ids')
def _compute_show_warning_msg(self):
partner_ids = self.env['res.users'].search([])\
.mapped('partner_id').mapped('id')
for record in self:
msg = _("""\nDocument contains no user followers.\n""")
for follower in record.message_follower_ids:
if follower.partner_id.id not in partner_ids:
record.show_warning_msg = True
record.warning_msg = msg
show_warning_msg = fields.Boolean(
compute='_compute_show_warning_msg',
string='Show warning message',
)
warning_msg = fields.Text(
compute='_compute_show_warning_msg',
string='Warning message',
)
But when the form is not in edit mode and I add or remove followers the compute method is not triggered. So I must press the "Edit" button and the "Save" to trigger the method.
I have tried to execute the compute method on the create and unlink methods of the follower table, but the form view is not refreshed
Is there a way to trigger the compute field and refresh the form in order to show the message?
Any workaround or fix?
Upvotes: 1
Views: 714
Reputation: 68
A possible solution, I added this code to the form view:
<field name="message_follower_ids" position="attributes">
<attribute name="class">oe_edit_only</attribute>
</field>
Upvotes: 2
Reputation: 9670
The button to add followers look like this:
<button aria-expanded="false" class="btn btn-sm btn-link dropdown-toggle" data-toggle="dropdown" title="Ningún seguidor">
<i class="fa fa-user"></i>
<span class="o_followers_count">0</span>
<span class="caret"></span>
</button>
So I just added the class oe_edit_only
to the button and problem fixed. The user has to be in edit mode to see the button and to add or remove followers:
<button aria-expanded="false" class="btn btn-sm btn-link dropdown-toggle oe_edit_only" data-toggle="dropdown" title="Ningún seguidor">
<i class="fa fa-user"></i>
<span class="o_followers_count">0</span>
<span class="caret"></span>
</button>
Upvotes: 1