diff --git a/inventory/apps.py b/inventory/apps.py index ad2bcf1a..dd0c6471 100644 --- a/inventory/apps.py +++ b/inventory/apps.py @@ -5,4 +5,8 @@ class InventoryConfig(AppConfig): name = 'inventory' def ready(self): - import inventory.signals + import inventory.signals + from decimal import Decimal + from inventory.models import VatRate + VatRate.objects.get_or_create(rate=Decimal('0.15'), is_active=True) + diff --git a/inventory/utils.py b/inventory/utils.py index 4d406336..70721d61 100644 --- a/inventory/utils.py +++ b/inventory/utils.py @@ -350,7 +350,7 @@ def set_bill_payment(dealer, entity, bill, amount, payment_method): account=cash_account, # Debit Cash amount=amount, # Payment amount tx_type="debit", - description="Payment Received", + description="Bill Payment Received", ) TransactionModel.objects.create( @@ -358,7 +358,7 @@ def set_bill_payment(dealer, entity, bill, amount, payment_method): account=account_payable, # Credit Accounts Receivable amount=amount, # Payment amount tx_type="credit", - description="Payment Received", + description="Bill Payment Received", ) bill.make_payment(amount) diff --git a/inventory/views.py b/inventory/views.py index 1405f3d3..34605090 100644 --- a/inventory/views.py +++ b/inventory/views.py @@ -2454,6 +2454,7 @@ class EstimateDetailView(LoginRequiredMixin, DetailView): if estimate.get_itemtxs_data(): calculator = CarFinanceCalculator(estimate) finance_data = calculator.get_finance_data() + print(finance_data.get("cars")) kwargs["data"] = finance_data kwargs["invoice"] = ( InvoiceModel.objects.all().filter(ce_model=estimate).first() @@ -2588,11 +2589,7 @@ class InvoiceDetailView(LoginRequiredMixin, DetailView): if invoice.get_itemtxs_data(): calculator = CarFinanceCalculator(invoice) - finance_data = calculator.get_finance_data() - print( - (finance_data["total_vat_amount"] + finance_data["total_price"]) - == finance_data["grand_total"] - ) + finance_data = calculator.get_finance_data() kwargs["data"] = finance_data kwargs["payments"] = JournalEntryModel.objects.filter( ledger=invoice.ledger @@ -3223,29 +3220,23 @@ class BillDetailView(LoginRequiredMixin, DetailView): if bill.get_itemtxs_data(): txs = bill.get_itemtxs_data()[0] - car_and_item_info = [ + transactions = [ { - "car": models.Car.objects.get(vin=x.item_model.name), - "total": models.Car.objects.get( - vin=x.item_model.name - ).finances.cost_price - * Decimal(x.quantity), - "itemmodel": x, + "item": x, + "total": Decimal(x.unit_cost) * Decimal(x.quantity), } for x in txs ] grand_total = sum( - Decimal( - models.Car.objects.get(vin=x.item_model.name).finances.cost_price - ) - * Decimal(x.quantity) + Decimal(x.unit_cost) * Decimal(x.quantity) for x in txs ) - vat = models.VatRate.objects.filter(is_active=True).first() - if vat: - grand_total += round(Decimal(grand_total) * Decimal(vat.rate), 2) - kwargs["car_and_item_info"] = car_and_item_info + # vat = models.VatRate.objects.filter(is_active=True).first() + # if vat: + # grand_total += round(Decimal(grand_total) * Decimal(vat.rate), 2) + kwargs["transactions"] = transactions kwargs["grand_total"] = grand_total + print(dir(txs[0])) return super().get_context_data(**kwargs) @@ -3324,7 +3315,7 @@ def bill_mark_as_paid(request, pk): bill.mark_as_paid(user_model=dealer.entity.admin) bill.save() bill.ledger.lock_journal_entries() - bill.ledger.post_journal_entries() + bill.ledger.post_journal_entries() bill.ledger.post() bill.ledger.save() messages.success(request, _("Bill marked as paid successfully.")) diff --git a/templates/ledger/bills/bill_detail.html b/templates/ledger/bills/bill_detail.html index 0cfd5f7f..22ea983e 100644 --- a/templates/ledger/bills/bill_detail.html +++ b/templates/ledger/bills/bill_detail.html @@ -217,13 +217,13 @@
- {% for item in car_and_item_info %} + {% for transaction in transactions %}{{estimate.customer.customer_name}}
+{{estimate.customer.customer_name}}