Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2 Ответы
22182 Представления

Hi

How do I get a value of field and put it in variable, so I can use it ?


Thanks for advance !

Аватар
Отменить
Лучший ответ

use this to get a fields value from js

var Users = new openerp.Model('res.users');
Users.query(['name', 'login', 'user_email', 'signature']) .filter([['active', '=', true], ['company_id', '=', main_company]]) .limit(15) .all().then(function (users) { // do work with users records, you can access only fields said in query
     for(i in users){
         console.log(i.name)
     }
 });

please refer this link

However a call to py function or model is done only after all js functions are executed.
if you need to use this variable, you should call the js function inside .then(function (users){ and pass your values

for example

var self = this
var Users = new openerp.Model('res.users');
Users.query(['name', 'login', 'user_email', 'signature']) .filter([['active', '=', true], ['company_id', '=', main_company]]) .limit(15) .all().then(function (users) { // do work with users records, you can access only fields said in query
     for(i in users){
         console.log(i.name)
         self.your_function(sample_var)
     }
 });


Аватар
Отменить

how to do this in odoo 12

Автор Лучший ответ

Thank you Mohammed

I wrote this code. First the "ResCompany" variable took the name in "res.company" but when I refresh or change the name of my company, the variable "ResCompany" take the default value which is 'Ghandi'.

Is there any explanation ?

var CompanyName = 'Ghandi';
var
Model = require('web.Model');
var
ResCompany = new Model('res.company');
ResCompany
.query(['name'])
   .filter([['id', '=', 1]])
   .first()
   .then(function (company){
        CompanyName = company.name;
    });

Аватар
Отменить
Related Posts Ответы Просмотры Активность
1
авг. 17
10014
1
сент. 15
4057
2
мар. 15
4455
0
дек. 24
1696
1
июн. 23
3782