Enable Dark Mode!
how-to-add-customer-rating-mixin-in-odoo-17.jpg
By: Anagha S

How to Add Customer Rating Mixin in Odoo 17

Technical

Every organization needs good customer service to succeed in today's compactive business world. One practical way to improve customer satisfaction is to include customer feedback and ratings in your business processes. Odoo provides an easy way to incorporate consumer feedback.

In this blog post, we will explore how to add a customer rating mixin in Odoo 17, enabling companies to get valuable input and enhance their goods and services.

To implement the customer rating mixin, you can inherit the rating. mixin model to your model as follows.

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')

You are now able to use the mixin features in your model.

If the field experts, after inheriting the rating.mixin model, the 'partner_id' field on your model is related to the 'rating. rating' records. The rating_get_partner_id () function will precede the default behavior if you use a different field name instead of 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 using e-mail :

If you want to send emails to request a rating from your customers, you can generate an email with links to rating objects. An example of a basic rating email template may be found below.

Your customer will receive an email with a link in it that takes them to a website with a rating and feedback form. After that, the customer may quick rate and provide feedback to let the firm or other users know how they felt about the products or services.

<?xml version="1.0"?>
<odoo>
<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="module_name.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>
</odoo>

Upon clicking the button with the model as demonstrated below, an email is sent. The method 'action_send_rating_mail' is used to initial the process:.

def action_send_rating_mail(self):
        template = self.env.ref('cust_rating.rating_my_model_email_template')
        template.send_mail(self.id, force_send=True)

The output generated from the email template is show in the image below:

How to Add Customer Rating Mixin in Odoo 17-cybrosys

The following page appear when you click on the rating link in the email, which takes you to the website:

How to Add Customer Rating Mixin in Odoo 17-cybrosys

To display all of the ratings for the model, define an action as follows: Here, I'm giving the menu item an action: -

<?xml version="1.0"?>
<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,form,pivot,graph</field>
        <field name="domain">
                [('res_model', '=', 'your.model')]</field>
  </record>

<menuitem id="menu_cust_rating" name="Customer rating" 
              parent="menu_test" sequence="20" 
              action="rating_rating_action_my_model"/>
</odoo>

How to Add Customer Rating Mixin in Odoo 17-cybrosys

This will provide you with a basic understanding of how to include customer feedback in your custom app. You can refer to the Project module as an example.

To read more about How to Add Customer Rating Mixin in Odoo 16, refer to our blog How to Add Customer Rating Mixin in Odoo 16.


If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment

 


whatsapp_icon
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message