38 lines
1.5 KiB
Python
38 lines
1.5 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):
|
|
# price_after_discount = get_financial_value(instance,"selling_price",vat) - get_financial_value(instance,"discount_amount",vat)
|
|
# subtotal = (
|
|
# price_after_discount +
|
|
# get_financial_value("registration_fee") +
|
|
# get_financial_value("administration_fee",vat) +
|
|
# get_financial_value("transportation_fee",vat) +
|
|
# get_financial_value("custom_card_fee",vat))
|
|
|
|
return 1000
|
|
|
|
def get_total(instance):
|
|
total = get_total_financials(instance)
|
|
total_vat = get_total_financials(instance,vat=True)
|
|
return total + total_vat |