Original price for variations (#1258)

* Original price for variations

* Documentation

* API-GET

* Fix existing tests to accomodate new attribute

* Test for variation's original_price on API
This commit is contained in:
Martin Gross
2019-04-18 16:13:49 +02:00
committed by GitHub
parent 4838835b1b
commit 2eb88840bd
9 changed files with 77 additions and 7 deletions
+2 -2
View File
@@ -19,7 +19,7 @@ class InlineItemVariationSerializer(I18nAwareModelSerializer):
class Meta:
model = ItemVariation
fields = ('id', 'value', 'active', 'description',
'position', 'default_price', 'price')
'position', 'default_price', 'price', 'original_price')
class ItemVariationSerializer(I18nAwareModelSerializer):
@@ -29,7 +29,7 @@ class ItemVariationSerializer(I18nAwareModelSerializer):
class Meta:
model = ItemVariation
fields = ('id', 'value', 'active', 'description',
'position', 'default_price', 'price')
'position', 'default_price', 'price', 'original_price')
class InlineItemBundleSerializer(serializers.ModelSerializer):
@@ -0,0 +1,23 @@
# Generated by Django 2.2 on 2019-04-18 11:49
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('pretixbase', '0116_auto_20190402_0722'),
]
operations = [
migrations.AddField(
model_name='itemvariation',
name='original_price',
field=models.DecimalField(blank=True, decimal_places=2, help_text='If set, this will be displayed next to '
'the current price to show that the '
'current price is a discounted one. '
'This is just a cosmetic setting and '
'will not actually impact pricing.',
max_digits=7, null=True, verbose_name='Original price'),
),
]
+9
View File
@@ -550,6 +550,8 @@ class ItemVariation(models.Model):
:type active: bool
:param default_price: This variation's default price
:type default_price: decimal.Decimal
:param original_price: The item's "original" price. Will not be used for any calculations, will just be shown.
:type original_price: decimal.Decimal
"""
item = models.ForeignKey(
Item,
@@ -578,6 +580,13 @@ class ItemVariation(models.Model):
null=True, blank=True,
verbose_name=_("Default price"),
)
original_price = models.DecimalField(
verbose_name=_('Original price'),
blank=True, null=True,
max_digits=7, decimal_places=2,
help_text=_('If set, this will be displayed next to the current price to show that the current price is a '
'discounted one. This is just a cosmetic setting and will not actually impact pricing.')
)
class Meta:
verbose_name = _("Product variation")
+1
View File
@@ -463,6 +463,7 @@ class ItemVariationForm(I18nModelForm):
'value',
'active',
'default_price',
'original_price',
'description',
]
@@ -45,6 +45,7 @@
{% bootstrap_form_errors form %}
{% bootstrap_field form.active layout="control" %}
{% bootstrap_field form.default_price addon_after=request.event.currency layout="control" %}
{% bootstrap_field form.original_price addon_after=request.event.currency layout="control" %}
{% bootstrap_field form.description layout="control" %}
</div>
</div>
@@ -78,6 +79,7 @@
<div class="panel-body form-horizontal">
{% bootstrap_field formset.empty_form.active layout="control" %}
{% bootstrap_field formset.empty_form.default_price addon_after=request.event.currency layout="control" %}
{% bootstrap_field formset.empty_form.original_price addon_after=request.event.currency layout="control" %}
{% bootstrap_field formset.empty_form.description layout="control" %}
</div>
</div>
@@ -270,7 +270,10 @@
{% endif %}
</div>
<div class="col-md-2 col-xs-6 price">
{% if item.original_price %}
{% if var.original_price %}
<del>{{ var.original_price|money:event.currency }}</del>
<ins>
{% elif item.original_price %}
<del>{{ item.original_price|money:event.currency }}</del>
<ins>
{% endif %}
@@ -294,7 +297,7 @@
{% else %}
{{ var.display_price.gross|money:event.currency }}
{% endif %}
{% if item.original_price %}
{% if item.original_price or var.original_price %}
</ins>
{% endif %}
{% if item.includes_mixed_tax_rate %}
+8 -2
View File
@@ -319,6 +319,7 @@ def test_item_detail_variations(token_client, organizer, event, team, item):
"active": True,
"description": None,
"position": 0,
"original_price": None
}]
res["has_variations"] = True
resp = token_client.get('/api/v1/organizers/{}/events/{}/items/{}/'.format(organizer.slug, event.slug,
@@ -941,7 +942,8 @@ TEST_VARIATIONS_RES = {
"description": None,
"position": 0,
"default_price": None,
"price": "23.00"
"price": "23.00",
"original_price": None
}
TEST_VARIATIONS_UPDATE = {
@@ -952,6 +954,7 @@ TEST_VARIATIONS_UPDATE = {
"description": None,
"position": 1,
"default_price": "20.0",
"original_price": None
}
@@ -987,6 +990,7 @@ def test_variations_create(token_client, organizer, event, item, variation):
"description": None,
"position": 1,
"default_price": None,
"original_price": "23.42",
"price": 23.0
},
format='json'
@@ -1025,6 +1029,7 @@ def test_variations_update(token_client, organizer, event, item, item3, variatio
res["id"] = variation.pk
res["price"] = "20.00"
res["default_price"] = "20.00"
res["original_price"] = "50.00"
resp = token_client.patch(
'/api/v1/organizers/{}/events/{}/items/{}/variations/{}/'.format(organizer.slug, event.slug, item.pk, variation.pk),
{
@@ -1032,7 +1037,8 @@ def test_variations_update(token_client, organizer, event, item, item3, variatio
"en": "ChildC2"
},
"position": 1,
"default_price": "20.00"
"default_price": "20.00",
"original_price": "50.00"
},
format='json'
)