Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
5460 Zobrazení

Hello i'm using an onlick function with javascript to get the name of one of my field.

Then I'm trying to pass this value into my python field but without success.


I've tried this solution : https://www.youtube.com/watch?v=Dk4XLN70hpg&ab_channel=Shameem%23Babu but it's not what I want.


Can you explain me how I can set the value I get in js from the dom element, to my python field n2.


Thanks a lot

Avatar
Zrušit
Autor Nejlepší odpověď

Edit: Abdullah thankyou we have almost the same code, it's doing the same thing; but I can't use the self in my python function as you do.


Hello I've made this js function that helps me to get the name of a field i'm clicking on:

odoo.define('app_catalogue_achat.index', function (require) {
"use strict";
var Model = require('web.Model')
var custom_model = new Model('app.history')
$(document).on('click', function() {
var domElement = $(event.target).val();
if (domElement)
// custom_model.call("write", [[55], {'product_id' : 1}])
custom_model.call('my_function', [[domElement]], {})
});
});

Plus this python function :

@api.model
def my_function(self, val, id):
print 'ok \n'
history_product_id = self.env['product.product'].search([('name', 'in', val)])
print history_product_id.id
# self.env['purchase.order'].create_history(history_product_id.id)
# self._get_month()

The python function translate the name i'm getting with js to my product id.

I get the good product id and i want to display it in a tree view (history) that is under my purchase order.

The main problem is that i can't use self in the pyhton function.

Self only working when I'm using an onchange function on the product id of the history tree view.

But when I try to add dynamicly the value that i get with js, I can't use self.

So I coudln't do self.product_id = my val 

or any other solution using self.


Even in the purchase order. 


Avatar
Zrušit
Nejlepší odpověď

Your JS function should look like this

_createTimeOff: function () {
return this._rpc({
model: 'hr.leave',
method: 'create_timeoff_portal',
args: [{
description: $('.new_timeoff_form .name').val(),
}]
}
you must have same name of the function in your py file
@api.model
def create_timeoff_portal(self, values):
    
for timeoff in self:
timeoff_values = {
'name': values['description'],
}
    
    timeoff_rec.sudo().write(timeoff_values)
i HOPE THIS GIVES YOU A LITTLE IDEA ABOUT HOW IT WILL BE DONE.
Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
1
čvn 25
4036
0
kvě 20
6401
1
zář 19
10860
3
pro 23
46086
1
čvn 16
11416