コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
20374 ビュー

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')]; 

アバター
破棄
関連投稿 返信 ビュー 活動
2
1月 23
5149
0
2月 21
3336
0
10月 18
3670
1
8月 23
411
2
4月 21
4257