Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
2 Відповіді
1538 Переглядів

Hello everyone 
i have problem i want to call python method i have implement in hr.employee model and i want it to be called when clicking on div tag for design purpose 
how can i achieve that 

hello
odoo.define('finger_print_modules.action_hello', function (require) {
"use strict";
var core = require('web.core');
var rpc = require('web.rpc');

function say_hello() {

rpc.query({
model: 'hr.employee',
method: 'action_hello',
args: [],
}).then(function(result) {
// Handle the result if needed
});
}

core.action_registry.add('action_hello', say_hello);

return {
say_hello: say_hello,
};
});
class Employee(models.Model):
_inherit = 'hr.employee'

@api.model
def action_hello(self):
print('hello in fingerprint')

this is what i have found after long search if anyone have any method that can help
Thank you 

Аватар
Відмінити
Автор Найкраща відповідь

ii found another method to implement it it was like this 

odoo.define('your_module.custom_action', function (require) { 
'use strict';
  var rpc = require('web.rpc');
  var core = require('web.core');
  $(document).on('click', '.custom-div', function () { 
    // var employeeId = $(this).data('employee-id');
// Assuming you have employee ID stored in data-employee-id attribute
      rpc.query({
          model: 'hr.employee',
          method: 'custom_action',
          args: [[]],
      })
  });
});


Аватар
Відмінити
Найкраща відповідь

Hi,

To call a Python method in the hr.employee model when clicking on a div tag, you can, by using an event listener, follow the below code:

odoo.define('finger_print_modules.action_hello', function (require) {

    "use strict";

    

    var rpc = require('web.rpc');

    var publicWidget = require('web.public.widget');

    

    publicWidget.registry.HelloWidget = publicWidget.Widget.extend({

        selector: '.your-div-class',

        events: {

            'click': '_onClick',

        },

        

        _onClick: function (event) {

            event.preventDefault();

            rpc.query({

                model: 'hr.employee',

                method: 'action_hello',

                args: [],

            }).then(function (result) {

                console.log(result);

            });

        },

    });

});


Hope it helps

Аватар
Відмінити
Автор

i ve did exactly what you told me and i got this
UncaughtClientError > OwlError
Uncaught Javascript Error > Invalid handler (expected a function, received: 'undefined')

Related Posts Відповіді Переглядів Дія
2
трав. 24
2243
0
трав. 25
605
1
черв. 24
4231
2
трав. 24
2398
2
трав. 24
4099