For an organization to be successful in today's competitive business, good customer service is inevitable. The best way to carry out this improvement in customer satisfaction is by incorporating customer feedback and ratings into your processes. Odoo provides an easy and efficient way to incorporate consumer feedback.
The following blog post will introduce the implementation of the Customer Rating Mixin in Odoo 18, wherein valuable inputs can be gathered by companies to improve upon their products and services.
Adding the Customer Rating Mixin in Odoo 18
The rating mixin allows you to send emails requesting customer feedback, automate transitions within Kanban processes, and collect statistics based on your ratings.
To enable customer ratings in your model, simply inherit the rating.mixin model in your custom model. Below is an example of how to implement it:
from odoo import fields, models
class YourModel(models.Model):
_name = 'your.model'
_description = 'Your Model'
_inherit = ['rating.mixin', 'mail.thread']
user_id = fields.Many2one('res.users', string='User')
partner_id = fields.Many2one('res.partner', string='Customer')
By inheriting rating.mixin, your model will now support rating functionality…
The rating.rating record will automatically link to the partner_id field in your model, provided that the field exists. If you wish to use a different field instead of partner_id, you can override this behavior by implementing the rating_get_partner_id() function.
Similarly, the rating.rating record will connect to the partner associated with the user_id field in your model (i.e., the partner being rated). This can be customized by overriding the rating_get_rated_partner_id() function if you are using a field other than user_id. Note that this function must return a res.partner record, as the system will automatically fetch the partner linked to user_id.
Additionally, if your model inherits from mail.thread, the rating event will be recorded in the chatter history.
Sending Rating Requests via Email
To collect customer feedback, you can send an email containing a link for customers to provide their rating. Below is an example of how to create an email template for this purpose:
<odoo>
<record id="rating_my_model_email_template" model="mail.template">
<field name="name">Customer Rating Request</field>
<field name="subject">Please Provide Your Feedback</field>
<field name="model_id" ref="module_name.model_your_model"/>
<field name="email_from">{{ object._rating_get_operator().email_formatted or 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()"/>
<p>Hello <t t-out="partner.name or ''"/>,<br/><br/>
We would appreciate it if you could take a moment to rate our services. Please click one of the icons below to provide your feedback.<br/><br/>
Thank you!</p>
<table>
<tr>
<td><a t-attf-href="/rate/{{ access_token }}/5"><img src="/rating/static/src/img/rating_5.png" alt="Excellent"/></a></td>
<td><a t-attf-href="/rate/{{ access_token }}/3"><img src="/rating/static/src/img/rating_3.png" alt="Average"/></a></td>
<td><a t-attf-href="/rate/{{ access_token }}/1"><img src="/rating/static/src/img/rating_1.png" alt="Poor"/></a></td>
</tr>
</table>
</div>
</field>
<field name="auto_delete" eval="False"/>
</record>
</odoo>
This template generates an email that allows customers to provide feedback interactively. When they click on a rating icon (e.g., excellent, average, or poor), they are directed to a webpage where they can submit their rating.
Sending the Rating Request
To send the rating request to the customer, you can trigger the following method from your model:
def action_send_rating_mail(self):
template = self.env.ref('module_name.rating_my_model_email_template')
template.send_mail(self.id, force_send=True)
Viewing Customer Ratings
To allow users to see all customer ratings related to your model, you can define an action and a button in your custom module's form view. This will display the ratings in various view modes, such as Kanban, Form, Pivot, or Graph:
<odoo>
<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', '=', 'your.model'), ('res_id', '=', active_id), ('consumed', '=', True)]</field>
</record>
<record id="your_model_view_form_inherit_rating" model="ir.ui.view">
<field name="name">your.model.view.form.inherit.rating</field>
<field name="model">your.model</field>
<field name="inherit_id" ref="module_name.your_model_view_form"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='button_box']" position="inside">
<button name="%(rating_rating_action_my_model)d" type="action"
class="oe_stat_button" icon="fa-smile-o">
<field name="rating_count" string="Rating" widget="statinfo"/>
</button>
</xpath>
</field>
</record>
</odoo>
These configurations will create a menu item that allows users to navigate to a section where they can view all customer ratings related to your model. The available default views, such as Kanban, Pivot, and Graph, provide a quick overview of customer feedback.
We can see the results as follows
It redirects to the website and shows a page like below when clicking on the link of rating
Once the ratings are done it shows as follows
This guide outlines how to integrate customer feedback using the customer rating mixin in Odoo 18. By following these steps, businesses can gather important customer insights and take actionable steps to improve their services.
To read more about How to Add Customer Rating Mixin in Odoo 17, refer to our blog How to Add Customer Rating Mixin in Odoo 17.