Enable Dark Mode!
how-to-add-customer-rating-mixin-in-odoo-19.jpg
By: Najiya Rafi

How to Add Customer Rating Mixin in Odoo 19

Technical Odoo 19 Odoo Enterprises Odoo Community

Customer feedback is an important aspect of enhancing products, services, and overall customer experience. In Odoo 19, you can create elegant and maintainable solutions for customer feedback rating systems using mixin classes. Rather than duplicating code for rating systems in different models, you can use a mixin to include the rating feature wherever it is required in an efficient and elegant way.

In this blog post, we will demonstrate how to create a Customer Rating Mixin in Odoo 19 and show you how to incorporate it into existing models.

Why Use a Customer Rating Mixin?

In real-world Odoo implementations, customer ratings are often required in multiple places, such as:

  • Sales Orders
  • Helpdesk Tickets
  • Projects or Tasks
  • Services or Subscriptions

Implementing rating logic separately for each model quickly leads to duplicated code and maintenance issues. A mixin solves this problem by providing:

  • Reusable rating fields and logic
  • Consistent behavior across models
  • Cleaner and more maintainable code
  • Upgrade-safe customizations

What Is a Mixin in This Context?

A mixin is an abstract model that adds shared behavior to other models. It does not store records on its own and does not represent a business entity. Instead, it extends existing models with additional capabilities—in this case, customer rating functionality.

In Odoo 19, mixins are defined using models.AbstractModel.

Step 1: Create the Customer Rating Mixin

Let’s start by creating a mixin that adds customer rating fields and helper methods.

from odoo import models, fields

class CustomerRatingMixin(models.AbstractModel):
  _name = 'customer.rating.mixin'
  _description = 'Customer Rating Mixin'
  customer_rating = fields.Selection(
      selection=[
          ('1', 'Very Poor'),
          ('2', 'Poor'),
          ('3', 'Average'),
          ('4', 'Good'),
          ('5', 'Excellent')
      ],
      string='Customer Rating'
  )
  rating_feedback = fields.Text(string='Customer Feedback')
  def set_customer_rating(self, rating, feedback=None):
      self.customer_rating = rating
      if feedback:
          self.rating_feedback = feedback

Step 2: Apply the Mixin to an Existing Model

Now let’s add customer rating functionality to an existing model, such as sale.order.

from odoo import models

class SaleOrder(models.Model):
  _inherit = ['sale.order', 'customer.rating.mixin']

With this inheritance, Sale Orders can now store and manage customer ratings without any additional setup.

Step 3: Using the Rating Feature in Business Logic

Once the mixin is applied, you can use the rating fields and methods in your workflows.

For example, you might automatically request or assign a rating when an order is completed:

def action_confirm(self):
  res = super().action_confirm()
  for order in self:
      order.set_customer_rating('5', 'Excellent service and fast delivery')
  return res

This keeps your implementation simple while ensuring consistency.

Benefits of This Approach

  • High Reusability – One mixin works across multiple models
  • Consistent Data Structure – Unified rating fields everywhere
  • Centralized Logic – Easier updates and maintenance
  • Clean Architecture – No clutter in core business models

Best Practices for Customer Rating Mixins

  • Always use models.AbstractModel for mixins
  • Keep rating logic generic and reusable
  • Avoid hardcoding model-specific workflows
  • Use descriptive and clear field names
  • Document the mixin if it’s shared across modules

Adding customer ratings in Odoo 19 does not have to be complex or repetitive. A Customer Rating Mixin allows you to implement feedback features in a clean, scalable, and upgrade-safe way.

By using this approach, you can:

  • Reduce duplicated code
  • Maintain consistent customer feedback data
  • Build more professional and maintainable Odoo modules

If you’re serious about writing high-quality Odoo customizations, mixins should be a standard part of your development toolbox.

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


Frequently Asked Questions

Can I use this rating mixin on multiple models?

Yes. That’s the main advantage of a mixin. You can inherit it in any number of models such as sale.order, helpdesk.ticket, or project.task.

Does the mixin create a separate database table?

No. Since the mixin is defined using models.AbstractModel, it does not create its own table. The fields are stored in the tables of the models that inherit it.

Can I change the rating scale (for example, 1–10)?

Absolutely. You can modify the Selection field values or even replace it with an integer or float field, depending on your business needs.

Is this approach upgrade-safe?

Yes. Mixins do not modify Odoo core code directly, making them one of the safest customization approaches during upgrades.

Can I calculate an average rating using this mixin?

Yes. You can add computed fields or reporting logic on top of this mixin to calculate average ratings across records.

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
Kakkanchery, 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