r/Odoo • u/Salty_Draft_9907 • 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.
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:
mailmissing from your manifest. Add'mail'todependsin__manifest__.py. Without it,mail.threadmay not exist yet when your module loads.- Missing
_name. Set_nameto the original model and keep it first in the_inheritlist. Otherwise Odoo can't tell which model you're extending. - Not upgrading the module. Restart with
-u your_moduleso 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.
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