By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
rocoderesrocoderes
  • Home
  • HTML & CSS
    • Login and Registration Form
    • Card Design
    • Loader
  • JavaScript
  • Python
  • Internet
  • Landing Pages
  • Tools
    • Google Drive Direct Download Link Generator
    • Word Count
  • Games
    • House Painter
Notification Show More
Latest News
How to set the dropdown value by clicking on a table row
Javascript – How to set the dropdown value by clicking on a table row
JavaScript
Attempting to increase the counter, when the object's tag exist
Javascript – Attempting to increase the counter, when the object’s tag exist
JavaScript
Cycle2 JS center active slide
Javascript – Cycle2 JS center active slide
JavaScript
Can import all THREE.js post processing modules as ES6 modules except OutputPass
Javascript – Can import all THREE.js post processing modules as ES6 modules except OutputPass
JavaScript
How to return closest match for an array in Google Sheets Appscript
Javascript – How to return closest match for an array in Google Sheets Appscript
JavaScript
Aa
Aa
rocoderesrocoderes
Search
  • Home
  • HTML & CSS
    • Login and Registration Form
    • Card Design
    • Loader
  • JavaScript
  • Python
  • Internet
  • Landing Pages
  • Tools
    • Google Drive Direct Download Link Generator
    • Word Count
  • Games
    • House Painter
Follow US
High Quality Design Resources for Free.
rocoderes > JavaScript > Javascript – How can I overwrite a JS function added to core.action_registry in Odoo 15?
JavaScript

Javascript – How can I overwrite a JS function added to core.action_registry in Odoo 15?

Admin
Last updated: 2024/01/07 at 7:12 AM
Admin
Share
2 Min Read
How can I overwrite a JS function added to core.action_registry in Odoo 15?

Problem:

The hr_attendance module adds to core.action_registry the abstract action hr_attendance_my_attendances, which has a function named update_attendance. I want to overwrite this function. I’ve tried a lot of things, with no result. Here’s a good example by @Kenly (How to override js method in Odoo 15?), but unfortunately I can’t use it because core.action_registry has no function extend.

Contents
Problem:Solution:

This is what I have now (in my module, in a file named my_attendances.js):

odoo.define('my_module.my_attendances', function (require) {
    "use strict";
    
    const session = require('web.session');
    var core = require('web.core');
    var MyAttendances = require('hr_attendance.my_attendances');

    var MyAttendancesExtended = MyAttendances.extend({

        // events: _.extend({
        //     'click .o_hr_attendance_sign_in_out_icon': 'update_attendance',
        // }, AbstractField.prototype.events),

        update_attendance: function () {
            console.log('I HAVE OVERWRITTEN THE FUNCTION');
            var self = this;
            this._rpc({
                model: 'hr.employee',
                method: 'attendance_manual',
                args: [[self.employee.id], 'hr_attendance.hr_attendance_action_my_attendances', None],
                context: session.user_context,
            })
            .then(function(result) {
                if (result.action) {
                    self.do_action(result.action);
                } else if (result.warning) {
                    self.displayNotification({ title: result.warning, type: 'danger' });
                }
            });
        },
    });
    
    core.action_registry.add('my_module.my_attendances', MyAttendancesExtended);
    
    return MyAttendancesExtended;

});

But it seems to do nothing, since I cannot see the I HAVE OVERWRITTEN THE FUNCTION message in the JS console.

And I think I’ve added fine the JS code to my module, since I get errors if I write wrong code. But just in case, I’ve added the JS file to the __manifest__.py with these lines:

'assets': {
    'web.assets_backend': [
        'my_module/static/src/js/my_attendance.js',
    ],
},

Anyone can give me a clue please?

Solution:

You created a new action that is not used.

To override update_attendance function, use include

Example:

/** @odoo-module **/

import MyAttendances from 'hr_attendance.my_attendances';
import session from 'web.session';

MyAttendances.include({

    update_attendance: function () {
        console.log('I HAVE OVERWRITTEN THE FUNCTION');
        var self = this;
        this._rpc({
            model: 'hr.employee',
            method: 'attendance_manual',
            args: [[self.employee.id], 'hr_attendance.hr_attendance_action_my_attendances', null],
            context: session.user_context,
        })
        .then(function(result) {
            if (result.action) {
                self.do_action(result.action);
            } else if (result.warning) {
                self.displayNotification({ title: result.warning, type: 'danger' });
            }
        });
    },
});

Related

Subscribe to Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

Share this Article
Facebook Twitter Email Print
What do you think?
Love0
Sad0
Happy0
Sleepy0
Angry0
Dead0
Wink0
Previous Article Delete all columns inside a Column Group with Google Apps Script Javascript – Delete all columns inside a Column Group with Google Apps Script
Next Article Chart.Js. point style as a linear gradient Javascript – Chart.Js. point style as a linear gradient
Leave a comment Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

- Advertisement -

You Might Also Like

How to set the dropdown value by clicking on a table row

Javascript – How to set the dropdown value by clicking on a table row

February 11, 2024
Attempting to increase the counter, when the object's tag exist

Javascript – Attempting to increase the counter, when the object’s tag exist

February 11, 2024
Cycle2 JS center active slide

Javascript – Cycle2 JS center active slide

February 10, 2024
Can import all THREE.js post processing modules as ES6 modules except OutputPass

Javascript – Can import all THREE.js post processing modules as ES6 modules except OutputPass

February 10, 2024
rocoderesrocoderes
Follow US

Copyright © 2022 All Right Reserved By Rocoderes

  • Home
  • About us
  • Contact us
  • Disclaimer
Join Us!

Subscribe to our newsletter and never miss our latest news, podcasts etc.

Zero spam, Unsubscribe at any time.
Welcome Back!

Sign in to your account

Lost your password?