How to inherit js file tax_group.js (account) in odoo 13

68 Views Asked by At

I need to add another state to a function in account/static/src/js/ tax_group.js line 94

var displayEditWidget = self._isPurchaseDocument() && this.record.data.state === 'draft' && this.getParent().mode === 'edit';

I already added inheritance to web.assets_backend but don't know how to exactly overwrite the function.

I hope somebody can help me.

Thank you very much

Paul

1

There are 1 best solutions below

5
Ahrimann On

For your purpose, Because the js refers to the field of a record:

...this.record.data.state

To add a new state value, you just have to add a new state in the corresponding python field "state" of the account.move model:

  1. in your __manifest__.py file, you should add the account module in the depends section:
depends: ['account'],
  1. in a new file in your custom module>models>my_account_move.py: inherit the model and add a new value to the existing state field:
    class AccountMove(models.Model):
        _inherit = "account.move"

        # in the original model located in addon: account/models/account_move.py: 
        # state = fields.Selection(selection=[('draft', 'Draft'),('posted', 'Posted'), ('cancel', 'Cancelled')], string='Status', required=True, readonly=True, copy=False, tracking=True, default='draft')

        state = fields.Selection(selection_add=[('mynewstate', 'My New   State')])

After this python customization, if you really need to override the js:

In you custom module ("my_custom_module"),

in a new js file, you should call the original js class and using include to "patch" it this way:

    odoo.define('my_custom_module.my_tax_group', function (require) {
        "use strict";
    
        var core = require('web.core');
        var _t = core._t;
    
        var TaxGroupCustomField = require('account.TaxGroupCustomField');
    
    
        TaxGroupCustomField.include({ 

    /**
     * To override an original function 
     * @private
     * @override
     */
    _render: function (){
        var res_original = this._super.apply(this, arguments);
        //var displayEditWidget = self._isPurchaseDocument() && this.record.data.state === 'draft' && this.getParent().mode === 'edit';
        
        
    },

});
});