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

Can anyone help me? I'm doing a query using RPC, but I can't extract the data, follow the code:

nfce_return_invoice: function(name){
return rpc.query({
model: 'pos.order',
method: 'search_invoice',
args: [{'name': name}]
},{timeout: 30000}).then(function (invoice) {
return invoice;
});
},
nfce_variaveis: function (obj) {
var self = this;
const invoice = self.pos.nfce_return_invoice(obj.order.name);
console.log(invoice);
},

what's coming out of console.log is this:
{state: ƒ, always: ƒ, then: ƒ, promise: ƒ, pipe: ƒ,…}

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

I am not expert in JS but I think following code would work:

self.pos.nfce_return_invoice(obj.order.name).then(function (invoice) {
console.log(invoice);
});


อวตาร
ละทิ้ง
ผู้เขียน

Inside "THEN" everything works perfectly, the problem is that I need to return the data to another function without promise got it?

คำตอบที่ดีที่สุด

This is the correct format for using rpc.


var rpc = require('web.rpc')

rpc.query(

     model: //your model,

     method: //your method,

      args: [{

          'arg1': value1,

      }]

 }).then(function (result) { 

            // your code 

  });


on model.py

@api.model
def your_method(self):
     ...

With your example, Try to change this function

nfce_return_invoice: function(name){
rpc.query({
model: 'pos.order',
method: 'search_invoice',
args: [{'name': name}]
},{timeout: 30000}).then(function (invoice) {
return invoice;
});
},


Reference: https://www.odoo.com/forum/help-1/question/how-do-i-properly-pass-args-using-rpc-in-odoo-11-141324#answer-141345


อวตาร
ละทิ้ง
ผู้เขียน

The data is coming in then, but they do not return without being a promise, I need them to use in the coupon printing on the pdv

Okay, instead of returning them, call the related function with data as argument. 

On Tue, 15 Oct 2019, 3:52 pm Michael Douglas, <contatomichael@outlook.com.br> wrote:

The data is coming in then, but they do not return without being a promise, I need them to use in the coupon printing on the pdv

Enviado por Odoo S.A. using Odoo.

ผู้เขียน

I didn't quite understand what I meant, take a look to see where I'm going wrong https://pastebin.com/Ubh3CacN

คำตอบที่ดีที่สุด

check with your method 'search_invoice' and check if it gets the correct data.and also 

check 'invoice' you get in js
you can find the error

อวตาร
ละทิ้ง
ผู้เขียน

There is no error, the problem is that it returns a promise and not the data

did you get the data as a response from Search_invoice function?

ผู้เขียน

Yes, the data has been returned, but I can't get the information out of the "promise" and return the data to the function I need, see my code: https://pastebin.com/Ubh3CacN

คำตอบที่ดีที่สุด

Did you find a solution?

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
พ.ค. 23
8056
2
ม.ค. 23
5424
when generating payslip i got this error แก้ไขแล้ว
1
ก.พ. 21
3682
0
ก.พ. 21
3566
0
มิ.ย. 20
2591