[IMP] crm_iap_enrich: send a toast notification for IAP credit shortage

Before this commit, it was posting a message in chatter if user did not have
credit enough to enrich a lead. This is mainly noise and not really user
friendly.

After this commit, it will show the toast notification for user message

Task-2269743

Part-of: odoo/odoo#60605
This commit is contained in:
Nikunj Ladava
2021-09-28 16:27:16 +00:00
committed by Thibault Delavallée
parent 025c022c03
commit 25125eb243
2 changed files with 11 additions and 7 deletions
@@ -16,9 +16,9 @@
</template>
<template id="mail_message_lead_enrich_no_credit">
<p>Lead enriched (based on email address)</p>
<div style="background-color:#ffffff;padding:15px;">
<span>Your balance for Lead Enrichment is insufficient. Please go to your <a t-attf-href="{{url}}" target="_blank">IAP account</a> to buy credits.</span>
<div>
<span>Not Enough Credits for Lead Enrichment.</span><br/>
<a t-attf-href="{{url}}" target="_blank"><i class="fa fa-arrow-right"/> Buy More Credits</a>
</div>
</template>
</data></odoo>
+8 -4
View File
@@ -92,10 +92,14 @@ class Lead(models.Model):
data = {
'url': self.env['iap.account'].get_credits_url('reveal'),
}
leads[0].message_post_with_view(
'crm_iap_enrich.mail_message_lead_enrich_no_credit',
values=data,
subtype_id=self.env.ref('mail.mt_note').id)
self.env['bus.bus'].sendone(
(self._cr.dbname, 'res.partner', self.env.user.partner_id.id),
{
'type': 'simple_notification',
'message': self.env.ref('crm_iap_enrich.mail_message_lead_enrich_no_credit')._render(data),
'message_is_html': True,
}
)
# Since there are no credits left, there is no point to process the other batches
break
except Exception as e: