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.