Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add tax_rate to product and product type

Anna Siwik4c82fbdcef54
diff --git a/saleor/product/migrations/0057_product_charge_taxes.py b/saleor/product/migrations/0057_product_charge_taxes.py
deleted file mode 100644
index f76ac94675..0000000000
--- a/saleor/product/migrations/0057_product_charge_taxes.py
+++ /dev/null
@@ -1,18 +0,0 @@
-# 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/migrations/0059_product_taxes.py b/saleor/product/migrations/0059_product_taxes.py
new file mode 100644
index 0000000000..ec187a2242
--- /dev/null
+++ b/saleor/product/migrations/0059_product_taxes.py
@@ -0,0 +1,28 @@
+# Generated by Django 2.0.3 on 2018-04-09 09:41
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('product', '0058_auto_20180329_0142'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='product',
+ name='charge_taxes',
+ field=models.BooleanField(default=True),
+ ),
+ migrations.AddField(
+ model_name='product',
+ name='tax_rate',
+ field=models.CharField(blank=True, default='standard', max_length=128),
+ ),
+ migrations.AddField(
+ model_name='producttype',
+ name='tax_rate',
+ field=models.CharField(blank=True, default='standard', max_length=128),
+ ),
+ ]
diff --git a/saleor/product/models.py b/saleor/product/models.py
index b17376665e..55c585dd1c 100644
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -69,9 +69,7 @@ class ProductType(models.Model):
variant_attributes = models.ManyToManyField(
'ProductAttribute', related_name='product_variant_types', blank=True)
is_shipping_required = models.BooleanField(default=False)
-
- # todo: replace this with proper tax rate field
- tax_rate = 'standard'
+ tax_rate = models.CharField(max_length=128, default='standard', blank=True)
class Meta:
app_label = 'product'
@@ -109,9 +107,7 @@ class Product(SeoModel):
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 field
- tax_rate = None
+ tax_rate = models.CharField(max_length=128, default='standard', blank=True)
objects = ProductQuerySet.as_manager()
diff --git a/tests/test_graphql.py b/tests/test_graphql.py
index da15a677a1..b99e50420f 100644
--- a/tests/test_graphql.py
+++ b/tests/test_graphql.py
@@ -683,6 +683,8 @@ def test_create_product(
$description: String!,
$isPublished: Boolean!,
$isFeatured: Boolean!,
+ $chargeTaxes: Boolean!,
+ $taxRate: String!,
$price: Float!,
$attributes: [AttributeValueInput]) {
productCreate(
@@ -692,6 +694,8 @@ def test_create_product(
description: $description,
isPublished: $isPublished,
isFeatured: $isFeatured,
+ chargeTaxes: $chargeTaxes,
+ taxRate: $taxRate,
price: $price,
attributes: $attributes) {
product {
@@ -701,6 +705,8 @@ def test_create_product(
description
isPublished
isFeatured
+ chargeTaxes
+ taxRate
name
price{
amount
@@ -729,6 +735,8 @@ def test_create_product(
product_name = 'test name'
product_isPublished = True
product_isFeatured = False
+ product_chargeTaxes = True
+ product_taxRate = 'standard'
product_price = 22
# Default attribute defined in product_type fixture
@@ -749,6 +757,8 @@ def test_create_product(
'description': product_description,
'isPublished': product_isPublished,
'isFeatured': product_isFeatured,
+ 'chargeTaxes': product_chargeTaxes,
+ 'taxRate': product_taxRate,
'price': product_price,
'attributes': [
{'slug': color_attr_slug, 'value': color_attr_value},
@@ -764,6 +774,8 @@ def test_create_product(
assert data['product']['description'] == product_description
assert data['product']['isFeatured'] == product_isFeatured
assert data['product']['isPublished'] == product_isPublished
+ assert data['product']['chargeTaxes'] == product_chargeTaxes
+ assert data['product']['taxRate'] == product_taxRate
assert data['product']['productType']['name'] == product_type.name
assert data['product']['category']['name'] == default_category.name
values = (
@@ -784,6 +796,8 @@ def test_update_product(
$description: String!,
$isPublished: Boolean!,
$isFeatured: Boolean!,
+ $chargeTaxes: Boolean!,
+ $taxRate: String!,
$price: Float!,
$attributes: [AttributeValueInput]) {
productUpdate(
@@ -793,6 +807,8 @@ def test_update_product(
description: $description,
isPublished: $isPublished,
isFeatured: $isFeatured,
+ chargeTaxes: $chargeTaxes,
+ taxRate: $taxRate,
price: $price,
attributes: $attributes) {
product {
@@ -802,6 +818,8 @@ def test_update_product(
description
isPublished
isFeatured
+ chargeTaxes
+ taxRate
name
price{
amount
@@ -828,6 +846,8 @@ def test_update_product(
product_name = 'updated name'
product_isPublished = True
product_isFeatured = False
+ product_chargeTaxes = True
+ product_taxRate = 'standard'
product_price = 33
variables = json.dumps({
@@ -837,6 +857,8 @@ def test_update_product(
'description': product_description,
'isPublished': product_isPublished,
'isFeatured': product_isFeatured,
+ 'chargeTaxes': product_chargeTaxes,
+ 'taxRate': product_taxRate,
'price': product_price})
response = admin_client.post(
@@ -849,6 +871,8 @@ def test_update_product(
assert data['product']['description'] == product_description
assert data['product']['isFeatured'] == product_isFeatured
assert data['product']['isPublished'] == product_isPublished
+ assert data['product']['chargeTaxes'] == product_chargeTaxes
+ assert data['product']['taxRate'] == product_taxRate
assert not data['product']['category']['name'] == default_category.name
diff --git a/tests/test_product.py b/tests/test_product.py
index 6a4054031f..e7e3c7b322 100644
--- a/tests/test_product.py
+++ b/tests/test_product.py
@@ -459,7 +459,7 @@ def test_get_price_per_item(
def test_product_get_price_per_item_variant_has_no_price(
product_type, default_category, taxes):
- product = Product.objects.create(
+ product = models.Product.objects.create(
product_type=product_type,
category=default_category,
price=Money('10.00', 'USD'))
@@ -473,7 +473,7 @@ def test_product_get_price_per_item_variant_has_no_price(
def test_product_get_price_per_item_variant_with_price(
product_type, default_category, taxes):
- product = Product.objects.create(
+ product = models.Product.objects.create(
product_type=product_type,
category=default_category,
price=Money('10.00', 'USD'))
@@ -487,7 +487,7 @@ def test_product_get_price_per_item_variant_with_price(
def test_product_get_price_range_with_variants(
product_type, default_category, taxes):
- product = Product.objects.create(
+ product = models.Product.objects.create(
product_type=product_type,
category=default_category,
price=Money('15.00', 'USD'))
@@ -506,7 +506,7 @@ def test_product_get_price_range_with_variants(
def test_product_get_price_range_no_variants(
product_type, default_category, taxes):
- product = Product.objects.create(
+ product = models.Product.objects.create(
product_type=product_type,
category=default_category,
price=Money('10.00', 'USD'))
@@ -520,7 +520,7 @@ def test_product_get_price_range_no_variants(
def test_product_get_price_per_item_do_not_charge_taxes(
product_type, default_category, taxes, sale):
- product = Product.objects.create(
+ product = models.Product.objects.create(
product_type=product_type,
category=default_category,
price=Money('10.00', 'USD'),
@@ -536,7 +536,7 @@ def test_product_get_price_per_item_do_not_charge_taxes(
def test_product_get_price_range_do_not_charge_taxes(
product_type, default_category, taxes, sale):
- product = Product.objects.create(
+ product = models.Product.objects.create(
product_type=product_type,
category=default_category,
price=Money('10.00', 'USD'),