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

[trep-engine.scm] upgrade engine to improve calculated-cells handling #1618

Merged

Conversation

christopherlam
Copy link
Contributor

@christopherlam christopherlam commented Apr 27, 2023

This branch offers an upgrade to trep-engine so that the calculator-fn handles both split and transaction-row?. calculated-cells is now a versioned record cells, each cell has 7 fields.

for use by #1617 by @dawansv -- instead of vector you'll need to make-cell.

Note income-gst-statement.scm stil offers the previous list of vectors, each vector has 6 fields, as a proof of backward compatibility.

EDIT: instead of records, it may be safer to use an assoc-list which is easier to upgrade eg.

     (if (column-uses? 'amount-single)
              (list (list (cons 'header (header-commodity (G_ "Amount")))
                          (cons 'calc-fn converted-amount)
                          (cons 'reverse-col? #t) 
                          (cons 'subtotal? #t)
                          (cons 'friendly-heading-fn (const ""))
                          (cons 'merge-dual-column #f)))
              '())

@dawansv
Copy link
Contributor

dawansv commented Apr 27, 2023

This is very nice! Lots to like here.

I like the idea of using a version 2 structure and then using the conversion procedure. Very clean.

I actually quite like the use of record because the field names used throughout the code when values are retrieved make the code so much more readable than the use of vector-ref. The assoc-list would work as well since it would show the key name.

The use of records has the added benefit of leaving the current column definition almost unchanged except for the vector -> make-cell conversion. So if people want to upgrade custom reports to v2 to get the extra parameter, it is quite easy with only that one change and the additional tr? parameter in the calculator functions.

Also although it's nice to see the key/value pair in the column definition with the assoc-list, it's a lot of extra code repeating these on every column, and I guess another potential source for errors? You mention it might be safer so that could be a +, although I don't quite have the knowledge to know why.

All in all this is a solid upgrade I think.

@christopherlam
Copy link
Contributor Author

christopherlam commented Apr 27, 2023

Also although it's nice to see the key/value pair in the column definition with the assoc-list, it's a lot of extra code repeating these on every column, and I guess another potential source for errors? You mention it might be safer so that could be a +, although I don't quite have the knowledge to know why.

Yes it's a source of errors, however (assq-ref alist 'inexistent-symbol) will return #f instead of crashing. It's also safer and easier to further upgrade to add another metadata, simply by adding another pair. It will not require versioning at all; it becomes a features-based upgrade.

@christopherlam
Copy link
Contributor Author

Modified. Remove arbitrary versioning. Maintain legacy vector to alist upgrade.

@christopherlam christopherlam force-pushed the stable-upgrade-trep-engine branch 4 times, most recently from d8af9a9 to fb4e8dc Compare April 27, 2023 14:36
@dawansv
Copy link
Contributor

dawansv commented Apr 28, 2023

That's pretty nice as well. I like your invalid-cell? function doing a good job at replacing what the record was doing in terms of making sure the required "fields" are propertly named. Having the keys in the column definitions definitely makes the code more readable. And I like the use of the cut macro to retrieve the values to avoid having to revert back to the longer lambda form that the use of record had gotten rid of.

calculated-cells was formerly a vector of RHS info - heading,
calculator-fn, subtotal? etc.

This upgrades it so that calculator-fn now accepts two arguments -
split and transaction-row? which is a bool. It uses a basic record
with version and list-of-cells, and each cell is a record (instead of
a vector) with relevant members.

This also enables the engine to handle previous calculated-cells --
note the income-gst-statement.scm will offer the previous one and will
be transparently upgraded to the above -- see the function
upgrade-to-calculated-cells-v2
christopherlam added a commit to christopherlam/gnucash that referenced this pull request Apr 29, 2023
@code-gnucash-org code-gnucash-org merged commit 08e9f48 into Gnucash:stable Apr 29, 2023
3 checks passed
@christopherlam christopherlam deleted the stable-upgrade-trep-engine branch April 29, 2023 00:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants