Customer ratings are comments (problems, details, etc.) made by users or customers on their interactions with your business, goods, or services. The business will eventually be able to use this feedback to improve its offerings. You can utilize customer reviews in Odoo by utilizing the rating mixin. You can email your customers to ask for their ratings and receive feedback using the customer rating mixin in Odoo.
Adding ratings to your model
You can simply inherit the rating. mixin model for adding ratings on your module.
class TestModels(models.Model):
_name = 'your.model'
_description = 'Your Model'
_inherit = ['rating.mixin', 'mail.thread']
user_id = fields.Many2one('res.users', string='Responsible')
partner_id = fields.Many2one('res.partner', string='Customer'
The features of the rating mixin are now accessible in your model.
The rating. rating records are linked to the partner_id field on your model if the field exists after inheriting the rating. mixin model. The default behavior will be altered by the _rating_get_partner() method if you substitute another field name for partner_id (for the res. partner model).
The rating event will be shown in the chatter history if your model inherits the mail. thread model.
Send rating requests to the customers using e-mail
You can create an email containing links to rating objects if you want to send emails to your customers asking for ratings. A basic template for a rating email is provided below.
<record id="rating_my_model_email_template" model="mail.template">
<field name="name">Test Model: Rating Request</field>
<field name="subject">Customer Rating Request</field>
<field name="model_id" ref="image_module.model_your_model"/>
<field name="email_from">{{ (object._rating_get_operator().email_formatted if object._rating_get_operator() else user.email_formatted) }}</field>
<field name="partner_to" >{{ object._rating_get_partner().id }}</field>
<field name="body_html" type="html">
<div>
<t t-set="access_token" t-value="object._rating_get_access_token()"/>
<t t-set="partner" t-value="object._rating_get_partner()"/>
<table border="0" cellpadding="0" cellspacing="0" width="590" style="width:100%; margin:0px auto;">
<tbody>
<tr><td valign="top" style="font-size: 13px;">
<t t-if="partner.name">
Hello <t t-out="partner.name or ''">Brandon Freeman</t>,<br/><br/>
</t>
<t t-else="">
Hello,<br/><br/>
</t>
Please take a moment to rate our services related to the task "
<t t-if="object._rating_get_operator().name">
assigned to <strong t-out="object._rating_get_operator().name or ''">Mitchell Admin</strong>.<br/>
</t>
<t t-else="">
.<br/>
</t>
</td></tr>
<tr><td style="text-align: center;">
<table border="0" cellpadding="0" cellspacing="0" width="590" summary="o_mail_notification" style="width:100%; margin: 32px 0px 32px 0px;">
<tr><td style="font-size: 13px;">
<strong>Tell us how you feel about our service</strong><br/>
<span style="font-size: 12px; opacity: 0.5; color: #454748;">(click on one of these smileys)</span>
</td></tr>
<tr><td style="font-size: 13px;">
<table style="width:100%;text-align:center;margin-top:2rem;">
<tr>
<td>
<a t-attf-href="/rate/{{ access_token }}/5">
<img alt="Satisfied" src="/rating/static/src/img/rating_5.png" title="Satisfied"/>
</a>
</td>
<td>
<a t-attf-href="/rate/{{ access_token }}/3">
<img alt="Okay" src="/rating/static/src/img/rating_3.png" title="Okay"/>
</a>
</td>
<td>
<a t-attf-href="/rate/{{ access_token }}/1">
<img alt="Dissatisfied" src="/rating/static/src/img/rating_1.png" title="Dissatisfied"/>
</a>
</td>
</tr>
</table>
</td></tr>
</table>
</td></tr>
</tbody>
</table>
</div>
</field>
<field name="auto_delete" eval="False"/>
</record>
Your customer will receive an email with a link that takes them to a web page with a rating and feedback form. The customer can then quickly rate and give comments to let the company or other users know how they found the services or items.
In the given example, we are sending an email when clicking the button in the model. The function to send mail is provided here.
def action_send_rating_mail(self):
template = self.env.ref('image_module.rating_my_model_email_template')
template.send_mail(
self.id, force_send=True)
The output of the template is given below:
It redirects to the website and shows a page like below when clicking on the link of rating:
Now, to see all the ratings, define an action as below:-
<record id="rating_rating_action_my_model" model="ir.actions.act_window">
<field name="name">Customer Ratings</field>
<field name="res_model">rating.rating</field>
<field name="view_mode">kanban,pivot,graph</field>
<field name="domain">[('res_model', '=', test_module.model_your_model), ('res_id', '=', active_id), ('consumed', '=', True)]</field>
</record>
The output of the action will be as follows:-