Follow-up:
How to create a statement rule
Go to [Financial] → [Configuration] → [Statements] → [Rules] and click on “+” (Create a new record).
The general idea here is as follows:
In the “Criteria” tab, you define the criteria that have to be matched in the Origin line.
If all criteria do match to the origin statement line, then Tryton Statement Lines are created according to the parameters in the “Lines” tab.
Our objective now is to match a customer payment in the Origin lines, and let Tryton create a Statement Line which relates the Origin line to the Customer Invoice.
We begin with the criteria.
Enter a name for the new rule, and choose your Company and your Journal.
Now look at the “Information” section of your Origin line to find the matching criteria.
In the example, I set the Description (A) to “GUTSCHR. UEBERWEISUNG”, like in the corresponding field of the Origin Line.
I find the invoice number in the “Remittance Information” field of the Origin Line.
So, in the “Information Rules” section, click on “+” to add a record. Choose the key “Remittance Information”
Now comes the tricky (and powerful) part:
The value field (right of the Key field) is a Python Regular Expression, which can contain, amongst others, a named group called “invoice”.
So we can define a Python RegEx that, when it matches our Remittance Information, gives back the invoice number.
For our example (B), the simple expression
R. Nr.: (?P<invoice>.*)
will do it.
A more sophisticated expression would be
(?i)R\w*\.*:*-*\w*\.*:* (?P<invoice>.{8})
which matches variants like “Rech-Nr:”, “RE.NR:”, and so on.
For now, we type the simple expression and click on “Apply changes”.
This was the complicated part, the rest is easy.
Go to the “Lines” tab, click “+” to add a record, and enter the variable name “amount” in the “Amount” field.
Leave “Party” and “Account” empty, Tryton will get the party and account automatically from the invoice data.
Click “Apply changes”, save your new rule, and that’s it.
To check if the rule works, open the Statement and click on “Apply Rules”. The Statement Lines for this origin line should now be created automatically.
Note on the “Description” field
A regular expression can also be used in the “Description” field.
In our example, if our customer would make a realtime transfer (instead of a normal transfer), the description would contain “ECHTZEIT-GUTSCHRIFT”.
So instead of “GUTSCHR. UEBERWEISUNG”, we could use the regex
GUTSCHR. UEBERWEISUNG|ECHTZEIT-GUTSCHRIFT
to match both a normal and a realtime transfer.
Note on invoice number format
I chose “Number/Year” as invoice number format. The customer in the example wrote correctly “150/2022”, which matches perfectly.
Most customers write things like “150-2022”, “150 2022”, “150 aus 2022”, or just “150”.
This cannot be matched directly with the above rule.
So I decided to change numbering format for invoices to a plain number without special characters in the future.
Brief aside: How to test Python Regular Expressions with named groups
To experiment with regular expressions and named groups outside of Tryton:
- Start your python3 interpreter:
$ python3
- Import the Python regular expressions module
>>> import re
- Enter your regular expression test. For our above example:
>>> result = re.search(r"R. Nr.: (?P<invoice>.*)", "R. Nr.: 150/2022")
- Check the result
To see if the group “invoice” is correctly filled:
>>> result.group('invoice')
'150/2022'