update bill
This commit is contained in:
parent
8ede7e815d
commit
11d801f488
@ -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)
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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."))
|
||||
|
||||
@ -217,13 +217,13 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for item in car_and_item_info %}
|
||||
{% for transaction in transactions %}
|
||||
<tr>
|
||||
<td class="">{{forloop.counter}}</td>
|
||||
<td class="">{{item.car.id_car_model}}</td>
|
||||
<td class="align-middle">{{item.itemmodel.quantity}}</td>
|
||||
<td class="align-middle ps-5">{{item.car.finances.cost_price}}</td>
|
||||
<td class="align-middle text-body-tertiary fw-semibold">{{item.total}}</td>
|
||||
<td class=""></td>
|
||||
<td class="">{{transaction.item.item_model.name}}</td>
|
||||
<td class="align-middle">{{transaction.item.quantity}}</td>
|
||||
<td class="align-middle ps-5">{{transaction.item.unit_cost}}</td>
|
||||
<td class="align-middle text-body-tertiary fw-semibold">{{transaction.total}}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
<tr class="bg-body-secondary total-sum">
|
||||
@ -235,7 +235,7 @@
|
||||
<tr class="bg-body-secondary total-sum">
|
||||
<td class="align-middle ps-4 fw-bolder text-body-highlight" colspan="4">{% trans "Grand Total" %}</td>
|
||||
<td class="align-middle text-start fw-bolder">
|
||||
<span id="grand-total">{{bill.additional_info.car_finance.total_vat}}</span>
|
||||
<span id="grand-total">{{grand_total}}</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
<!-- <section> begin ============================-->
|
||||
<section class="pt-5 pb-9 bg-body-emphasis dark__bg-gray-1200 border-top">
|
||||
<div class="row-small mt-3">
|
||||
<div class="d-flex justify-content-between align-items-end mb-4">
|
||||
<div class="d-flex justify-content-between align-items-end mb-4 mx-3">
|
||||
<h2 class="mb-0">{% trans 'Estimate' %}</h2>
|
||||
<div class="d-flex align-items-center gap-2">
|
||||
{% if estimate.status == 'draft' %}
|
||||
@ -46,7 +46,7 @@
|
||||
<a href="{% url 'invoice_create' estimate.pk %}" class="btn btn-phoenix-primary"><span class="d-none d-sm-inline-block">{% trans 'Create Invoice' %}</span></a>
|
||||
{% else %}
|
||||
<a href="{% url 'create_sale_order' estimate.pk %}" class="btn btn-phoenix-primary"><span class="d-none d-sm-inline-block">{% trans 'Create Sale Order' %}</span></a>
|
||||
<a href="{% url 'preview_sale_order' estimate.pk %}" class="btn btn-phoenix-primary"><span class="d-none d-sm-inline-block">{% trans 'Preview Sale Order' %}</span></a>
|
||||
{% comment %} <a href="{% url 'preview_sale_order' estimate.pk %}" class="btn btn-phoenix-primary"><span class="d-none d-sm-inline-block">{% trans 'Preview Sale Order' %}</span></a> {% endcomment %}
|
||||
{% endif %}
|
||||
{% elif estimate.status == 'in_review' %}
|
||||
<a href="{% url 'estimate_preview' estimate.pk %}" class="btn btn-phoenix-primary"><span class="d-none d-sm-inline-block">{% trans 'Preview' %}</span></a>
|
||||
@ -83,7 +83,7 @@
|
||||
<div class="row align-items-center g-0">
|
||||
<div class="col-auto col-lg-6 col-xl-5">
|
||||
<h6 class="mb-2 me-3">{% trans 'Customer' %} :</h6>
|
||||
<p class="fs-9 text-body-secondary fw-semibold mb-0">{{estimate.customer.customer_name}}</p>
|
||||
<p class="fs-9 text-body-secondary fw-semibold mb-0">{{estimate.customer.customer_name}}</p>
|
||||
</div>
|
||||
<div class="col-12 col-lg-4">
|
||||
<h6 class="mb-2"> {% trans 'Email' %} :</h6>
|
||||
@ -119,7 +119,9 @@
|
||||
<thead class="bg-body-secondary">
|
||||
<tr>
|
||||
<th scope="col" style="width: 24px;">#</th>
|
||||
<th scope="col" style="min-width: 260px;">{% trans "Item" %}</th>
|
||||
<th scope="col" style="min-width: 260px;">{% trans "Make" %}</th>
|
||||
<th scope="col" style="min-width: 260px;">{% trans "Model" %}</th>
|
||||
<th scope="col" style="min-width: 260px;">{% trans "Year" %}</th>
|
||||
<th scope="col" style="min-width: 60px;">{% trans "Quantity" %}</th>
|
||||
<th scope="col" style="min-width: 60px;">{% trans "Unit Price" %}</th>
|
||||
<th scope="col" style="min-width: 60px;">{% trans "Total" %}</th>
|
||||
@ -129,27 +131,29 @@
|
||||
<tbody>
|
||||
{% for item in data.cars %}
|
||||
<tr>
|
||||
<td class="">{{forloop.counter}}</td>
|
||||
<td class="">{{item.make}}</td>
|
||||
<td class="align-middle"></td>
|
||||
<td class="align-middle">{{item.make}}</td>
|
||||
<td class="align-middle">{{item.model}}</td>
|
||||
<td class="align-middle">{{item.year}}</td>
|
||||
<td class="align-middle">{{item.quantity}}</td>
|
||||
<td class="align-middle ps-5">{{item.unit_price}}</td>
|
||||
<td class="align-middle text-body-tertiary fw-semibold">{{item.total}}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
<tr class="bg-body-secondary total-sum">
|
||||
<td class="align-middle ps-4 fw-semibold text-body-highlight" colspan="4">{% trans "Vat" %} ({{data.vat}}%)</td>
|
||||
<td class="align-middle ps-4 fw-semibold text-body-highlight" colspan="6">{% trans "Vat" %} ({{data.vat}}%)</td>
|
||||
<td class="align-middle text-start fw-semibold">
|
||||
<span id="grand-total">+ {{data.total_vat_amount}}</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="bg-body-secondary total-sum">
|
||||
<td class="align-middle ps-4 fw-semibold text-body-highlight" colspan="4">{% trans "Discount Amount" %}</td>
|
||||
<td class="align-middle ps-4 fw-semibold text-body-highlight" colspan="6">{% trans "Discount Amount" %}</td>
|
||||
<td class="align-middle text-start text-danger fw-semibold ">
|
||||
<span id="grand-total">- {{data.total_discount}}</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="bg-body-secondary total-sum">
|
||||
<td class="align-middle ps-4 fw-semibold text-body-highlight" colspan="4">{% trans "Additional Services" %}</td>
|
||||
<td class="align-middle ps-4 fw-semibold text-body-highlight" colspan="6">{% trans "Additional Services" %}</td>
|
||||
<td class="align-middle text-start fw-semibold">
|
||||
{% for service in data.additionals %}
|
||||
<small><span class="fw-semibold">+ {{service.name}} - {{service.total}}</span></small><br>
|
||||
@ -157,7 +161,7 @@
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="bg-body-secondary total-sum">
|
||||
<td class="align-middle ps-4 fw-bolder text-body-highlight" colspan="4">{% trans "Grand Total" %}</td>
|
||||
<td class="align-middle ps-4 fw-bolder text-body-highlight" colspan="6">{% trans "Grand Total" %}</td>
|
||||
<td class="align-middle text-start fw-bolder">
|
||||
<span id="grand-total">{{data.grand_total}}</span>
|
||||
</td>
|
||||
|
||||
@ -57,7 +57,7 @@
|
||||
<!-- <section> begin ============================-->
|
||||
<section class="pt-5 pb-9">
|
||||
<div class="row-small mt-3">
|
||||
<div class="d-flex justify-content-between align-items-end mb-4">
|
||||
<div class="d-flex justify-content-between align-items-end mb-4 mx-3">
|
||||
<h2 class="mb-0">{% trans 'Invoice' %}</h2>
|
||||
<div class="d-flex align-items-center gap-2">
|
||||
{% if invoice.invoice_status == 'in_review' %}
|
||||
@ -212,46 +212,50 @@
|
||||
<thead class="bg-body-secondary">
|
||||
<tr>
|
||||
<th scope="col" style="width: 24px;">#</th>
|
||||
<th scope="col" style="min-width: 260px;">{% trans "Item" %}</th>
|
||||
<th scope="col" style="min-width: 260px;">{% trans "Make" %}</th>
|
||||
<th scope="col" style="min-width: 260px;">{% trans "Model" %}</th>
|
||||
<th scope="col" style="min-width: 260px;">{% trans "Year" %}</th>
|
||||
<th scope="col" style="min-width: 60px;">{% trans "Quantity" %}</th>
|
||||
<th scope="col" style="min-width: 60px;">{% trans "Unit Price" %}</th>
|
||||
<th scope="col" style="min-width: 60px;">{% trans "Total" %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for item in car_and_item_info %}
|
||||
{% for item in data.cars %}
|
||||
<tr>
|
||||
<td class="">{{forloop.counter}}</td>
|
||||
<td class="">{{item.info.make}}</td>
|
||||
<td class="align-middle"></td>
|
||||
<td class="align-middle">{{item.make}}</td>
|
||||
<td class="align-middle">{{item.model}}</td>
|
||||
<td class="align-middle">{{item.year}}</td>
|
||||
<td class="align-middle">{{item.quantity}}</td>
|
||||
<td class="align-middle ps-5">{{item.finances.selling_price}}</td>
|
||||
<td class="align-middle ps-5">{{item.total}}</td>
|
||||
<td class="align-middle text-body-tertiary fw-semibold">{{item.total}}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
<tr class="bg-body-secondary total-sum">
|
||||
<td class="align-middle ps-4 fw-semibold text-body-highlight" colspan="4">{% trans "Discount Amount" %}</td>
|
||||
<td class="align-middle ps-4 fw-semibold text-body-highlight" colspan="6">{% trans "Discount Amount" %}</td>
|
||||
<td class="align-middle text-start fw-semibold">
|
||||
<span id="grand-total">- {{discount_amount}}</span>
|
||||
<span id="grand-total">- {{data.total_discount}}</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="bg-body-secondary total-sum">
|
||||
<td class="align-middle ps-4 fw-semibold text-body-highlight" colspan="4">{% trans "VAT" %} ({{vat}}%)</td>
|
||||
<td class="align-middle ps-4 fw-semibold text-body-highlight" colspan="6">{% trans "VAT" %} ({{data.vat}}%)</td>
|
||||
<td class="align-middle text-start fw-semibold">
|
||||
<span id="grand-total">+ {{data.total_vat_amount}}</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="bg-body-secondary total-sum">
|
||||
<td class="align-middle ps-4 fw-semibold text-body-highlight" colspan="4">{% trans "Additional Services" %}</td>
|
||||
<td class="align-middle ps-4 fw-semibold text-body-highlight" colspan="6">{% trans "Additional Services" %}</td>
|
||||
<td class="align-middle text-start fw-bold">
|
||||
{% for service in additional_services %}
|
||||
{% for service in data.additionals %}
|
||||
<small><span class="fw-bold">+ {{service.name}} - {{service.price}}</span></small><br>
|
||||
{% endfor %}
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="bg-body-secondary total-sum">
|
||||
<td class="align-middle ps-4 fw-bolder text-body-highlight" colspan="4">{% trans "Grand Total" %}</td>
|
||||
<td class="align-middle ps-4 fw-bolder text-body-highlight" colspan="6">{% trans "Grand Total" %}</td>
|
||||
<td class="align-middle text-start fw-bolder">
|
||||
<span id="grand-total">{{total}}</span>
|
||||
<span id="grand-total">{{data.grand_total}}</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user