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

If overriding tax_category, it only makes sense to update tax_categor… #11802

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

Conversation

mrbrdo
Copy link
Contributor

@mrbrdo mrbrdo commented Nov 22, 2022

…y_id as well

fixes confusing display of Tax category as "None" in admin, while it actually uses "Default"
ideally, it would be better to update the tax_category_id in the DB and re-update any time TaxCategory#is_default changes

I can also implement the "ideal" solution as described but it will require to add a migration (which means when updating spree, migrations need to be copied again, and ran).

Also in this case, is there any reason why Product#tax_category_id would actually be nil, or can we make it mandatory? In the current implementation it will always return the default category. Is it possible to create (and use) a product without having any tax categories?
On the other hand, I assume we always want Variant#tax_category_id to fallback to Product#tax_category_id unless explicitly set.

After some thinking, need a comment on this. Using this solution, the tax_category_id will also be set in the DB after the product is updated (in the backend) due to how Rails forms work. This means that if default TaxCategory is changed, these products will keep using the same TaxCategory as before. In the current implementation, they would switch to the new default, which may be the desired behavior.
But on the other hand having tax_category_id not reflect tax_category, and having it show up as None in the backend both sounds wrong. Honestly for the last 6 months I have been clicking to change it to Default (the name of my default TaxCategory) on every new product, since I wasn't clear what None would do.

@viezly
Copy link

viezly bot commented Nov 22, 2022

Changes preview:

Legend:

👀 Review pull request on Viezly

…y_id as well

fixes confusing display of Tax category as "None" in admin, while it actually uses "Default"
ideally, it would be better to update the tax_category_id in the DB and re-update if
TaxCategory#is_default changes
mrbrdo referenced this pull request Nov 22, 2022
When Tax Category was deleted all Variants using that category would raise ActiveRecord::RecordNotFound when `#tax_category` was called on Variant object.
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.

None yet

1 participant