Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
3 Risposte
7336 Visualizzazioni

Hello,

When I update data with an override "write" function, I do a post request for an external application with the id of changed record (cf: the code bellow). Then the app get the values in postgres but the values hasn't change at this time.


@api.multi    
def write(self, values):
    for record in self:            
        res = super(my_class_xxxx, self).write(values) 
        data = {"id": record.id}
        requests.post("https://us-central1-xxxxxxxx.com", data=data)        
    return res        

 I think the record is update in Odoo but the value of the database change when the write function is returned.

What can I do for call the endpoint when the data has changed in postgres?

Avatar
Abbandona
Risposta migliore

hmm you are right is not committed yet DB. it's committed when request return result 
I think you need to explicitly commit the cursor to stored data forcefully in DB like

​@api.multi
def write(self, values):
    for record in self:
        res = super(my_class_xxxx, self).write(values)
        data = {"id": record.id}
​        record.env.cr.commit()
       requests.post("https://us-central1-xxxxxxxx.com", data=data)
    return res

Avatar
Abbandona
Risposta migliore

Hi Theo: 

You may want to consider using an Automated Action (Settings > Technical > Automation) to invoke the api on the On Creation trigger condition of the model.

Avatar
Abbandona
Autore Risposta migliore

Thank you both for your answers, the method of Ravi Gadhia works perfectly so I haven't tried your's ​Paresh Wagh ​but I think it can works too :)

Avatar
Abbandona

it will not work because odoo commits the cursor/transaction when the response despatched.

Post correlati Risposte Visualizzazioni Attività
18
ago 18
20101
2
mar 25
637
6
dic 23
45193
1
apr 25
966
0
feb 25
698