# How to refresh the transaction in button call

**URL:** https://discuss.tryton.org/t/how-to-refresh-the-transaction-in-button-call/4542
**Category:** Developer
**Created:** [August 17, 2021, 6:58pm UTC](https://discuss.tryton.org/t/how-to-refresh-the-transaction-in-button-call/4542 "2021-08-17T18:58:51Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![German](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/german/32/143_2.png) [@German](https://discuss.tryton.org/u/German)
#### Post date: [August 17, 2021, 6:58pm UTC](https://discuss.tryton.org/t/how-to-refresh-the-transaction-in-button-call/4542/1 "2021-08-17T18:58:51Z")

</div>

Hello,  
I have a button which call a subprocess inside the method, that subprocess is a python script which update the received record on the database. (using psycopg2)

I tried to re instance after the subprocess.check\_output() like:

updated\_invoice = Pool().get(‘account\_invoice’)

But I see the old record (without the information added by the script), ¿Is there any way yo tell the ORM to refresh or query again the db?

PD: If I click the button again, the record has the new information, I guess it’s because tryton is using a new transaction  
Thanks in advance.

---

<div class="post-metadata">

### Author: ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)
#### Post date: [August 17, 2021, 7:12pm UTC](https://discuss.tryton.org/t/how-to-refresh-the-transaction-in-button-call/4542/2 "2021-08-17T19:12:25Z")

</div>

You should create a new transaction that reads the values commited by the external proccess.

Why are you using an external script? It will be easier to call the same process in the same Tryton transaction

---

<div class="post-metadata">

### Author: ![German](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/german/32/143_2.png) [@German](https://discuss.tryton.org/u/German)
#### Post date: [August 17, 2021, 7:16pm UTC](https://discuss.tryton.org/t/how-to-refresh-the-transaction-in-button-call/4542/3 "2021-08-17T19:16:53Z")

</div>

Sorry, How could I create the new transaction?

I’m using Invoice.search() after the subprocess call but not sure if this triggers a new transaction.

Unfortunaly the external script was there long ago with java code, so I’m planning in future integrate it to tryton, for now it’s not possible for me.

---

<div class="post-metadata">

### Author: ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)
#### Post date: [August 17, 2021, 7:40pm UTC](https://discuss.tryton.org/t/how-to-refresh-the-transaction-in-button-call/4542/4 "2021-08-17T19:40:57Z")

</div>

You should call [transaction.new](https://docs.tryton.org/projects/server/en/latest/ref/transaction.html#trytond.transaction.Transaction.new_transaction) to strat a new transaction.

From there you wilm be able to perform any databae query which will see the values created on the external process.

---

<div class="post-metadata">

### Author: ![German](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/german/32/143_2.png) [@German](https://discuss.tryton.org/u/German)
#### Post date: [August 17, 2021, 8:33pm UTC](https://discuss.tryton.org/t/how-to-refresh-the-transaction-in-button-call/4542/5 "2021-08-17T20:33:54Z")

</div>

I’m trying with this:

```
@classmethod
@ModelView.button
def do_attached_document(cls, invoices):
              transaction = Transaction()
              transaction.new_transaction()
              Invoice = Pool().get('account.invoice')

```

Which seems to work, but from tryton I get this error, I know I’m very close 😅:

> Traceback (most recent call last):  
> File “/trytond/wsgi.py”, line 80, in dispatch\_request  
> return endpoint(request, \*\*request.view\_args)  
> File “/trytond/protocols/dispatcher.py”, line 46, in rpc  
> request, database\_name, \*request.rpc\_params)  
> File “/trytond/wsgi.py”, line 51, in auth\_required  
> return wrapped(\*args, \*\*kwargs)  
> File “/trytond/protocols/wrappers.py”, line 122, in wrapper  
> return func(request, pool, \*args, \*\*kwargs)  
> File “/trytond/protocols/dispatcher.py”, line 205, in \_dispatch  
> security.reset(pool.database\_name, session, context=context)  
> File “/trytond/security.py”, line 134, in reset  
> with Transaction().start(dbname, 0, context=context):  
> File “/trytond/transaction.py”, line 86, in start  
> assert self.user is None  
> AssertionError

---

<div class="post-metadata">

### Author: ![German](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/german/32/143_2.png) [@German](https://discuss.tryton.org/u/German)
#### Post date: [August 20, 2021, 12:34am UTC](https://discuss.tryton.org/t/how-to-refresh-the-transaction-in-button-call/4542/6 "2021-08-20T00:34:00Z")

</div>

I figure it out with:

> ```
> with Transaction().new_transaction() as transaction:
> with transaction.set_user(1):
> Invoice = Pool().get('account.invoice')
> 
> ```

Thank you

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [August 20, 2021, 6:22am UTC](https://discuss.tryton.org/t/how-to-refresh-the-transaction-in-button-call/4542/7 "2021-08-20T06:22:34Z")

</div>

It is not really the Model that is linked to the transaction but you must be under the new transaction to call methods on it like `search`.

---

<div class="post-metadata">

### Author: ![system](https://discuss-cdn.tryton.org/uploads/default/original/1X/c6f8ec0a40525cdcd50058c734283450a4b3d38b.png) [@system](https://discuss.tryton.org/u/system)
#### Post date: [September 19, 2021, 6:23am UTC](https://discuss.tryton.org/t/how-to-refresh-the-transaction-in-button-call/4542/8 "2021-09-19T06:23:28Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
