1

I need to perform a notification on a non tryton database after the creation of the record.

I see that it's possible to overwrite the create function.. but there is any better solutions to be sure to be after the commit of the database ?

I do in this way

@classmethod
def create(cls, values):
    newObject = super(Inventory, cls).create(values)
    newObject.notifieToMainServer()

regards

1 Answers1

1

Yes, you can call a function when the Transcation is commited by using the atexit function of the tryton Transaction.

So your code will be something like:

from trytond.transaction import Transaction

@classmethod
def create(cls, values):
   records = super().create(values)
   Transaction.atexit(notifyToMainServer)
   return records

If you need to prevent the commit of the transaction when the notification can not be sent, you can use the Two-Phase commit protocol by joining some datamangers on the Transaction. Tryton by default implements an sendmail_transactional function which may be used as reference for implementing a DataManager to send your custom notifications.

Hope it helps!

pokoli
  • 1,045
  • 7
  • 15