CASE: automatically propose an adjustment

It is now possible to create an adjustment button that lets users click on it and lead to the adjustment page, but with the adjustment already filled in (based on Liquid logic):

The extra button on the left below will lead to this:

Here’s some example code, with some added comments to explain the code:


{% comment %}This case describes the functionality of the adjustmentbutton-tag which can create a button to automatically make an adjustment, filled with values taken from Liquid logic{% endcomment %}
{% ic %}{::infotext}
{% t "Select all accounts that need to be counter booked" %} {% input custom.accounts.counter as:account_collection range:"2" %}
{% t "Depending on the value of all accounts, the remaining value will be booked to either 76 or 66 range" %}
{:/infotext}{% endic %}

{% comment %}We take the value of the chosen accounts to create a account collection{% endcomment %}
{% assign accounts = period.accounts | range:custom.accounts.counter %}

{% comment %}Show all accounts with the remaining value{% endcomment %}
{% stripnewlines %}
| Acc nbr
| Acc descr.
| Acc value
{% newline %}
|----10%----
|----75%----
|-----------:+
{% for acc in accounts %}
  {% newline %}
  | {{ acc.number }}
  | {{ acc.name }}
  | {% =$0+ acc.value as:currency %}
{% if forloop.last %}
  {% newline %}
  |
  |
  |_^ {{ $0 | currency }} ^_| {% comment %}this value is needed for the counter booking as well{% endcomment %}
{% endif %}  
{% endfor %}
{% endstripnewlines %}

{% comment %}some text we want to display on the adjustment button{% endcomment %}
{% capture adj_txt %}{% t "Create adj." %}{% endcapture %}

{% comment %}Now we'll loop over all those accounts again and counter book them - the remaining value taken in register $0,  will be used as a counter booking as well{% endcomment %}
{% adjustmentbutton text:adj_txt %}

{% for acc in accounts %}
  {% comment %}description for the counter booking{% endcomment %}
  {% capture description %}{% t "Counter booking" %}{% endcapture %}
  
  {% comment %}needed to propose the counter value of the original value of the account - the type of account and its sign will decide if it is D or C{% endcomment %}
  {% assign value_acc = -acc.value %} 
  
  {% comment %}the attribute "original_account_number" is used to give the account number to be made, with account_name the name and the description. This can be linked to fixed values or local variables you create. And the value can be anything, but it is the combination of the value (+/-) and the type of account (asset/liability/...) that defines where the value needs to be in the adjustment (D/C){% endcomment %}
  {% adjustmenttransaction original_account_number:acc.number account_name:acc.name description:description value:value_acc %}
  
  {% comment %}only one line has to be created extra as the counter booking - see value taken in $0{% endcomment %}
  {% if forloop.last %} {% comment %}only needed one time, at the end of the loop{% endcomment %}
    {% if $0 > 0 %}
      {% comment %}this means the counter booking needs to be on acc 660000{% endcomment %}
      {% assign counter_acc = "660000" %}
      {% assign counter_name = "Counter loss" %}  
    {% else %}
      {% comment %}this means the counter booking needs to be on acc 760000{% endcomment %}
      {% assign counter_acc = "760000" %}
      {% assign counter_name = "Counter profit" %}      
    
    {% endif %}
    {% assign counter_value = $0 %}  {% comment %}no need to counter the sign of the value{% endcomment %}
    
    {% adjustmenttransaction original_account_number:counter_acc account_name:counter_name description:description value:counter_value %}
  {% endif %}
{% endfor %}

{% endadjustmentbutton %} 

Of course, there are way lot more possibilities and better cases for this.
For example you could add the tag category in it so the adjustment can be marked as external or internal (only works with those values as those are the only options).