# Required clicks per Button

**URL:** https://discuss.tryton.org/t/required-clicks-per-button/222
**Category:** Feature
**Created:** [October 6, 2016, 10:04am UTC](https://discuss.tryton.org/t/required-clicks-per-button/222 "2016-10-06T10:04:35Z")
**Posts on this page:** 20
**Page:** 1

<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: [October 6, 2016, 10:04am UTC](https://discuss.tryton.org/t/required-clicks-per-button/222/1 "2016-10-06T10:04:36Z")

</div>

## Rational

Some buttons are approbations and in some cases we need to have clicks of multiple users. Such multiple clicks can require click from a specific group or click from a number of user. Also they can depend on the record approved (ex: amount of the purchase). And this is configuration specific to the company rules so it must be configurable from the interface.

## Proposal

We could extend the `ir.model.button` to contain a list of rules. Each rule is a constraint that must be passed.  
We extend the `ModelView.button` decorator to record who has clicked on the button and to check all approbation rules. The decorator will filter out all records that does not pass the rules from the super call.  
The rule will be composed of a group, a number (of user) and a condition (PYSON). It will also have a list of buttons that will clear the “click” if clicked.  
The “click” will just record the user.

## Implementation

> **[Add button rule (#5944) · Issues · Tryton / Tryton · GitLab](https://foss.heptapod.net/tryton/tryton/-/issues/5944)**
>
> From https://discuss.tryton.org/t/required-clicks-per-button/222

[https://codereview.tryton.org/26791002](https://codereview.tryton.org/26791002)

## Future

- Add “clicked by me” Function field to use as filter

---

<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: [October 6, 2016, 10:13am UTC](https://discuss.tryton.org/t/required-clicks-per-button/222/2 "2016-10-06T10:13:01Z")

</div>

I’m not sure about the name ‘Approbation’ but I could not find a better one?

---

<div class="post-metadata">

### Author: ![maxx](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/maxx/32/2320_2.png) [@maxx](https://discuss.tryton.org/u/maxx)
#### Post date: [October 6, 2016, 11:03am UTC](https://discuss.tryton.org/t/required-clicks-per-button/222/3 "2016-10-06T11:03:48Z")

</div>

“Approval” ? “Acceptation” ? “Authorization” ? “Allowance” ?

---

<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: [October 6, 2016, 12:09pm UTC](https://discuss.tryton.org/t/required-clicks-per-button/222/4 "2016-10-06T12:09:25Z")

</div>

Indeed I think I will just use the names: Rule and Click

---

<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: [October 6, 2016, 12:52pm UTC](https://discuss.tryton.org/t/required-clicks-per-button/222/5 "2016-10-06T12:52:36Z")

</div>

> [@ced](#):
>
> Indeed I think I will just use the names: Rule and Click

I like this names as then they can be used as “Approval”, “Reject” or whatever option that requires a click of several Users.

---

<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: [October 7, 2016, 3:45pm UTC](https://discuss.tryton.org/t/required-clicks-per-button/222/6 "2016-10-07T15:45:05Z")

</div>

I have a working implementation at

> **[Add button rule (#5944) · Issues · Tryton / Tryton · GitLab](https://foss.heptapod.net/tryton/tryton/-/issues/5944)**
>
> From https://discuss.tryton.org/t/required-clicks-per-button/222

[https://codereview.tryton.org/26791002](https://codereview.tryton.org/26791002)

But I feel it is missing something on the UI because the user click on the button and nothing happens. He doe not have feedback about his action.  
My proposal is to show a counter of clicks on buttons that have rules and a tool-tip which shows the user names who clicked.  
This will require to set automatically new attribute on the XML definition of the button and create an RPC method that compute the values.

---

<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: [October 7, 2016, 5:33pm UTC](https://discuss.tryton.org/t/required-clicks-per-button/222/7 "2016-10-07T17:33:40Z")

</div>

I think there will be a problem for example if the “confirm” button of the sale is configured with a rule and one user click on “confirm”. But before a second one also click, the sale is reset to draft and changed. Once the sale is back to “quotation”, the older clicks are still counted.

A possible solution will be to remove (or inactivate for history) the clicks of all record button once another button (or a defined list of buttons) of the same record is clicked.  
Or each document must take care of their clicks themselves but this solution is less customizable.

---

<div class="post-metadata">

### Author: ![sergyo](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/sergyo/32/181_2.png) [@sergyo](https://discuss.tryton.org/u/sergyo)
#### Post date: [October 8, 2016, 8:35am UTC](https://discuss.tryton.org/t/required-clicks-per-button/222/8 "2016-10-08T08:35:39Z")

</div>

That’s a great feature!!

> [@ced](#):
>
> A possible solution will be to remove (or inactivate for history) the clicks of all record button once another button (or a defined list of buttons) of the same record is clicked.  
> Or each document must take care of their clicks themselves but this solution is less customizable.

IMHO by default any change of state or click in another button should remove the clicks of our button and could be customized with a list of buttons as you propose.  
Another point is user notification. +1 for tooltip and counter for current user, but I think another users that clicked the button should be notified as well (when another user click or when their clicks are removed). This can be achieved with the “new” notes functionality.

---

<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: [October 8, 2016, 10:09am UTC](https://discuss.tryton.org/t/required-clicks-per-button/222/9 "2016-10-08T10:09:46Z")

</div>

> [@sergyo](#):
>
> +1 for tooltip and counter for current user, but I think another users that clicked the button should be notified as well

The counter and tooltip is visible to all users.

> [@sergyo](#):
>
> but I think another users that clicked the button should be notified as well (when another user click or when their clicks are removed). This can be achieved with the “new” notes functionality.

Using note will be a wrong usage of it. Note should be filled by users for users, not by the system. Indeed notification about modification should be managed by the [email notification](https://discuss.tryton.org/t/email-notification/71)

---

<div class="post-metadata">

### Author: ![sergyo](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/sergyo/32/181_2.png) [@sergyo](https://discuss.tryton.org/u/sergyo)
#### Post date: [October 8, 2016, 10:44am UTC](https://discuss.tryton.org/t/required-clicks-per-button/222/10 "2016-10-08T10:44:21Z")

</div>

> [@ced](#):
>
> The counter and tooltip is visible to all users.

That’s correct. But I was referring to notify other affected users at the moment in a reactive way.

> [@ced](#):
>
> Using note will be a wrong usage of it. Note should be filled by users for users, not by the system. Indeed notification about modification should be managed by the [email notification](https://discuss.tryton.org/t/email-notification/71)

Email notification would be a great option as well.

What about permissions about change workflow state when one button was clicked but needs more clicks? In your examples of sales if an user clicked Confirm but two clicks are required, did any user (with correct permissions) can go back to previous state?

---

<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: [October 8, 2016, 10:49am UTC](https://discuss.tryton.org/t/required-clicks-per-button/222/11 "2016-10-08T10:49:53Z")

</div>

> [@sergyo](#):
>
> That’s correct. But I was referring to notify other affected users at the moment in a reactive way.

For direct notification, I have an idea which is out of the scope of this feature. I will write another blueprint.

> [@sergyo](#):
>
> What about permissions about change workflow state when one button was clicked but needs more clicks? In your examples of sales if an user clicked Confirm but two clicks are required, did any user (with correct permissions) can go back to previous state?

Yes he can because he has the right. If for some reason company has a work-flow that prevent such behaviour, it should be added by customizing the workflow method or create a new workflow state. But I do not think it is a common use case because if we want multiple validation it is because we want to allow to cancel the validation.

---

<div class="post-metadata">

### Author: ![albert](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/albert/32/21_2.png) [@albert](https://discuss.tryton.org/u/albert)
#### Post date: [October 10, 2016, 7:49am UTC](https://discuss.tryton.org/t/required-clicks-per-button/222/12 "2016-10-10T07:49:18Z")

</div>

We recently created an “approval” module [1] (not finished) but it basically aims to cover the same requirement as this feature proposal.

The main difference (apart from the fact that you hack the button system) is that we expect a “sale\_approval” (or purchase\_approval) module, for example, that explicitly creates the “approval” records.

Some features we aimed to cover are:

- By creating the approval requiests explicitly it is very easy to have a “pending approvals” section for each user.
- Expects the user to explain why an item is rejected.
- Moving the sale to draft state, will set all the approval records to “Cancelled” state, so it keeps the history of what has happened.
- We keep track of when the request for approval was created and when has been approved (the company wants to know if something was purchased/sold too late) and whose fault it was.
- It is explicit who has to approve a document. Having the record of pending approvals it is more obvious what is missing for the document to be approved and who to press for their approval.

[1] [https://bitbucket.org/nantic/trytond-approval](https://bitbucket.org/nantic/trytond-approval)

---

<div class="post-metadata">

### Author: ![guillemNaN](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/guillemnan/32/69_2.png) [@guillemNaN](https://discuss.tryton.org/u/guillemNaN)
#### Post date: [October 10, 2016, 8:49am UTC](https://discuss.tryton.org/t/required-clicks-per-button/222/13 "2016-10-10T08:49:50Z")

</div>

I think the rule must to have a “Description” required field and the button contain a badge \* per rule that shows the number of clicks that match this rule (user group), a color or icon that shows if the rule is accomplished (with an alternative text for blind people that says if its approved or not) and a tooltip that shows the rule description to explain the user what are these badges and how to get the document approved (or reach the next state).

- see “Friends” item in “List Icons” example of Ionic Framework  
[http://ionicframework.com/docs/components/#item-icons](http://ionicframework.com/docs/components/#item-icons)

---

<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: [October 10, 2016, 11:07am UTC](https://discuss.tryton.org/t/required-clicks-per-button/222/14 "2016-10-10T11:07:44Z")

</div>

> [@albert](#):
>
> it is very easy to have a “pending approvals” section for each user

Indeed it is still easy with the current design. As what you called “approvals” are button clicks.

> [@albert](#):
>
> Expects the user to explain why an item is rejected.

As rejection will be based on clicking on other button, you still can put a comment wizard on the cancel/reject button.

> [@albert](#):
>
> It is explicit who has to approve a document.

I think it is a wrong design. It should not be “who has to” but “who is allowed to”. So approbation should follow our current button design using groups.

> [@guillemNaN](#):
>
> rule must to have a “Description” required field

Added but not required like the record rule.

---

<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: [October 11, 2016, 8:16am UTC](https://discuss.tryton.org/t/required-clicks-per-button/222/15 "2016-10-11T08:16:59Z")

</div>

> [@ced](#):
>
> As rejection will be based on clicking on other button, you still can put a comment wizard on the cancel/reject button.

Indeed I think rejection explanation is not linked to this feature at all. It should be something build in the document because rejection can even occurs when there is no multiple validation.

> [@ced](#):
>
> I think it is a wrong design. It should not be “who has to” but “who is allowed to”. So approbation should follow our current button design using groups.

In fact, I think this feature will create a new need to improve existing domains of documents. Common multi-validated document will require to have a Function Boolean field with searcher which will be True if the user has clicked.

---

<div class="post-metadata">

### Author: ![albert](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/albert/32/21_2.png) [@albert](https://discuss.tryton.org/u/albert)
#### Post date: [October 11, 2016, 3:23pm UTC](https://discuss.tryton.org/t/required-clicks-per-button/222/16 "2016-10-11T15:23:09Z")

</div>

I think this would be solved by your Function Boolean fields but just in case:

What we do is to have an explicit Group of users that have to approve it (not an explicit user). But in case there are several groups who must do it, you end up having two approvals.

Note that in some cases the company needs something like this: Users of group “X” must approve, if they do and the amount is \> 10.000€ then (and only after the it has been approved) somebody at group “Managers  
of X” has to approve too. And in that case, if amount \> 100.000, then “Managers of Managers of X” must approve too.

So “Managers of Managers of X” should have a list of documents to approve.

It seems to me that with the proposed design it will not be easy to create such list. Isn’t it?

I think the main difference is that in your proposal you check the rules in “real time” while what we do is check the rules (we don’t have rules, but you get the idea) and then create the approval requests on the group of users that have to validate them.

---

<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: [October 11, 2016, 3:41pm UTC](https://discuss.tryton.org/t/required-clicks-per-button/222/17 "2016-10-11T15:41:12Z")

</div>

The order is pointless. So it is just a matter of showing the records that a user must click on.

---

<div class="post-metadata">

### Author: ![albert](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/albert/32/21_2.png) [@albert](https://discuss.tryton.org/u/albert)
#### Post date: [October 11, 2016, 3:59pm UTC](https://discuss.tryton.org/t/required-clicks-per-button/222/18 "2016-10-11T15:59:53Z")

</div>

I don’t think the order is pointless. Most of the time, only if the “lower” level manager has approved a purchase will you want to raise it to an upper level.

The upper level does not want to be annoyed if the lower level are still deciding if they really need that purchase.

---

<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: [October 11, 2016, 4:02pm UTC](https://discuss.tryton.org/t/required-clicks-per-button/222/19 "2016-10-11T16:02:32Z")

</div>

Such archaic company will have the resources to customize the domain.

---

<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: [October 19, 2017, 9:53am UTC](https://discuss.tryton.org/t/required-clicks-per-button/222/20 "2017-10-19T09:53:20Z")

</div>


