# Create a custom button for new record

**URL:** https://discuss.tryton.org/t/create-a-custom-button-for-new-record/1576
**Category:** User
**Created:** [July 16, 2019, 6:31pm UTC](https://discuss.tryton.org/t/create-a-custom-button-for-new-record/1576 "2019-07-16T18:31:56Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![iehoshia](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/iehoshia/32/243_2.png) [@iehoshia](https://discuss.tryton.org/u/iehoshia)
#### Post date: [July 16, 2019, 6:31pm UTC](https://discuss.tryton.org/t/create-a-custom-button-for-new-record/1576/1 "2019-07-16T18:31:56Z")

</div>

Hi,

I will thank how to create a new record from a custom button. I read about how tryton use it on Ctrl + N but I want a custom button or after a specific action. For example, after post an invoice create a new record.

Thanks in advance!

[https://github.com/tryton/tryton/blob/946c0b079ede79cb71cd81d31a0eb193fceab9f7/tryton/gui/main.py#L198](https://github.com/tryton/tryton/blob/946c0b079ede79cb71cd81d31a0eb193fceab9f7/tryton/gui/main.py#L198)

---

<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: [July 16, 2019, 10:22pm UTC](https://discuss.tryton.org/t/create-a-custom-button-for-new-record/1576/2 "2019-07-16T22:22:31Z")

</div>

If you have a custom workflow, you have to write a wizard for it.

---

<div class="post-metadata">

### Author: ![iehoshia](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/iehoshia/32/243_2.png) [@iehoshia](https://discuss.tryton.org/u/iehoshia)
#### Post date: [July 17, 2019, 1:52am UTC](https://discuss.tryton.org/t/create-a-custom-button-for-new-record/1576/3 "2019-07-17T01:52:07Z")

</div>

I’m not sure where to start the development, maybe some decorator like this to create a new record, but I don’t know, maybe some docs to read about these case.

> <https://github.com/tryton/account_invoice/blob/develop/invoice.py#L1386>

---

<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: [July 17, 2019, 7:26am UTC](https://discuss.tryton.org/t/create-a-custom-button-for-new-record/1576/4 "2019-07-17T07:26:39Z")

</div>

You can use the button\_action decorator to launch a wizard but indeed if you do not need any input from the user, you can just put your code in the button method.

---

<div class="post-metadata">

### Author: ![iehoshia](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/iehoshia/32/243_2.png) [@iehoshia](https://discuss.tryton.org/u/iehoshia)
#### Post date: [July 17, 2019, 12:50pm UTC](https://discuss.tryton.org/t/create-a-custom-button-for-new-record/1576/5 "2019-07-17T12:50:02Z")

</div>

I searched a lot but I could not find an example for create a new record from a button, which code I need to add to create a new record in a custom module? I’m not sure, maybe something like this:

> <https://github.com/tryton/account_statement/blob/develop/statement.py#L1157>

---

<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: [July 17, 2019, 1:11pm UTC](https://discuss.tryton.org/t/create-a-custom-button-for-new-record/1576/6 "2019-07-17T13:11:29Z")

</div>

It is not clear what you want to do.  
I think instead of asking for how to do what you think is the solution, you should describe your real need.

---

<div class="post-metadata">

### Author: ![iehoshia](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/iehoshia/32/243_2.png) [@iehoshia](https://discuss.tryton.org/u/iehoshia)
#### Post date: [July 17, 2019, 1:21pm UTC](https://discuss.tryton.org/t/create-a-custom-button-for-new-record/1576/7 "2019-07-17T13:21:07Z")

</div>

I need to create a new record from a custom button when it is pressed. The button is in form view of Invoice records.

---

<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: [July 17, 2019, 1:34pm UTC](https://discuss.tryton.org/t/create-a-custom-button-for-new-record/1576/8 "2019-07-17T13:34:50Z")

</div>

A new record of which model? A new invoice or another model?

---

<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: [July 17, 2019, 1:58pm UTC](https://discuss.tryton.org/t/create-a-custom-button-for-new-record/1576/9 "2019-07-17T13:58:17Z")

</div>

What is the new record? What is the purpose and the usage? With which data is it created? Is the user’s input required? What should happen to the record once created? What should see the user? etc.

---

<div class="post-metadata">

### Author: ![iehoshia](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/iehoshia/32/243_2.png) [@iehoshia](https://discuss.tryton.org/u/iehoshia)
#### Post date: [July 17, 2019, 5:27pm UTC](https://discuss.tryton.org/t/create-a-custom-button-for-new-record/1576/10 "2019-07-17T17:27:30Z")

</div>

The button is in the invoice view form, I need to create a new empty record in the same view (similar to press Ctrl + N). The purpose of the usage is that the user that invoice doesn’t want to press Ctrl + N every time he post an invoice, instead after press post button, after post the invoice automatically create a new invoice record. When the new record is created the user is ready to edit it and fill the form. Maybe the user need to see a warning windows that ask him if he want to create a new record.

---

<div class="post-metadata">

### Author: ![iehoshia](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/iehoshia/32/243_2.png) [@iehoshia](https://discuss.tryton.org/u/iehoshia)
#### Post date: [July 17, 2019, 5:27pm UTC](https://discuss.tryton.org/t/create-a-custom-button-for-new-record/1576/11 "2019-07-17T17:27:48Z")

</div>

> [@pokoli](#):
>
> model

In the same invoice model.

---

<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: [July 17, 2019, 7:07pm UTC](https://discuss.tryton.org/t/create-a-custom-button-for-new-record/1576/12 "2019-07-17T19:07:39Z")

</div>

The method of the [button may return the string ‘new’](http://docs.tryton.org/projects/server/en/latest/topics/views/index.html?highlight=button#button).

---

<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: [August 16, 2019, 7:07pm UTC](https://discuss.tryton.org/t/create-a-custom-button-for-new-record/1576/13 "2019-08-16T19:07:42Z")

</div>

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