问题
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