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

I have following code:
odoo.define('module_name.templates', function(require){
"use strict";

$(document).ready(function() {
    var rpc = require('web.rpc');
   
    $('#query').click(getProductBySKU);
    function getProductBySKU(){
        var domain = [];
        var args = [domain];

        var res = rpc.query({
            model: 'product.template',
            method: 'search',
            args: args
        }).then(function (products) {
            console.log(product); });
        };
    });
});
With that code it gives me Array of numbers, e.x. [1,2]. Length of array is equal to number of entries I have, but no objects at all. If I replace the domain with something like [('id', '=', 2)] I get error "Int object is not subscriptable". So my question: is it possible to get list of objects from database with search method or at least get the fields from specified DB entries.
I also tried with search_read method. Like this:
odoo.define('shift_knob.templates', function(require){
"use strict";

$(document).ready(function() {
    var rpc = require('web.rpc');
   
    $('#query').click(getProductBySKU);
    function getProductBySKU(){
        console.log("Hello world!");
        var domain = [('id', '=', 2)];
        var args = [domain];

        var res = rpc.query({
            model: 'product.template',
            method: 'search_read',
            args: [[], ['name', 'default_code']]
            /* args: args */
        }).then(function (products) {
            console.log(products); });
        };
    });
});

I get the list of objects with name, default code, but I can use only id as identificator and not the fields I want

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

Have you tried  var domain = [('name', 'like', 'something')]; 

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
2
січ. 23
5201
0
лют. 21
3359
0
жовт. 18
3717
1
серп. 23
411
2
квіт. 21
4320