콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
20568 화면

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
5324
0
2월 21
3491
0
10월 18
3876
1
8월 23
411
2
4월 21
4437