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

Moving Account.amount to Account.credit & Account.debit #133

Merged
merged 39 commits into from
Aug 29, 2024

Conversation

adamcharnock
Copy link
Owner

@adamcharnock adamcharnock commented Jul 1, 2024

I've had a go at this this morning, and you can see the the core changes here.

Most of the lines changed are tests.

Notes:

  • It is a straightforward but far-reaching change
  • I was hoping this would drop out a bunch of complexity, but it did not
  • my_leg.amount is still available as a property on the Django model. It is now always a positive value.
  • Can still use the amount argument when creating a Leg, a deprication warning will be shown.
  • I've added amount_legacy (I.e. debits are negative) to the LegView, so it is still available at my_leg.view.amount_legacy
  • I'm not against merging this for Hordak 2.0 or 3.0
  • The more time I spend with this branch the more it does feel like a much better way to structure things. I'm rather in favour of merging this.

Remaining Tasks

  • Test against MySQL
  • Trigger to ensure that only credit or debit is set
    • Test
  • Trigger to ensure that credit/debit is > 0
    • Test

Follow-up work

I'll do this next in another PR

@adamcharnock adamcharnock marked this pull request as draft July 1, 2024 06:22
@adamcharnock
Copy link
Owner Author

I would love the input of both @nitsujri and @PetrDlouhy on this.

@nitsujri - I know this isn't precisely what you asked for, but what are your thoughts?

@PetrDlouhy - How comfortable would be feel about deploying this kind of change (once stable) into your production environment?

@adamcharnock adamcharnock marked this pull request as ready for review July 1, 2024 18:37
@adamcharnock adamcharnock changed the title Experiment in moving Account.amount to Account.credit & Account.debit Moving Account.amount to Account.credit & Account.debit Jul 1, 2024
@adamcharnock adamcharnock requested a review from PetrDlouhy July 1, 2024 20:53
@adamcharnock
Copy link
Owner Author

All tests now passing 🎉🎉🎉

@adamcharnock adamcharnock changed the title Moving Account.amount to Account.credit & Account.debit Moving Account.amount to Account.credit & Account.debit Jul 2, 2024
Copy link
Contributor

@nitsujri nitsujri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love everything about this. I won't be able to test this until August due to travels and deadlines, but in spirit, I 100% approve and happy to see it go out ahead of our team's direct testing.

hordak/models/core.py Outdated Show resolved Hide resolved
@@ -155,7 +155,7 @@ def test_utility_bill(self):

# We receive the actual bill (we are moving a negative amount of money,
# as this is an outgoing)
self.gas_payable.transfer_to(self.cash, Money(-300, "EUR"))
self.cash.transfer_to(self.gas_payable, Money(300, "EUR"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incredible! I'm insanely excited to see this change right here.

I'm sure you already know this, but just stating it explicitly to be on the same page:

This is a breaking change for anyone doing RHS -> LHS, vice versa - using the current .transfer_to. Saw that accounting_transfer_to "effectively" replaces it which I think is 100% correct, just it's a significant change and warrants an "Upgrade to 2.0" document.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm very pleased to hear it! And yes, absolutely understood re upgrading. I've put these notes in the changelog. How does that seem to you?

@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 84.57944% with 33 lines in your changes missing coverage. Please review.

Project coverage is 89.52%. Comparing base (9f11999) to head (ab11c27).
Report is 7 commits behind head on master.

Files Patch % Lines
hordak/tests/models/test_core.py 73.95% 25 Missing ⚠️
hordak/templates/hordak/transactions/leg_list.html 0.00% 4 Missing ⚠️
...nagement/commands/create_benchmark_transactions.py 0.00% 2 Missing ⚠️
hordak/forms/transactions.py 85.71% 0 Missing and 1 partial ⚠️
...emplates/hordak/transactions/transaction_list.html 0.00% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #133      +/-   ##
==========================================
- Coverage   90.62%   89.52%   -1.10%     
==========================================
  Files          69       69              
  Lines        4414     4506      +92     
  Branches      294      324      +30     
==========================================
+ Hits         4000     4034      +34     
- Misses        363      415      +52     
- Partials       51       57       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

CHANGES.txt Outdated Show resolved Hide resolved
@adamcharnock
Copy link
Owner Author

Hi @PetrDlouhy – I'm inclined to merge this sometime soon. If you wanted to have a dramatic "I object!" moment then please do so soon (other reasoned input also very welcome)

@nitsujri
Copy link
Contributor

Would it be possible to remove the views? I believe the views are now no longer needed?

Specifically migrations against any column that is part of a view becomes a pain.

@PetrDlouhy
Copy link
Collaborator

Ať first glance this seems reasonable. I don't have any direct objection.
I would have to find some time to test this with my project to tell more.

Copy link
Contributor

@nitsujri nitsujri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was able to test it on our codebase. Overall looks great after internal modifications.

Recommended changes:

  • Remove views
  • Leg.credit and debit max_digits needs to use HORDAK_MAX_DIGITS.
  • get_queryset needs to swap signs based on account type.

hordak/migrations/0044_legview.py Show resolved Hide resolved
hordak/admin.py Outdated Show resolved Hide resolved
@adamcharnock
Copy link
Owner Author

@nitsujri

Leg.credit and debit max_digits needs to use HORDAK_MAX_DIGITS.

Done

get_queryset needs to swap signs based on account type.

Done

Remove views

Done

I'm a bit loathed to removed them as I think they may be useful, but I'm also willing to be found wrong on this. I've therefore added this warning to the docs for each view: Hordak's database views are still experimental and may change or be removed in a future version.

In the mean-time, my hope is that the new way of structuring sql-heavy migrations will make this problem less onerous.

@adamcharnock
Copy link
Owner Author

I've also made some additional changes, in particular moving many balance calculations into annotations. I think this should help performance a lot. Once this settles we can see if something like #76 (running totals) is still required.

I'll merge this soon unless anyone cries out. Let me know if you find any time for some testing @PetrDlouhy. I could always do an alpha-release if that helps at all.

Copy link
Contributor

@nitsujri nitsujri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debit column still holds negative value post migration - blocking issue.

hordak_leg
SET
credit = CASE WHEN amount > 0 THEN amount END,
debit = CASE WHEN amount < 0 THEN amount END,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried migrating our staging system in preps for production. Found the debit column was holding a negative value. Same with the views.

I believe it should be flipped?

debit = CASE WHEN amount < 0 THEN -amount END,

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for catching this! Fixed.

@adamcharnock adamcharnock merged commit da9a3c7 into master Aug 29, 2024
23 checks passed
@adamcharnock
Copy link
Owner Author

A pre-release is now out as 2.0.0a1 🎉🎉🎉🎉🎉

A huge thank you to @nitsujri and @PetrDlouhy for working through this with me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants