-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add tax collection and blocked countries processing #166
Open
jkachel
wants to merge
18
commits into
main
Choose a base branch
from
jkachel/5766-tax-collection-blocked-countries-proc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jkachel
added
the
product:unified-ecommerce
Issues related to the Unified Ecommerce project
label
Nov 4, 2024
- Add the mitol-django-geoip library - Add a user_profile model so we can cache some additional user info from Keycloak - Update the APISIX middleware to pull additional data into the profile when it exists - Add some fields to the basket to track user location data (since we'll need it elsewhere)
- Adds some APIs for determining the location of the user - Adds the TaxRate and BlockedCountry models - Adds a test setting (force profile country) - Adds some factories
- Formatted some stuff that's unrelated (inadvertently but it's probably a good idea anyway) - Added PLR0913 to test ignore list because tired of seeing it - Added tests for location determination stuff
- Added some dataclasses for location metadata - Updated basket location storage to split out tax and blocked country geolocations (since they might be different) - Finished up tests - Updated the blanket ruff ignore list to add line length to migrations The basket location stuff will need to migrate into the order too but haven't done that yet.
- Renamed "authentication" to "users" (it really didn't have anything to do with auth) - Adjusted the hooks for basket_add to fix some circular import issues and cause less database hits - Updated the Order model to match the Basket for user data and tax rate additions - Updated TaxRate and BlockedCountry to use SoftDelete - Added at least one point where it should run the location-based checks - adding an item to cart will now actually check blocked countries and taxes now
- Added a bunch of helper functions for price calculation in the basket - Added py-moneyed for said price calculations - Updated the cart to show tax if it's been calculated
jkachel
force-pushed
the
jkachel/5766-tax-collection-blocked-countries-proc
branch
from
November 4, 2024 21:32
2ca96bc
to
ff8044c
Compare
- Moved a migration so it's not out of order now - Fixed some stuff that got munged up by doing the merge - Ran ruff and fixed a bunch of issues (ruff config is not the best at the moment, need to fix that too, later) - Updated the pyproject.toml to ignore some stuff that we're unlikely to change
jkachel
force-pushed
the
jkachel/5766-tax-collection-blocked-countries-proc
branch
from
November 4, 2024 22:17
23c8789
to
04064ce
Compare
… order properly - Add some more columns to the test mule cart page - Fix some places where we're using floats for money - Update the Order to pull in the tax and blocked countries check fields - Add some more helpers to get Money objects out when that makes more sense than a Decimal - Bump versions of some stuff so geoip has migrations, etc.
Using CountryField makes Spectacular expand the enum and since they're the same it emits a warning.
…he model tax calcs
…or testing - The logic that was in CustomerVerificationHooks is now in payments/api.py - this pulls the logic out into a more reusable place and also makes it much easier to write tests - Add tests for the various steps of the basket_add hook - Fix a couple of logic errors that came up in testing
… UserProfile, fix up order tax collection Not done: this will also require a new version of payment_gateway and the tax collection needs a bit of help still Also adds a cancel button to the checkout interstitial so you can stop the form submit
… dependency on py-moneyed if i have to quantize the decimal then py-moneyed doesn't really help any
jkachel
force-pushed
the
jkachel/5766-tax-collection-blocked-countries-proc
branch
from
November 8, 2024 13:48
cd536bd
to
6029d40
Compare
jkachel
added
Needs Review
An open Pull Request that is ready for review
and removed
Work in Progress
Not done yet.
labels
Nov 12, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Needs Review
An open Pull Request that is ready for review
product:unified-ecommerce
Issues related to the Unified Ecommerce project
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What are the relevant tickets?
Closes mitodl/hq#5766
Description (What does it do?)
Adds a
basket_add
hook that is fired before a user adds an item to their basket, so we can perform tasks based on the user and product being added.Adds a wrapper plugin to pull in some data that other plugins will need and finish setting up the basket object. (At the moment, this means geolocating the user for tax lookup and blocked countries reasons.) Geolocation works based on geolocating via IP and by considering the user's profile.
Adds a check for blocked countries that runs when an item is added to the basket. If the user belongs to a country that we've blocked either globally in UE or for a particular product, the check raises an exception and basket processing stops.
Adds a check for tax assessment for the user. If the user is in a country that assesses tax, we then flag the basket as being taxable with the rate that matches for the user.
Pulls in the geoip code from ol-django for geolocation, adds support for field mappings in the APISIX middleware, and adds a few other necessary things for this process. It also adds the necessary data to orders so tax is collected through the order process, and updates the display of the orders in Django Admin to make them more usable.
Screenshots
Completed order in Django Admin (displays the new fields/groupings):
Cart with some updates to show tax/etc.:
How can this be tested?
You will need to import the MaxMind GeoLite2 databases. See the documentation in the ol-django geoip app for instructions.
For best results, simply add a "country code" to your user profile manually through the Django Admin.
For completed orders that involve tax:
For completed orders that involve discounts: