Odoo 10-Javascript查询模型 [英] Odoo 10 - Javascript Query to a Model

查看:114
本文介绍了Odoo 10-Javascript查询模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做

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:{}});
        }
});

它工作正常,并返回一个 Order 对象.但是我的问题是我想访问关系对象(many2many,many2one),但是订单对象只有他关系的ID.例如,如果我想从刚刚获取的订单访问companyinvoice对象,则需要执行另一个查询,并且希望在一个查询中全部获取.

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.

推荐答案

使用下面的js代码在py中调用方法以获取所需的数据.

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..
     });

在订单模式下Py中的方法

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

我希望这对您有用.

这篇关于Odoo 10-Javascript查询模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