Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Set if charge taxes on product
Anna Siwik514adda104ad
diff --git a/saleor/dashboard/product/forms.py b/saleor/dashboard/product/forms.pyindex eb53ec0cc4..6a9c9d56b6 100644--- a/saleor/dashboard/product/forms.py+++ b/saleor/dashboard/product/forms.py@@ -193,7 +193,9 @@ class ProductForm(forms.ModelForm, AttributesMixin):'Featured product toggle','Feature this product on homepage'),'collections': pgettext_lazy(- 'Add to collection select', 'Collections')}+ 'Add to collection select', 'Collections'),+ 'charge_taxes': pgettext_lazy(+ 'Charge taxes on product', 'Charge taxes on this product')}category = TreeNodeChoiceField(queryset=Category.objects.all())collections = forms.ModelMultipleChoiceField(diff --git a/saleor/product/migrations/0057_product_charge_taxes.py b/saleor/product/migrations/0057_product_charge_taxes.pynew file mode 100644index 0000000000..f76ac94675--- /dev/null+++ b/saleor/product/migrations/0057_product_charge_taxes.py@@ -0,0 +1,18 @@+# Generated by Django 2.0.3 on 2018-04-09 09:41++from django.db import migrations, models+++class Migration(migrations.Migration):++ dependencies = [+ ('product', '0056_auto_20180330_0321'),+ ]++ operations = [+ migrations.AddField(+ model_name='product',+ name='charge_taxes',+ field=models.BooleanField(default=True),+ ),+ ]diff --git a/saleor/product/models.py b/saleor/product/models.pyindex 006f52d4de..b17376665e 100644--- a/saleor/product/models.py+++ b/saleor/product/models.py@@ -108,6 +108,7 @@ class Product(SeoModel):attributes = HStoreField(default={}, blank=True)updated_at = models.DateTimeField(auto_now=True, null=True)is_featured = models.BooleanField(default=False)+ charge_taxes = models.BooleanField(default=True)# todo: replace this with proper tax rate fieldtax_rate = None@@ -176,11 +177,12 @@ class Product(SeoModel):variant, discounts=discounts, taxes=taxes)for variant in self]return TaxedMoneyRange(min(prices), max(prices))+ price = calculate_discounted_price(self, self.price, discounts)+ if not self.charge_taxes:+ taxes = Nonetax_rate = self.tax_rate or self.product_type.tax_rate- discounted_price = calculate_discounted_price(- self, self.price, discounts)- taxed_price = apply_tax_to_price(taxes, tax_rate, discounted_price)- return TaxedMoneyRange(start=taxed_price, stop=taxed_price)+ price = apply_tax_to_price(taxes, tax_rate, price)+ return TaxedMoneyRange(start=price, stop=price)class ProductVariant(models.Model):@@ -220,12 +222,13 @@ class ProductVariant(models.Model):raise InsufficientStock(self)def get_price_per_item(self, discounts=None, taxes=None):- tax_rate = (- self.product.tax_rate or self.product.product_type.tax_rate)price = self.price_override or self.product.priceprice = calculate_discounted_price(self.product, price, discounts)- price = apply_tax_to_price(taxes, tax_rate, price)- return price+ if not self.product.charge_taxes:+ taxes = None+ tax_rate = (+ self.product.tax_rate or self.product.product_type.tax_rate)+ return apply_tax_to_price(taxes, tax_rate, price)def get_absolute_url(self):slug = self.product.get_slug()diff --git a/templates/dashboard/product/detail.html b/templates/dashboard/product/detail.htmlindex e1209e2b65..37deaa0347 100644--- a/templates/dashboard/product/detail.html+++ b/templates/dashboard/product/detail.html@@ -39,7 +39,13 @@<span class="card-title">{{ product }} <br> {{ product.product_type }}</span><div class="row"><div class="col s5 m6">- <p class="text-padding">{% trans "Sale price" context "Product field" %}</p>+ <p class="text-padding">+ {% if product.charge_taxes %}+ {% trans "Sale price (taxes are charged)" context "Product field" %}+ {% else %}+ {% trans "Sale price (taxes are not charged)" context "Product field" %}+ {% endif %}+ </p></div><div class="col s7 m6">{% with sale_price as price_range %}diff --git a/templates/dashboard/product/form.html b/templates/dashboard/product/form.htmlindex 085d7349d3..e3161e3332 100644--- a/templates/dashboard/product/form.html+++ b/templates/dashboard/product/form.html@@ -86,6 +86,7 @@<div class="col s12 l4"><div class="row">{{ product_form.price|materializecss }}+ {{ product_form.charge_taxes|materializecss }}</div>{% if not product.product_type.has_variants %}<div class="row">diff --git a/tests/test_product.py b/tests/test_product.pyindex d28096993a..6a4054031f 100644--- a/tests/test_product.py+++ b/tests/test_product.py@@ -516,3 +516,34 @@ def test_product_get_price_range_no_variants(expected_price = TaxedMoney(net=Money('10.00', 'USD'), gross=Money('12.30', 'USD'))assert price == TaxedMoneyRange(start=expected_price, stop=expected_price)+++def test_product_get_price_per_item_do_not_charge_taxes(+ product_type, default_category, taxes, sale):+ product = Product.objects.create(+ product_type=product_type,+ category=default_category,+ price=Money('10.00', 'USD'),+ charge_taxes=False)+ variant = product.variants.create()++ price = variant.get_price_per_item(+ taxes=taxes, discounts=Sale.objects.all())++ assert price == TaxedMoney(+ net=Money('5.00', 'USD'), gross=Money('5.00', 'USD'))+++def test_product_get_price_range_do_not_charge_taxes(+ product_type, default_category, taxes, sale):+ product = Product.objects.create(+ product_type=product_type,+ category=default_category,+ price=Money('10.00', 'USD'),+ charge_taxes=False)++ price = product.get_price_range(taxes=taxes, discounts=Sale.objects.all())++ expected_price = TaxedMoney(+ net=Money('5.00', 'USD'), gross=Money('5.00', 'USD'))+ assert price == TaxedMoneyRange(start=expected_price, stop=expected_price)