Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
20388 มุมมอง

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
5160
0
ก.พ. 21
3339
0
ต.ค. 18
3693
1
ส.ค. 23
411
2
เม.ย. 21
4271