What’s the best way to customize the TaxableMixin

Hello, after multiple attempts, I can’t find a way to modify the TaxableMixin to adapt it. The only option I have left is modifying the original files. I’d like to know if you can give me any ideas. Thank you very much.

You cannot modify TaxableMixin, you should just inherit the models you want to expand (or all of them). You can create your own Mixin to apply that to several models.

For example:

class MyMixin:
    new_field = fields.Char('New Field')

class Invoice(MyMixin, metaclass=PoolMeta):
    __name__ = 'account.invoice'

class InvoiceLine(MyMixin, metaclass=PoolMeta):
    __name__ = 'acocunt.invoice.line'

To modify TaxableMixin you can just create a Mixin that inherits all models that are a subclass of TaxableMixin. You should use register_mixin for that.

Here is how you should update your __init__.py file:

from . import account
from trytond.modules.account.tax import TaxableMixin

def register():
    Pool.register_mixin(
        account.TaxableMixin, TaxableMixin, 'module_name')

Of course, you should have a TaxableMixin class in your account.py file of your module or adapt the code to work with your classe difinition.

The only drawback of register_mixin is that it is not possible to add fields there as the definition is registered after fields are sincronized in the database. If you need to add fields, you need to do explicity inherit all your models as albert already explained.

1 Like

Thank you very much! In the end, I was able to make it work with your method. I did something like this:
from .. import account_mix

class Invoice(account_mix.Mixin, metaclass=PoolMeta):
‘Invoice’
name = ‘account.invoice’
I managed to make it work by inheriting from a custom TaxableMixin, but Pool.register_mixin didn’t work for me (perhaps I was too tired to debug it). Really appreciate your help!"