Pablo Pantaleon
Pablo Pantaleon

Reputation: 1536

Odoo 10 - Javascript Query to a Model

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.

Upvotes: 1

Views: 2150

Answers (1)

Chavada Viki
Chavada Viki

Reputation: 1524

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.

Upvotes: 1

Related Questions