Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested if statements for better CSV import #1393

Open
mgajda opened this issue Nov 16, 2020 · 6 comments
Open

Nested if statements for better CSV import #1393

mgajda opened this issue Nov 16, 2020 · 6 comments
Labels
A-WISH Some kind of improvement request, hare-brained proposal, or plea. csv The csv file format, csv output format, or generally CSV-related.

Comments

@mgajda
Copy link

mgajda commented Nov 16, 2020

I did not find a way to make a conjunction of multiple conditions in CSV import documentation nor examples.

Small example:

  1. Director's fees are classified separately from wages, but director's reimbursements are treated the same as other emps:
if
payroll
  account2 expenses:operating:payroll:wages
  if
  director
    account2 expenses:operating:payroll:directors-fees

if
reimbursement
  account2 expenses:operating:education  

Documentation:

In order to make a conjunction of conditions you may nest if statements with indentation.
For example when director's fees are classified separately from wages, but director's reimbursements are treated the same as other emps...

This allows you to conveniently build nested matching rules.

@mgajda mgajda added the A-WISH Some kind of improvement request, hare-brained proposal, or plea. label Nov 16, 2020
@simonmichael simonmichael added the csv The csv file format, csv output format, or generally CSV-related. label Nov 17, 2020
@simonmichael
Copy link
Owner

Hi @mgajda, since 1.19 you can combine matchers with &: https://hledger.org/csv.html#combining-matchers .

@alerque
Copy link
Collaborator

alerque commented Nov 17, 2020

Combining matchers into an AND operation is not the same thing as being able to nest them.

I believe Michal's case could be coded pretty easily using a single flat level of matches (with or without and AND matcher) but the order of operations becomes critical and off the top of my head I'm not sure what it is and I don't see it skimming the docs. Are rules guaranteed to match in a certain order?

@simonmichael
Copy link
Owner

@alerque yes rules are evaluated in the order you'd expect (related: https://hledger.org/csv.html#how-csv-rules-are-evaluated). And you're right, @mgajda doesn't need nesting or ANDing here, this would do:

if payroll
  account2 expenses:operating:payroll:wages
# more specific rule overriding the above:
if director
  account2 expenses:operating:payroll:directors-fees

Nesting if blocks is unlikely to get implemented I suspect.

@mgajda
Copy link
Author

mgajda commented Nov 18, 2020

Yes, I upgraded to latest hledger from GitHub and use & conjunction as a workaround. However, it is somewhat inconvenient when ruleset grows.

@simonmichael
Copy link
Owner

Could you give an example ?

@the-solipsist
Copy link
Collaborator

If "Nesting if blocks is unlikely to get implemented", could we close this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-WISH Some kind of improvement request, hare-brained proposal, or plea. csv The csv file format, csv output format, or generally CSV-related.
Projects
None yet
Development

No branches or pull requests

4 participants