34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
|
|
from decimal import Decimal
|
|
from django.conf import settings
|
|
from inventory import models
|
|
|
|
def calculate_vat(value):
|
|
"""Helper to calculate VAT dynamically for a given value."""
|
|
vat_rate = getattr(settings, 'VAT_RATE', Decimal('0.15')) # Default VAT rate
|
|
return (value * vat_rate).quantize(Decimal('0.01'))
|
|
# def get_financial_value(instance,attribute,vat=False):
|
|
# if vat:
|
|
# return calculate_vat(getattr(instance, attribute, Decimal('0.00')) if instance else Decimal('0.00'))
|
|
# return getattr(instance, attribute, Decimal('0.00')) if instance else Decimal('0.00')
|
|
|
|
def get_financial_value(name,vat=False):
|
|
val = models.AdditionalServices.objects.filter(name=name).first()
|
|
if not val:
|
|
return 0
|
|
if vat:
|
|
return (val.price * settings.VAT_RATE).quantize(Decimal('0.01'))
|
|
return val.price
|
|
|
|
|
|
def get_total_financials(instance,vat=False):
|
|
total = 0
|
|
if instance.additional_services.count() != 0:
|
|
total = sum(x.price for x in instance.additional_services) + instance.selling_price
|
|
if vat:
|
|
total = (total * settings.VAT_RATE).quantize(Decimal('0.01')) + total
|
|
return total
|
|
|
|
def get_total(instance):
|
|
total = get_total_financials(instance,vat=True)
|
|
return total |