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

Fix default product tax rate in Dashboard 1.0 #3880

Merged
merged 2 commits into from Mar 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -25,6 +25,7 @@ All notable, unreleased changes to this project will be documented in this file.
- Add light/dark theme - #3856 by @dominik-zeglen
- Fix bug where logo-document is not renamed to logo-light - #3867 by @jxltom
- Copy addresses in checkoutCreate and draftOrderCreate mutations - #3866 by @pawelzar
- Fix default product tax rate in Dashboard 1.0 - #3880 by @pawelzar


## 2.4.0
Expand Down
3 changes: 2 additions & 1 deletion saleor/dashboard/product/forms.py
Expand Up @@ -259,7 +259,8 @@ class Meta:
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
product_type = self.instance.product_type
self.initial['tax_rate'] = product_type.tax_rate
self.initial['tax_rate'] = (
self.instance.tax_rate or product_type.tax_rate)
self.available_attributes = (
product_type.product_attributes.prefetch_related('values').all())
self.prepare_fields_for_attributes()
Expand Down
23 changes: 23 additions & 0 deletions saleor/product/migrations/0090_auto_20190328_0608.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions saleor/product/models.py
Expand Up @@ -21,7 +21,7 @@
from ..core import TaxRateType
from ..core.exceptions import InsufficientStock
from ..core.models import PublishableModel, SortableModel
from ..core.utils.taxes import DEFAULT_TAX_RATE_NAME, apply_tax_to_price
from ..core.utils.taxes import apply_tax_to_price
from ..core.utils.translations import TranslationProxy
from ..core.weight import WeightUnits, zero_weight
from ..discount.utils import calculate_discounted_price
Expand Down Expand Up @@ -77,9 +77,7 @@ class ProductType(models.Model):
name = models.CharField(max_length=128)
has_variants = models.BooleanField(default=True)
is_shipping_required = models.BooleanField(default=True)
tax_rate = models.CharField(
max_length=128, default=DEFAULT_TAX_RATE_NAME,
choices=TaxRateType.CHOICES)
tax_rate = models.CharField(max_length=128, choices=TaxRateType.CHOICES)
weight = MeasurementField(
measurement=Weight, unit_choices=WeightUnits.CHOICES,
default=zero_weight)
Expand Down Expand Up @@ -112,7 +110,7 @@ class Product(SeoModel, PublishableModel):
updated_at = models.DateTimeField(auto_now=True, null=True)
charge_taxes = models.BooleanField(default=True)
tax_rate = models.CharField(
max_length=128, default=DEFAULT_TAX_RATE_NAME, blank=True,
max_length=128, blank=True,
choices=TaxRateType.CHOICES)
weight = MeasurementField(
measurement=Weight, unit_choices=WeightUnits.CHOICES,
Expand Down
7 changes: 5 additions & 2 deletions tests/conftest.py
Expand Up @@ -20,6 +20,7 @@
from saleor.checkout import utils
from saleor.checkout.models import Cart
from saleor.checkout.utils import add_variant_to_cart
from saleor.core.utils.taxes import DEFAULT_TAX_RATE_NAME
from saleor.dashboard.menu.utils import update_menu
from saleor.dashboard.order.utils import fulfill_order_line
from saleor.discount import VoucherType
Expand Down Expand Up @@ -314,7 +315,8 @@ def permission_manage_orders():
@pytest.fixture
def product_type(color_attribute, size_attribute):
product_type = ProductType.objects.create(
name='Default Type', has_variants=True, is_shipping_required=True)
name='Default Type', has_variants=True, is_shipping_required=True,
tax_rate=DEFAULT_TAX_RATE_NAME)
product_type.product_attributes.add(color_attribute)
product_type.variant_attributes.add(size_attribute)
return product_type
Expand All @@ -335,7 +337,8 @@ def product(product_type, category):

product = Product.objects.create(
name='Test product', price=Money('10.00', 'USD'),
product_type=product_type, attributes=attributes, category=category)
product_type=product_type, attributes=attributes, category=category,
tax_rate=DEFAULT_TAX_RATE_NAME)

variant_attr = product_type.variant_attributes.first()
variant_attr_value = variant_attr.values.first()
Expand Down