Conditionally show decimal places for tax rates

This commit is contained in:
Raphael Michel
2019-01-21 10:53:50 +01:00
parent d482bc9de0
commit d8a57b0baa
6 changed files with 33 additions and 21 deletions

View File

@@ -330,7 +330,7 @@
{% if line.tax_rate %} {% if line.tax_rate %}
<br/> <br/>
<small> <small>
{% blocktrans trimmed with rate=line.tax_rate taxname=line.tax_rule.name|default:s_taxes %} {% blocktrans trimmed with rate=line.tax_rate|floatformat:-2 taxname=line.tax_rule.name|default:s_taxes %}
<strong>plus</strong> {{ rate }}% {{ taxname }} <strong>plus</strong> {{ rate }}% {{ taxname }}
{% endblocktrans %} {% endblocktrans %}
</small> </small>
@@ -340,7 +340,7 @@
{% if line.tax_rate and line.price %} {% if line.tax_rate and line.price %}
<br/> <br/>
<small> <small>
{% blocktrans trimmed with rate=line.tax_rate taxname=line.tax_rule.name|default:s_taxes %} {% blocktrans trimmed with rate=line.tax_rate|floatformat:-2 taxname=line.tax_rule.name|default:s_taxes %}
incl. {{ rate }}% {{ taxname }} incl. {{ rate }}% {{ taxname }}
{% endblocktrans %} {% endblocktrans %}
</small> </small>
@@ -364,7 +364,7 @@
{% if fee.tax_rate %} {% if fee.tax_rate %}
<br/> <br/>
<small> <small>
{% blocktrans trimmed with rate=fee.tax_rate taxname=fee.tax_rule.name|default:s_taxes %} {% blocktrans trimmed with rate=fee.tax_rate|floatformat:-2 taxname=fee.tax_rule.name|default:s_taxes %}
<strong>plus</strong> {{ rate }}% {{ taxname }} <strong>plus</strong> {{ rate }}% {{ taxname }}
{% endblocktrans %} {% endblocktrans %}
</small> </small>
@@ -374,7 +374,7 @@
{% if fee.tax_rate %} {% if fee.tax_rate %}
<br/> <br/>
<small> <small>
{% blocktrans trimmed with rate=fee.tax_rate taxname=fee.tax_rule.name|default:s_taxes %} {% blocktrans trimmed with rate=fee.tax_rate|floatformat:-2 taxname=fee.tax_rule.name|default:s_taxes %}
incl. {{ rate }}% {{ taxname }} incl. {{ rate }}% {{ taxname }}
{% endblocktrans %} {% endblocktrans %}
</small> </small>

View File

@@ -132,7 +132,7 @@
{% if line.tax_rate and line.total %} {% if line.tax_rate and line.total %}
<br /> <br />
<small> <small>
{% blocktrans trimmed with rate=line.tax_rate taxname=line.tax_rule.name|default:s_taxes %} {% blocktrans trimmed with rate=line.tax_rate|floatformat:-2 taxname=line.tax_rule.name|default:s_taxes %}
<strong>plus</strong> {{ rate }}% {{ taxname }} <strong>plus</strong> {{ rate }}% {{ taxname }}
{% endblocktrans %} {% endblocktrans %}
</small> </small>
@@ -142,7 +142,7 @@
{% if line.tax_rate and line.total %} {% if line.tax_rate and line.total %}
<br /> <br />
<small> <small>
{% blocktrans trimmed with rate=line.tax_rate taxname=line.tax_rule.name|default:s_taxes %} {% blocktrans trimmed with rate=line.tax_rate|floatformat:-2 taxname=line.tax_rule.name|default:s_taxes %}
incl. {{ rate }}% {{ taxname }} incl. {{ rate }}% {{ taxname }}
{% endblocktrans %} {% endblocktrans %}
</small> </small>
@@ -179,7 +179,7 @@
{% if fee.tax_rate %} {% if fee.tax_rate %}
<br /> <br />
<small> <small>
{% blocktrans trimmed with rate=fee.tax_rate taxname=fee.tax_rule.name|default:s_taxes %} {% blocktrans trimmed with rate=fee.tax_rate|floatformat:-2 taxname=fee.tax_rule.name|default:s_taxes %}
<strong>plus</strong> {{ rate }}% {{ taxname }} <strong>plus</strong> {{ rate }}% {{ taxname }}
{% endblocktrans %} {% endblocktrans %}
</small> </small>
@@ -189,7 +189,7 @@
{% if fee.tax_rate %} {% if fee.tax_rate %}
<br /> <br />
<small> <small>
{% blocktrans trimmed with rate=fee.tax_rate taxname=fee.tax_rule.name|default:s_taxes %} {% blocktrans trimmed with rate=fee.tax_rate|floatformat:-2 taxname=fee.tax_rule.name|default:s_taxes %}
incl. {{ rate }}% {{ taxname }} incl. {{ rate }}% {{ taxname }}
{% endblocktrans %} {% endblocktrans %}
</small> </small>

