How to override wizard's method on odoo 12

1.1k views Asked by At

I am trying to override a single method on wizard's class that gets executed when the user click submit.

account_consolidation_custom/wizard/CustomClass.py

class AccountConsolidationConsolidate(models.TransientModel):
    _name = 'account.consolidation.consolidate_custom'
    _inherit = 'account.consolidation.base'

    def get_account_balance(self, account, partner=False, newParam=False):
    ....my custom code...

account_consolidation_custom/__manifest_.py

{
    'name': "account_consolidation_custom",

    'summary': """""",

    'description': """
    """,

    'author': "My Company",
    'website': "http://www.yourcompany.com",

    'category': 'Uncategorized',
    'version': '0.1',

    'depends': ['base','account_consolidation'],

    # always loaded
    'data': [],
}

The method's name is exactly the same as the original, but when I click on the submit button, nothing seems to happen, is still calling the method from the base module instead of the custom.

Do you know how to get only one method overwritten instead of the whole wizard class?

2

There are 2 answers

6
CZoellner On BEST ANSWER

You're creating a new wizard/transient model when giving different values to the private attributes _name and _inherit. Instead you should use the original odoo model name account.consolidation.consolidate to both attributes or just remove the _name attribute completely.

Odoo has it's own inheriting mechanism, which is managed by the three class attributes _name, _inherit and _inherits.

0
czuniga On

I was able to make it work using the following code:

class AccountConsolidationConsolidate(models.TransientModel):
    _inherit = 'account.consolidation.consolidate'

   def get_account_balance(self, account, partner=False, newParam=False):
    ....my custom code...

After that I was able to overwrite the base methods.