# Rules / regular expression with account\_statement\_rule

**URL:** https://discuss.tryton.org/t/rules-regular-expression-with-account-statement-rule/2457
**Category:** User
**Created:** [March 16, 2020, 4:27pm UTC](https://discuss.tryton.org/t/rules-regular-expression-with-account-statement-rule/2457 "2020-03-16T16:27:56Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![edbo](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/e/f14d63/32.png) [@edbo](https://discuss.tryton.org/u/edbo)
#### Post date: [March 16, 2020, 4:27pm UTC](https://discuss.tryton.org/t/rules-regular-expression-with-account-statement-rule/2457/1 "2020-03-16T16:27:56Z")

</div>

I’m playing around with the account\_statement\_rule module, but I just walked into a problem. I want to have a rule where:

- (party is empty or not) and amount \> 0 → the account should be ‘receivable’
- (party is empty or not) and amount \< 0 → the account should be ‘payable’

How to achieve this?

---

<div class="post-metadata">

### Author: ![edbo](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/e/f14d63/32.png) [@edbo](https://discuss.tryton.org/u/edbo)
#### Post date: [March 16, 2020, 5:04pm UTC](https://discuss.tryton.org/t/rules-regular-expression-with-account-statement-rule/2457/2 "2020-03-16T17:04:26Z")

</div>

I’m just thinking about a small enhancement to get this working:

The module is never looking if there is a party on the origin. So I would propose to change [https://hg.tryton.org/modules/account\_statement\_rule/file/tip/account.py#l360](https://hg.tryton.org/modules/account_statement_rule/file/tip/account.py#l360)

```auto
party = self.party

```

to

```auto
party = self.party or origin.party

```

The module then checks first if there is a `party` on the rule. If not get the party from the `origin`.

---

<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: [March 16, 2020, 5:40pm UTC](https://discuss.tryton.org/t/rules-regular-expression-with-account-statement-rule/2457/3 "2020-03-16T17:40:57Z")

</div>

Which will be the benefit of your proposal?  
The party of the line and the party of the origin should be exactly the same.

---

<div class="post-metadata">

### Author: ![edbo](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/e/f14d63/32.png) [@edbo](https://discuss.tryton.org/u/edbo)
#### Post date: [March 16, 2020, 6:44pm UTC](https://discuss.tryton.org/t/rules-regular-expression-with-account-statement-rule/2457/4 "2020-03-16T18:44:51Z")

</div>

I forgot a small detail: I **import** the bank statements, so the origin lines are created automatically.

> [@pokoli](#):
>
> The party of the line and the party of the origin should be exactly the same.

Yes, but the account\_statement\_rule doesn’t do anything with that. It tries to find the party again based on account number or party name, but neither of those exists in the keywords. And if there is no party, the rule-system stops.

> [@pokoli](#):
>
> Which will be the benefit of your proposal?

When you want to create origin lines with an account where party is required and the rule-system doesn’t find a party, the rule-system should try to get the party from the origin line. If it then fails, that’s no problem.  
In this way, users are able to automatically generate almost all the statement lines, which is a big win, when you have a lot of origin lines with a party. Those lines are then automatically generated.

---

<div class="post-metadata">

### Author: ![edbo](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/e/f14d63/32.png) [@edbo](https://discuss.tryton.org/u/edbo)
#### Post date: [March 16, 2020, 7:13pm UTC](https://discuss.tryton.org/t/rules-regular-expression-with-account-statement-rule/2457/5 "2020-03-16T19:13:00Z")

</div>

> [@pokoli](#):
>
> Which will be the benefit of your proposal?

With the change I can do all the work in about 4 steps:

1. import bank statement
2. open a bank statement and make the tab “Origins” active
3. press the “Apply Rules” button
4. validate / post / reconcile

As a small company I don’t want to spend a lot of time. I think I can catch almost all of the origin lines with a set of rules.

---

<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: [March 16, 2020, 11:38pm UTC](https://discuss.tryton.org/t/rules-regular-expression-with-account-statement-rule/2457/6 "2020-03-16T23:38:43Z")

</div>

> [@edbo](#):
>
> When you want to create origin lines with an account where party is required and the rule-system doesn’t find a party, the rule-system should try to get the party from the origin line.

How could you not have the party on the statement line but on the origin? The origin is created first and lines are created based on the origin so they should have party filled.

---

<div class="post-metadata">

### Author: ![edbo](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/e/f14d63/32.png) [@edbo](https://discuss.tryton.org/u/edbo)
#### Post date: [March 17, 2020, 10:27am UTC](https://discuss.tryton.org/t/rules-regular-expression-with-account-statement-rule/2457/7 "2020-03-17T10:27:38Z")

</div>

> [@ced](#):
>
> How could you not have the party on the statement line but on the origin? The origin is created first and lines are created based on the origin so they should have party filled.

During importing the statement, the party is searched based on bank account number. So most of the origin lines have a party based on that. However the account\_statement\_rule doesn’t do anything with that. Instead it tries to find the party again. See [https://hg.tryton.org/modules/account\_statement\_rule/file/tip/account.py#l314](https://hg.tryton.org/modules/account_statement_rule/file/tip/account.py#l314) and [https://hg.tryton.org/modules/account\_statement\_rule/file/tip/account.py#l352](https://hg.tryton.org/modules/account_statement_rule/file/tip/account.py#l352). It would be a nice if the module also checks if a party exists on the origin.

---

<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: [March 17, 2020, 11:57am UTC](https://discuss.tryton.org/t/rules-regular-expression-with-account-statement-rule/2457/8 "2020-03-17T11:57:42Z")

</div>

OK it is when the rule creates a new line based on the origin. So I agree that it will be better to use the party of origin if set but only after trying to find it from the keywords rule.

---

<div class="post-metadata">

### Author: ![edbo](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/e/f14d63/32.png) [@edbo](https://discuss.tryton.org/u/edbo)
#### Post date: [March 17, 2020, 12:28pm UTC](https://discuss.tryton.org/t/rules-regular-expression-with-account-statement-rule/2457/9 "2020-03-17T12:28:34Z")

</div>

Yes, I agree and I think that’s the case in my second message of this thread.

---

<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: [March 17, 2020, 1:12pm UTC](https://discuss.tryton.org/t/rules-regular-expression-with-account-statement-rule/2457/10 "2020-03-17T13:12:14Z")

</div>

No using the origin party should be fallback after the rules not before. Because it is the point of the rule to fill those field using expression. For example the same bank account can be used by different parties.
