How to Create Mixins in Odoo 18 (Beginner-Friendly Guide)

Afghanistan Åland Islands Albania Algeria American Samoa Andorra Angola Anguilla Antarctica Antigua and Barbuda Argentina Armenia Aruba Australia Austria Azerbaijan Bahamas Bahrain Bangladesh Barbados Belarus Belgium Belize Benin Bermuda Bhutan Bolivia Bosnia and Herzegovina Botswana Bouvet Island Brazil British Indian Ocean Territory British Virgin Islands Brunei Bulgaria Burkina Faso Burundi Cambodia Cameroon Canada Cape Verde Caribbean Netherlands Cayman Islands Central African Republic Chad Chile China Christmas Island Cocos (Keeling) Islands Colombia Comoros Congo Cook Islands Costa Rica Croatia Cuba Curaçao Cyprus Czechia Denmark Djibouti Dominica Dominican Republic DR Congo Ecuador Egypt El Salvador Equatorial Guinea Eritrea Estonia Eswatini Ethiopia Falkland Islands Faroe Islands Fiji Finland France French Guiana French Polynesia French Southern and Antarctic Lands Gabon Gambia Georgia Germany Ghana Gibraltar Greece Greenland Grenada Guadeloupe Guam Guatemala Guernsey Guinea Guinea-Bissau Guyana Haiti Heard Island and McDonald Islands Honduras Hong Kong Hungary Iceland India Indonesia Iran Iraq Ireland Isle of Man Israel Italy Ivory Coast Jamaica Japan Jersey Jordan Kazakhstan Kenya Kiribati Kosovo Kuwait Kyrgyzstan Laos Latvia Lebanon Lesotho Liberia Libya Liechtenstein Lithuania Luxembourg Macau Madagascar Malawi Malaysia Maldives Mali Malta Marshall Islands Martinique Mauritania Mauritius Mayotte Mexico Micronesia Moldova Monaco Mongolia Montenegro Montserrat Morocco Mozambique Myanmar Namibia Nauru Nepal Netherlands New Caledonia New Zealand Nicaragua Niger Nigeria Niue Norfolk Island Northern Mariana Islands North Korea North Macedonia Norway Oman Pakistan Palau Palestine Panama Papua New Guinea Paraguay Peru Philippines Pitcairn Islands Poland Portugal Puerto Rico Qatar Réunion Romania Russia Rwanda Saint Barthélemy Saint Helena, Ascension and Tristan da Cunha Saint Kitts and Nevis Saint Lucia Saint Martin Saint Pierre and Miquelon Saint Vincent and the Grenadines Samoa San Marino São Tomé and Príncipe Saudi Arabia Senegal Serbia Seychelles Sierra Leone Singapore Sint Maarten Slovakia Slovenia Solomon Islands Somalia South Africa South Georgia South Korea South Sudan Spain Sri Lanka Sudan Suriname Svalbard and Jan Mayen Sweden Switzerland Syria Taiwan Tajikistan Tanzania Thailand Timor-Leste Togo Tokelau Tonga Trinidad and Tobago Tunisia Türkiye Turkmenistan Turks and Caicos Islands Tuvalu Uganda Ukraine United Arab Emirates United Kingdom United States United States Minor Outlying Islands United States Virgin Islands Uruguay Uzbekistan Vanuatu Vatican City Venezuela Vietnam Wallis and Futuna Western Sahara Yemen Zambia Zimbabwe Odoo
Published in Blog on November 25, 2025 5 min read
How to Create Mixins in Odoo 18 Banner Image

Have you ever found yourself repeating the same blocks of code across different Odoo models? Maybe a behavior that needs to be reused in multiple apps? If yes, you’re already facing the exact problem mixins solve. Mixins help you write cleaner, reusable, and maintainable code — especially in Odoo 18, where modular development is more important than ever.

In this guide, you’ll learn exactly how mixins work, why they matter, and how to create your own mixins in Odoo 18 using simple, easy-to-follow steps.

 


What Are Mixins in Odoo?

In Odoo, a mixin is a reusable class that provides specific features or behaviors that you can add to multiple models. You don’t need to rewrite the same function several times — you simply inherit the mixin.

