I've made a module to run code when Save (write) action is made when editing products (product.template). The purpose is to request an external URL to update this product in my website (a script that updates website using API).
The odoo function is:
class ProductTemplateExtra(models.Model):
_inherit = "product.template"
def write(self,vals):
self.ensure_one()
resultat = super().write(vals)
urlupdate = 'https://...sript.php?i=%s' % (self.id)
try:
f = urlopen(urlupdate)
except:
print("An exception occurred")
return resultat
The stript is running fine, but the urlopen is executed BEFORE super().write(vars), and in the script.php I'm getting the OLD values, not the updated values from product.template (just after this, the record is saved and the api gets the updated values, but not when the action is executed).
Using Odoo 15CE
What I'm doing wrong?