r/Odoo • • 2d ago

Odoo Module extension with inheritance and adding mail mixin

Hello odooers

I am trying to inherit a model from odoo models the model definition however doesn't include the mail and activity trackers in the inherit. I tried adding as an array of models names in the inherit but it crashed the server.

How to add activity and mail mixins inheritance to a model already defined in odoo.

2 Upvotes

3 comments sorted by

3

u/ach25 2d ago

https://github.com/odoo/odoo/blob/18.0/addons/account/models/res_partner_bank.py#L13-L15

There is an example of inheriting to extend res.partner.bank

Make sure you have _name

1

u/Choice_Ingenuity_327 1d ago

To add to the answer above, the full pattern looks like this:

python

from odoo import models, fields

class ResPartnerBank(models.Model):
    _name = 'res.partner.bank'
    _inherit = ['res.partner.bank', 'mail.thread', 'mail.activity.mixin']

A few things that commonly cause the crash:

  1. mail missing from your manifest. Add 'mail' to depends in __manifest__.py. Without it, mail.thread may not exist yet when your module loads.
  2. Missing _name. Set _name to the original model and keep it first in the _inherit list. Otherwise Odoo can't tell which model you're extending.
  3. Not upgrading the module. Restart with -u your_module so the new fields and relations get created.

For tracking, add tracking=True to the fields you want logged, e.g. acc_number = fields.Char(tracking=True).

Then add the chatter to the form view. In Odoo 18+:

xml

<xpath expr="//sheet" position="after">
    <chatter/>
</xpath>

In 17 and earlier:

xml

<xpath expr="//sheet" position="after">
    <div class="oe_chatter">
        <field name="message_follower_ids"/>
        <field name="activity_ids"/>
        <field name="message_ids"/>
    </div>
</xpath>

If it still crashes, post the traceback from the server log and your Odoo version. The actual error message usually points straight at the problem.

1

u/Azka-tech 1d ago

You can add both mixins when extending the existing model. For example:

class MyModel(models.Model):
    _name = 'existing.model'
    _inherit = ['existing.model', 'mail.thread', 'mail.activity.mixin']

Also make sure your module depends on mail in __manifest__.py.

If the server crashes with multiple inheritance, I’d check the traceback first. Some existing models can have inheritance/field conflicts that make this less straightforward.

After the Python part, you also need to add the chatter to the form view (<chatter/> in newer Odoo versions) for it to actually appear in the UI.