Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
5458 Widoki

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

Awatar
Odrzuć
Autor Najlepsza odpowiedź

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. 


Awatar
Odrzuć
Najlepsza odpowiedź

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.
Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
cze 25
4036
0
maj 20
6401
1
wrz 19
10860
3
gru 23
46086
1
cze 16
11416