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

Tax clean-up and refactoring (SHOOP-975) #189

Merged
merged 59 commits into from Oct 1, 2015
Merged

Conversation

suutari-ai
Copy link
Contributor

Main part of all this goes to refactoring everything to use
Shop.create_price. That should prevent taxful/taxless price mismatches
in a Shop.

Prices and other money amounts are now passed as Money and Price objects
in the code, which ensures some more type safety. Yeppee!

TaxModule API was rethought through and got some changes.

OrderSource, BaseBasket and StoredBasket now have the price
unit (=currency+taxfullness) stored in them to avoid mixing units after
a basket load.

Calculation of taxes is made more explicit in OrderSource API.

Made OrderLine, SourceLine and PriceInfo to use unified API for price
fields (named Priceful). This should help when implementing template
helpers for rendering prices taxful/taxless depending on
user's/merchant's preference (Shop's taxfullness could differ from
rendering taxfullnes as long as TaxModule may calculate taxes
efficiently, which of course is not always true though.)

There is some small fixes and refactorings included here and there for
some things I found out while implementing this. Hope you don't mind.

TODO:

  • Assigning customers to correct tax groups on creation (retail
    customers and company customers)
  • Implementing value-added taxes correctly (i.e. not just selecting the
    first tax, but actually adding them together)
  • The taxful/taxless price rendering stuff as said above.
  • Cleaning up the TODOs
  • Documentation of the whole system (for developers and for merchants)

Good luck reviewing! Have fun!

suutari-ai and others added 10 commits October 1, 2015 05:10
Test not fixed yet though; marked with xfail.
This is unused.

Refs SHOOP-975
These would need a price unit (i.e. currency and taxfulness info) to be
useful.  Since they are not limited to single Shop, they can't easily
just inherit the unit from a Shop.

Until we have decided how to handle price units that are not bound to
a shop, we're better without them.

Refs SHOOP-975
Make untaxed mandatory and use its currency for type checking the sums.

Remove skipping of line taxes without amount, since their base amount
should still be taken into account.

Add a docstring.

Refs SHOOP-975
@anders-jenkins
Copy link

Refer to this link for build results (access rights to CI server needed):
http://spartacus.aintra:8080//job/shoop-ng-pull-requests/1196/
Test FAILed.

@anders-jenkins
Copy link

Refer to this link for build results (access rights to CI server needed):
http://spartacus.aintra:8080//job/shoop-ng-pull-requests/1197/
Test PASSed.



class CurrencyBound(object):
def __init__(self, currency=None, *args, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

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

Docstring? What's the use for this class?

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'll add..

@akx
Copy link
Contributor

akx commented Oct 1, 2015

Aside from the few nits I found to pick, this looks like good stuff.

I know you're diligent enough to have tested the logic thoroughly, so I didn't start to build a "mental map" of it right now -- especially with a diff this huge.

@Pikkupomo
Copy link
Contributor

Issue with TaxRule

Rule 1:
Tax = 25% tax
customer_tax_group = "normal customer"
country_code_pattern = FI
postal_code_pattern=20300-20400

Rule 2:
Tax = 50% tax
country_code_pattern = FI
postal_code_pattern=20300-20400

Customer has Tax group = "normal customer"

In checkout confirm, you see 50% taxation in use. this surely is a bug:
image

suutari-ai and others added 21 commits October 1, 2015 15:04
Money without currency makes no sense.  Better to be explicit with this
rather than defaulting to some external setting.

Refs SHOOP-975
Just for simplicity.

Refs SHOOP-975
There is no need to require id rather than object.  Change the argument
names to `shop` and `products`, since they will accept real objects too.

Note: Passing ids is still supported.
These pragma directives are cheating.
Easier to debug than "NoneType object has no attribute x".

Refs SHOOP-975
To get nicer repr; useful in debugging test failures.

Refs SHOOP-975
Rename unit_price to base_unit_price in OrderLine, SourceLine,
BasketLine, LinePriceMixin, etc.

Refs SHOOP-975
Also move it to shoop.core.pricing.

Refs SHOOP-975
…amount

For unifying the price fields with PriceInfo.  This will be nice when
implementing template helpers for price rendering with/without taxes.

Refs SHOOP-975
Move stuff from PriceInfo to Priceful mixin and use the Priceful mixin
for PriceInfo too.

Now all three PriceInfo, OrderLine and SourceLine use the same Priceful
API for price stuff.

Write some new tests for Priceful too.

Refs SHOOP-975
These are created with makemigrations and then fine tuned manually,
because some field renames were not detected correctly.

Refs SHOOP-975
Fix the definition of is_orderable to use `(x|length > 0)` instead of
`bool(x)`, since `bool` is not available as a Jinja function.
* Allow changing Tax objects that are not in use (not in order lines).
* Allow always changing the enabled property.
* Allow always changing the translated names.
* Raise ValidationError on clean rather than ImmutabilityError on save
  so that a nice message will be displayed to user rather than "Internal
  server error".

Refs SHOOP-975
@anders-jenkins
Copy link

Refer to this link for build results (access rights to CI server needed):
http://spartacus.aintra:8080//job/shoop-ng-pull-requests/1208/
Test FAILed.

@suutari-ai
Copy link
Contributor Author

retest this please

@anders-jenkins
Copy link

Refer to this link for build results (access rights to CI server needed):
http://spartacus.aintra:8080//job/shoop-ng-pull-requests/1211/
Test PASSed.

@akx
Copy link
Contributor

akx commented Oct 1, 2015

Well, then.

akx added a commit that referenced this pull request Oct 1, 2015
Tax clean-up and refactoring (SHOOP-975)
@akx akx merged commit 2cb5a50 into shuup:master Oct 1, 2015
@suutari-ai suutari-ai deleted the tax-fix3 branch October 1, 2015 12:27
tulimaki pushed a commit to tulimaki/shuup that referenced this pull request Dec 22, 2017
Basket API: allow adding zero priced product
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

4 participants