forked from CGM_Public/pretix_original
Show percentage of discount in cart (Z#23176955) (#4719)
* Show percentage of discount in cart (Z#23176955) * Fix computation
This commit is contained in:
@@ -3218,6 +3218,12 @@ class CartPosition(AbstractPosition):
|
|||||||
self.tax_code = line_price.code
|
self.tax_code = line_price.code
|
||||||
self.save(update_fields=['line_price_gross', 'tax_rate'])
|
self.save(update_fields=['line_price_gross', 'tax_rate'])
|
||||||
|
|
||||||
|
@property
|
||||||
|
def discount_percentage(self):
|
||||||
|
if not self.line_price_gross:
|
||||||
|
return 0
|
||||||
|
return (self.line_price_gross - self.price) / self.line_price_gross * 100
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def addons_without_bundled(self):
|
def addons_without_bundled(self):
|
||||||
addons = [op for op in self.addons.all() if not op.is_bundled]
|
addons = [op for op in self.addons.all() if not op.is_bundled]
|
||||||
|
|||||||
@@ -268,8 +268,14 @@
|
|||||||
{% if line.discount and line.line_price_gross != line.price %}
|
{% if line.discount and line.line_price_gross != line.price %}
|
||||||
<span class="text-success discounted" data-toggle="tooltip" title="{% trans "The price of this product was reduced because of an automatic discount." %}">
|
<span class="text-success discounted" data-toggle="tooltip" title="{% trans "The price of this product was reduced because of an automatic discount." %}">
|
||||||
<br>
|
<br>
|
||||||
<span class="fa fa-percent fa-fw" aria-hidden="true"></span>
|
<span class="fa fa-star fa-fw" aria-hidden="true"></span>
|
||||||
|
{% if line.price < line.line_price_gross %}
|
||||||
|
{% blocktranslate trimmed with percent=line.discount_percentage|floatformat:0 %}
|
||||||
|
{{ percent }} % Discount
|
||||||
|
{% endblocktranslate %}
|
||||||
|
{% else %}
|
||||||
{% trans "Discounted" %}
|
{% trans "Discounted" %}
|
||||||
|
{% endif %}
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
@@ -335,8 +341,14 @@
|
|||||||
{% if line.discount and line.line_price_gross != line.price %}
|
{% if line.discount and line.line_price_gross != line.price %}
|
||||||
<span class="text-success discounted" data-toggle="tooltip" title="{% trans "The price of this product was reduced because of an automatic discount." %}">
|
<span class="text-success discounted" data-toggle="tooltip" title="{% trans "The price of this product was reduced because of an automatic discount." %}">
|
||||||
<br>
|
<br>
|
||||||
<span class="fa fa-percent fa-fw" aria-hidden="true"></span>
|
<span class="fa fa-star fa-fw" aria-hidden="true"></span>
|
||||||
|
{% if line.price < line.line_price_gross %}
|
||||||
|
{% blocktranslate trimmed with percent=line.discount_percentage|floatformat:0 %}
|
||||||
|
{{ percent }} % Discount
|
||||||
|
{% endblocktranslate %}
|
||||||
|
{% else %}
|
||||||
{% trans "Discounted" %}
|
{% trans "Discounted" %}
|
||||||
|
{% endif %}
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user