# Data reloading using on\_write method

**URL:** https://discuss.tryton.org/t/data-reloading-using-on-write-method/1291
**Category:** Developer
**Created:** [April 3, 2019, 5:01pm UTC](https://discuss.tryton.org/t/data-reloading-using-on-write-method/1291 "2019-04-03T17:01:34Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![bell](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@bell](https://discuss.tryton.org/u/bell)
#### Post date: [April 3, 2019, 5:01pm UTC](https://discuss.tryton.org/t/data-reloading-using-on-write-method/1291/1 "2019-04-03T17:01:34Z")

</div>

Hi!  
There is a form action in our application. This action runs a wizard that can change multiple records, not just the current record. To reload the data, we set the attribute _on\_write = “on\_write”_ in the tree tag and defined a method _on\_write_. We also registered the method in _trytond.model.Model_.\ __rpc\__. But at change of records the method _on\_write_ is not called and the client does not reload the data.  
What are we doing wrong?  
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: [April 4, 2019, 10:29am UTC](https://discuss.tryton.org/t/data-reloading-using-on-write-method/1291/2 "2019-04-04T10:29:53Z")

</div>

> [@bell](#):
>
> But at change of records

What change? `on_write` works only with write change.

---

<div class="post-metadata">

### Author: ![bell](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@bell](https://discuss.tryton.org/u/bell)
#### Post date: [April 4, 2019, 11:37am UTC](https://discuss.tryton.org/t/data-reloading-using-on-write-method/1291/3 "2019-04-04T11:37:20Z")

</div>

> [@ced](#):
>
> What change? `on_write` works only with write change.

Sorry, if to mark changed records, then changes become visible in a tree view.  
We save changes using the method `write` (or `save`).  
However, the method `on_write` is still not called.

---

<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: [April 4, 2019, 1:10pm UTC](https://discuss.tryton.org/t/data-reloading-using-on-write-method/1291/4 "2019-04-04T13:10:20Z")

</div>

> [@bell](#):
>
> Sorry, if to mark changed records, then changes become visible in a tree view.

I do not understand what this means?

> [@bell](#):
>
> We save changes using the method `write` (or `save` ).

How are you using a method? Are you using a client? If yes which one? How to do you test?

---

<div class="post-metadata">

### Author: ![bell](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@bell](https://discuss.tryton.org/u/bell)
#### Post date: [April 4, 2019, 1:53pm UTC](https://discuss.tryton.org/t/data-reloading-using-on-write-method/1291/5 "2019-04-04T13:53:46Z")

</div>

> [@ced](#):
>
> I do not understand what this means?

Our wizard can change several records, even if only the current record is marked. In this case, the changes are not visible in the tree view.  
If we pre-mark the changeable records, the changes are displayed in the tree view.

> [@ced](#):
>
> How are you using a method?

We change the required records and execute `Model.save(records)`.

> [@ced](#):
>
> Are you using a client? If yes which one?

Desktop Client 4.6.

> [@ced](#):
>
> How to do you test?

We inserted `logger.info()` into the method `on_write` and this logging does not work.

---

<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: [April 4, 2019, 2:42pm UTC](https://discuss.tryton.org/t/data-reloading-using-on-write-method/1291/6 "2019-04-04T14:42:54Z")

</div>

> [@bell](#):
>
> Our wizard can change several records, even if only the current record is marked. In this case, the changes are not visible in the tree view.

What does the wizard? Is it run as dialog?  
The wizard call a reload with written set when it ends [http://hg.tryton.org/tryton/file/tip/tryton/gui/window/wizard.py#l395](http://hg.tryton.org/tryton/file/tip/tryton/gui/window/wizard.py#l395)

> [@bell](#):
>
> If we pre-mark the changeable records, the changes are displayed in the tree view.

I do not understand what mean “pre-mark”?

---

<div class="post-metadata">

### Author: ![bell](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@bell](https://discuss.tryton.org/u/bell)
#### Post date: [April 4, 2019, 3:08pm UTC](https://discuss.tryton.org/t/data-reloading-using-on-write-method/1291/7 "2019-04-04T15:08:32Z")

</div>

> [@ced](#):
>
> What does the wizard? Is it run as dialog?

Yes, it is run as dialog.

> [@ced](#):
>
> The wizard call a reload with written set when it ends [tryton: 7ab6b091a0b1 tryton/gui/window/wizard.py](http://hg.tryton.org/tryton/file/tip/tryton/gui/window/wizard.py#l395)

I see, but written set must be marked (more precisely, selected).

> [@ced](#):
>
> I do not understand what mean “pre-mark”?

“pre-mark” means “select before calling the wizard”.

But it is not clear why the method `on_write` is not called.

---

<div class="post-metadata">

### Author: ![bell](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@bell](https://discuss.tryton.org/u/bell)
#### Post date: [April 11, 2019, 4:48pm UTC](https://discuss.tryton.org/t/data-reloading-using-on-write-method/1291/8 "2019-04-11T16:48:03Z")

</div>

We solved the problem of data reloading without `on_write` method.  
Here is our solution:

```
class OurWizard(Wizard):
    .....
    start = StateView(
        .....
        [
            Button('Cancel', 'end', 'tryton-cancel'),
            Button('Run', 'run', 'tryton-ok', default=True),
        ]
    )

    run = StateTransition()

    def transition_run(self):
        .....
        return 'end'

    def end(self):
        return 'reload'

```

The ending state of the wizard may return one of the client side action keywords:

> **[Wizard — Tryton server](https://docs.tryton.org/latest/server/ref/wizard.html)**

---

<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: [May 11, 2019, 4:48pm UTC](https://discuss.tryton.org/t/data-reloading-using-on-write-method/1291/9 "2019-05-11T16:48:06Z")

</div>

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