Skip to Content
Menu
This question has been flagged
1 Reply
19559 Views

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

Avatar
Discard
Best Answer

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

Avatar
Discard
Related Posts Replies Views Activity
2
Jan 23
4130
0
Feb 21
2633
0
Oct 18
2974
1
Aug 23
411
2
Apr 21
3416