View File

@@ -294,11 +294,11 @@
</ins> </ins>
{% endif %} {% endif %}
{% if var.display_price.rate and var.display_price.gross and event.settings.display_net_prices %} {% if var.display_price.rate and var.display_price.gross and event.settings.display_net_prices %}
<small>{% blocktrans trimmed with rate=var.display_price.rate name=var.display_price.name %} <small>{% blocktrans trimmed with rate=var.display_price.rate|floatformat:-2 name=var.display_price.name %}
<strong>plus</strong> {{ rate }}% {{ name }} <strong>plus</strong> {{ rate }}% {{ name }}
{% endblocktrans %}</small> {% endblocktrans %}</small>
{% elif var.display_price.rate and var.display_price.gross %} {% elif var.display_price.rate and var.display_price.gross %}
<small>{% blocktrans trimmed with rate=var.display_price.rate name=var.display_price.name %} <small>{% blocktrans trimmed with rate=var.display_price.rate|floatformat:-2 name=var.display_price.name %}
incl. {{ rate }}% {{ name }} incl. {{ rate }}% {{ name }}
{% endblocktrans %}</small> {% endblocktrans %}</small>
{% endif %} {% endif %}
@@ -398,11 +398,11 @@
</ins> </ins>
{% endif %} {% endif %}
{% if item.display_price.rate and item.display_price.gross and event.settings.display_net_prices %} {% if item.display_price.rate and item.display_price.gross and event.settings.display_net_prices %}
<small>{% blocktrans trimmed with rate=item.display_price.rate name=item.display_price.name %} <small>{% blocktrans trimmed with rate=item.display_price.rate|floatformat:-2 name=item.display_price.name %}
<strong>plus</strong> {{ rate }}% {{ name }} <strong>plus</strong> {{ rate }}% {{ name }}
{% endblocktrans %}</small> {% endblocktrans %}</small>
{% elif item.display_price.rate and item.display_price.gross %} {% elif item.display_price.rate and item.display_price.gross %}
<small>{% blocktrans trimmed with rate=item.display_price.rate name=item.display_price.name %} <small>{% blocktrans trimmed with rate=item.display_price.rate|floatformat:-2 name=item.display_price.name %}
incl. {{ rate }}% {{ name }} incl. {{ rate }}% {{ name }}
{% endblocktrans %}</small> {% endblocktrans %}</small>
{% endif %} {% endif %}

View File

