Odoo 10 - Javascript Query to a Model

纵然是瞬间 提交于 2020-01-15 09:24:08

问题


I'm doing:

var callback = new $.Deferred();
new Model('pos.order').query(['invoice_id']).filter([['id', '=', '100']])
    .first().then(function (order) {
        if (order) {
            callback.resolve(order);
        } else {
            callback.reject({code:400, message:'Missing Order', data:{}});
        }
});

It works fine, and returns an Order object. But my issue is that i want to access the relation objects (many2many, many2one), but the order object has only the ID's of his relations. For example if i want to access the company or invoice object from the Order that i just fetched i need to do another query and i want to get all in a single query.


回答1:


Use below js code to call method in py to get your required data.

new Model("pos.order")
    .call("method_in_pos_order_model", [100])
    .then(function (result) {
          // Result is having what you want..
     });

Method in Py under pos.order model

@api.model
def method_in_pos_order_model(self,id):
    return self.search([('id','=',id)])

I hope this will work for you.



来源:https://stackoverflow.com/questions/45574893/odoo-10-javascript-query-to-a-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!