Common examples of built-in mixins:

  • mail.thread – adds chatter functionality

     
  • mail.activity.mixin – allows scheduling activities

     
  • portal.mixin – adds portal-related features

     
  • sequence.mixin – enables automatic sequence generation

Mixins save time, reduce bugs, and help keep your modules consistent.

 


Why Mixins Are Important in Odoo 18

Odoo 18 introduces performance improvements and a streamlined modular structure. Mixins play an even bigger role because:

  • They help you avoid duplicated code
  • They make models easier to maintain
  • They encourage clean architecture
  • They allow you to add a feature once and reuse it anywhere

If you want to write professional-quality Odoo modules, understanding mixins is essential.

 


How to Create Mixins in Odoo 18 (Step-by-Step)

This is the core section — and the primary keyword appears naturally here.

Creating mixins in Odoo 18 is simple once you understand the basic structure. Below is a beginner-friendly walkthrough.

 


Step 1: Define Your Mixin Class

A mixin class is usually placed in a separate Python file inside your module, such as mixins/custom_mixin.py.

Example:

Key points:

  • Use models.AbstractModel for mixins

     
  • _name should be unique

     
  • Do not define database-specific behaviors unless needed

     
  • Add reusable methods or fields

 


Step 2: Inherit the Mixin When Needed

Now, you use your mixin inside any model where you want to reuse the features.

Example:

 

That’s it! Your project.task model now has:

  • A new field extra_note

     
  • Access to set_note_with_timestamp()

     
  • Any other reusable logic you add later

 


Step 3: Use the Mixin Logic

You can now call your mixin’s methods inside other model logic.

This keeps your code clean, organized, and easy to extend.

 


Best Practices When Creating Mixins in Odoo 18

1. Keep Mixins Focused

Each mixin should have a single purpose:

  • Logging
  • Timestamping
  • Notifications
  • Computed value utilities
  • Access rights helpers

This avoids confusion and makes your code predictable.

2. Avoid Heavy Business Logic

Mixins should not contain:

  • Complex workflows
  • Large compute chains
  • Business rules specific to a single model

Keep them generic and reusable.

3. Use Clear, Consistent Names

Good naming patterns:

  • custom.timestamp.mixin

     
  • product.validation.mixin

     
  • email.helper.mixin

Avoid vague names like common.mixin.

4. Always Document Your Mixins

Add docstrings explaining:

  • What the mixin does
  • Which models should use it
  • Any dependencies

 


Example: Creating a Practical Validation Mixin

Here’s a more advanced but easy-to-understand example.

Goal:

Add reusable validation to ensure a name field is never left blank.

Mixin Code:

 

Using the mixin:

 

This gives you a reusable validation rule across multiple models.

 


Conclusion

Mixins are one of the most powerful tools available to Odoo 18 developers. They help you avoid repetitive work, keep your modules clean, and make your code easier to maintain. Once you understand the basics, you can build your own mixins for validation, logging, formatting, or any reusable functionality.

Have you tried creating your first mixin in Odoo 18 yet?

Share your experience or questions in the comments.

 


Frequently Asked Questions (FAQs) 

1. What is a mixin in Odoo?

A mixin is a reusable abstract model that adds specific behavior or features to other models. It helps reduce code duplication and promotes clean module design.

2. How do I create a mixin in Odoo 18?

Create a class that inherits from models.AbstractModel, add reusable fields or methods, then include it in other models using _inherit.

3. Where should I place mixins in my Odoo module?

Most developers create a separate folder such as mixins/ or place them under models/ in a file like custom_mixin.py.

4. Can mixins have fields in Odoo?

Yes. Mixins can have fields, methods, and computed functions — as long as they stay reusable and generic.

5. Are mixins the same as multiple inheritance?

Mixins use Odoo’s multiple inheritance system, but they’re structured specifically for adding reusable behavior across different models.

 

Hi...

Got ideas? We’ve got
the skills. Let’s team up.

Have a question or ready to discuss your project? Our team is here to help you scope, design, and deliver.

Trusted by Leading Businesses
Metro
Zabeel Equstrian
GEMS Logo
APSG Logo
Anisia Logo
Foodlinx Logo
🌐 +1
Select Subject?
send mail graphic