exclude discount from total price

This commit is contained in:
Arvind Tiwari 2018-05-07 06:11:44 +05:30
commit 2ff8c25034
5 changed files with 27 additions and 25 deletions

View file

@ -36,22 +36,27 @@ class VMPricing(models.Model):
)
discount_name = models.CharField(max_length=255, null=True, blank=True)
discount_amount = models.DecimalField(
max_digits=4, decimal_places=2, default=0
max_digits=6, decimal_places=2, default=0
)
def __str__(self):
return self.name + ' => ' + ' - '.join([
display_str = self.name + ' => ' + ' - '.join([
'{}/Core'.format(self.cores_unit_price.normalize()),
'{}/GB RAM'.format(self.ram_unit_price.normalize()),
'{}/GB SSD'.format(self.ssd_unit_price.normalize()),
'{}/GB HDD'.format(self.hdd_unit_price.normalize()),
'{}% VAT'.format(self.vat_percentage.normalize())
if not self.vat_inclusive else 'VAT-Incl',
'{} {}'.format(
self.discount_amount if self.discount_amount else '',
self.discount_name if self.discount_name else 'Discount'
),
])
if self.discount_amount:
display_str = ' - '.join([
display_str,
'{} {}'.format(
self.discount_amount,
self.discount_name if self.discount_name else 'Discount'
)
])
return display_str
@classmethod
def get_vm_pricing_by_name(cls, name):

View file

@ -76,7 +76,7 @@
<span class="pull-right">{{vm.vat|floatformat:2|intcomma}} CHF</span>
</p>
{% endif %}
{% if vm_pricing.discount_amount %}
{% if vm.discount > 0 %}
<p class="text-primary">
{%trans "Discount" as discount_name %}
<span>{{ vm_pricing.discount_name|default:discount_name }}: </span>

View file

@ -158,7 +158,7 @@ class IndexView(CreateView):
)
return HttpResponseRedirect(referer_url + "#order_form")
price, vat, vat_percent = get_vm_price_with_vat(
price, vat, vat_percent, discount = get_vm_price_with_vat(
cpu=cores,
memory=memory,
ssd_size=storage,
@ -171,7 +171,8 @@ class IndexView(CreateView):
'price': price,
'vat': vat,
'vat_percent': vat_percent,
'total_price': price + vat,
'discount': discount,
'total_price': price + vat - discount,
'pricing_name': vm_pricing_name
}
request.session['specs'] = specs
@ -388,9 +389,6 @@ class OrderConfirmationView(DetailView):
request.session.get('billing_address_data')
),
'cms_integration': get_cms_integration('default'),
'vm_pricing': VMPricing.get_vm_pricing_by_name(
self.request.session['specs']['pricing_name']
),
}
return render(request, self.template_name, context)