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

Adds database support for tax identifiers #2832

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jkachel
Copy link
Contributor

@jkachel jkachel commented Nov 21, 2023

Pre-Flight checklist

  • Migrations
    • Migration is backwards-compatible with current production code
  • Testing
    • Code is tested
    • Changes have been manually tested

What are the relevant tickets?

Closes mitodl/hq#2794

What's this PR do?

This PR contains only model additions.

To the TaxRate table:

  • Adds a tax ID and tax ID name field to store MIT's tax identifier for a given country. These default to empty string and "GSTIN", respectively.

To the Orders table:

  • Adds a foreign key to the TaxRate table, solely for linking MIT's tax identifier to the order. This defaults to null.

To the B2BOrders table:

  • Adds the tax calculation fields - country, rate, tax name - so assessed tax (where applicable) can be tracked as it is in the Order table.
  • Adds a foreign key to the TaxRate table, solely for linking MIT's tax identifier to the order. This defaults to null.
  • Adds a set of fields to store the customer's tax identifier information. These default to null.

These should facilitate the process of adding the GSTIN and collecting tax IDs for B2B orders in the frontend. They should appear in the serializers as expected. This PR doesn't contain any frontend changes - those will be taken care of in a separate issue and PR (since I believe we're waiting on that info at the moment).

How should this be manually tested?

Automated tests should pass. This is just a set of model changes so you should see the new fields in the database.

What GIF best describes this PR or how it makes you feel?

💸

Comment on lines +158 to +174
tax_country_code = models.CharField(max_length=2, blank=True, null=True)
tax_rate = models.DecimalField(
max_digits=6, decimal_places=4, null=True, blank=True, default=0
)
tax_rate_name = models.CharField(max_length=100, null=True, default="VAT")

# These represent the customer's tax identifier for the order
customer_tax_identifier = models.TextField(default="")
customer_tax_identifier_name = models.CharField(
max_length=100, null=True, default=""
)

# This is the FK to the tax rate for MIT's tax identifier
mit_tax_identifier = models.ForeignKey(
TaxRate, on_delete=models.DO_NOTHING, blank=True, null=True
)

Copy link
Contributor

Choose a reason for hiding this comment

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

Although we know we used separate fields to keep the data consistent w.r.t to the time of order, now that we are moving onwards, and added a foreign key to the same table as well. Do you think this might be the time we start using table versioning? Just like how we use product versions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this is probably the better route, especially at the moment since we're not (AFAIK) using this actively quite yet. Doing this will be a bigger change so it will be a bit before it's done.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree. Making a decision about doing this would probably depend upon:

  1. What's the urgency of this?
  2. Are we using the Tax feat in production yet? If yes, We'll also need to migrate the data.

FYI, @cachob

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't speak to urgency but we should not be collecting tax currently - the code is there but all the defined tax rates are turned off, which effectively disables the tax collection code.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jkachel Thanks for your response. My bad, My intention was actually to ask this from @cachob.

@cachob Could you respond on #2832 (comment)?

@pdpinch
Copy link
Member

pdpinch commented Nov 29, 2023 via email

@arslanashraf7
Copy link
Contributor

I think I’m missing some context here. What data are you considering versioning?

Actually, the TaxRate table entries might be edited over time because the Tax rate itself might change in the future. However, we wanted to retain the older tax rate for orders that were placed at a specific time so that each order price remains consistent over time. e.g. If an order was placed with a GST of 18% in June 2023, It should remain even when that GST tax rate changes to 20% after some time.

To solve this, We initially introduced independent fields in the Order model and we'd just copy the Tax Rate name, %, etc in the Order table at the time of order so the Order doesn't depend upon the Tax Rate table.

I'm cautious about versioning because it adds a lot of complexity which flows downstream through the data platform and reporting.

I agree this would add complexity.

What would be the downside if we don't version?

Just that we would have extra fields in Order and B2B orders, Which we can definitely live with if we don't version the Tax Rate table.

@jkachel
Copy link
Contributor Author

jkachel commented Feb 20, 2024

After looking back at this, I think the best/easiest solution to this would be to capture MIT's GSTIN in the TaxRate table, and then capture it again in the individual Order and B2BOrder records when an order is saved. (So, the same workflow we use for the tax rates themselves.) This would avoid the complexity of versioned tables, avoid issues with the FK, and bring this to parity with the existing tax rate implementation.

@arslanashraf7 thoughts?

@arslanashraf7
Copy link
Contributor

After looking back at this, I think the best/easiest solution to this would be to capture MIT's GSTIN in the TaxRate table, and then capture it again in the individual Order and B2BOrder records when an order is saved. (So, the same workflow we use for the tax rates themselves.) This would avoid the complexity of versioned tables, avoid issues with the FK, and bring this to parity with the existing tax rate implementation.

@arslanashraf7 thoughts?

Thanks for bringing this back to my attention. I agree, if we don't want to keep a versioning table we will need to capture them in independent fields in order and tax rate tables. Just putting it out here so you know how I'm understanding it:

  1. The current GSTIN would always be in the TaxRate table (This can change over time)
  2. As for the order GSTIN would be part of the Order/B2bOrder tables. (This won't change, Probably a readable field only)

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

Successfully merging this pull request may close these issues.

None yet

4 participants