@@ -113,12 +113,12 @@
{{ var.display_price.gross|money:event.currency }} {{ var.display_price.gross|money:event.currency }}
{% endif %} {% endif %}
{% if var.display_price.rate and var.display_price.gross and event.settings.display_net_prices %} {% if var.display_price.rate and var.display_price.gross and event.settings.display_net_prices %}
<small>{% blocktrans trimmed with rate=var.display_price.rate name=var.display_price.name %} <small>{% blocktrans trimmed with rate=var.display_price.rate|floatformat:-2 name=var.display_price.name %}
<strong>plus</strong> {{ rate }}% taxes <strong>plus</strong> {{ rate }}% {{ name }}
{% endblocktrans %}</small> {% endblocktrans %}</small>
{% elif var.display_price.rate and var.display_price.gross %} {% elif var.display_price.rate and var.display_price.gross %}
<small>{% blocktrans trimmed with rate=var.display_price.rate name=var.display_price.name %} <small>{% blocktrans trimmed with rate=var.display_price.rate|floatformat:-2 name=var.display_price.name %}
incl. {{ rate }}% taxes incl. {{ rate }}% {{ name }}
{% endblocktrans %}</small> {% endblocktrans %}</small>
{% endif %} {% endif %}
</div> </div>
@@ -190,11 +190,11 @@
{{ item.display_price.gross|money:event.currency }} {{ item.display_price.gross|money:event.currency }}
{% endif %} {% endif %}
{% if item.display_price.rate and item.display_price.gross and event.settings.display_net_prices %} {% if item.display_price.rate and item.display_price.gross and event.settings.display_net_prices %}
<small>{% blocktrans trimmed with rate=item.display_price.rate name=item.display_price.name %} <small>{% blocktrans trimmed with rate=item.display_price.rate|floatformat:-2 name=item.display_price.name %}
<strong>plus</strong> {{ rate }}% {{ name }} <strong>plus</strong> {{ rate }}% {{ name }}
{% endblocktrans %}</small> {% endblocktrans %}</small>
{% elif item.display_price.rate and item.display_price.gross%} {% elif item.display_price.rate and item.display_price.gross%}
<small>{% blocktrans trimmed with rate=item.display_price.rate name=item.display_price.name %} <small>{% blocktrans trimmed with rate=item.display_price.rate|floatformat:-2 name=item.display_price.name %}
incl. {{ rate }}% {{ name }} incl. {{ rate }}% {{ name }}
{% endblocktrans %}</small> {% endblocktrans %}</small>
{% endif %} {% endif %}

View File

@@ -19,7 +19,19 @@ var floatformat = function (val, places) {
val = parseFloat(val); val = parseFloat(val);
} }
var parts = roundTo(val, places).toFixed(places).split("."); var parts = roundTo(val, places).toFixed(places).split(".");
if (places === 0) {
return parts[0];
}
parts[0] = parts[0].replace(new RegExp("\\B(?=(\\d{" + django.get_format("NUMBER_GROUPING") + "})+(?!\\d))", "g"), django.get_format("THOUSAND_SEPARATOR")); parts[0] = parts[0].replace(new RegExp("\\B(?=(\\d{" + django.get_format("NUMBER_GROUPING") + "})+(?!\\d))", "g"), django.get_format("THOUSAND_SEPARATOR"));
return parts[0] + django.get_format("DECIMAL_SEPARATOR") + parts[1]; return parts[0] + django.get_format("DECIMAL_SEPARATOR") + parts[1];
}; };
var autofloatformat = function (val, places) {
"use strict";
console.log(val, roundTo(val, 0))
if (val == roundTo(val, 0)) {
places = 0;
}
return floatformat(val, places);
};

View File

@@ -232,12 +232,12 @@ Vue.component('pricebox', {
taxline: function () { taxline: function () {
if (this.$root.display_net_prices) { if (this.$root.display_net_prices) {
return django.interpolate(strings.tax_plus, { return django.interpolate(strings.tax_plus, {
'rate': floatformat(this.price.rate, 2), 'rate': autofloatformat(this.price.rate, 2),
'taxname': this.price.name 'taxname': this.price.name
}, true); }, true);
} else { } else {
return django.interpolate(strings.tax_incl, { return django.interpolate(strings.tax_incl, {
'rate': floatformat(this.price.rate, 2), 'rate': autofloatformat(this.price.rate, 2),
'taxname': this.price.name 'taxname': this.price.name
}, true); }, true);
} }