From e02ae8f0108ccda22ebc3154fbb78b4880e38b98 Mon Sep 17 00:00:00 2001 From: gitea Date: Wed, 15 Jan 2025 12:54:19 +0000 Subject: [PATCH 1/4] fix the calculation and some small changes --- .gitignore | 1 + inventory/views.py | 40 ++++++++++++------- .../ledger/coa_accounts/account_detail.html | 9 +++-- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 5424089d..237f8bef 100644 --- a/.gitignore +++ b/.gitignore @@ -71,6 +71,7 @@ wheels/ *.egg *.manifest *.spec +inventory/management/commands/run.py # Installer logs pip-log.txt diff --git a/inventory/views.py b/inventory/views.py index 3cf4b970..b8b5db5b 100644 --- a/inventory/views.py +++ b/inventory/views.py @@ -1853,9 +1853,11 @@ class AccountDetailView(LoginRequiredMixin, DetailView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - account_model: AccountModel = context['object'] + account_model: AccountModel = context['object'] context['header_title'] = f'Account {account_model.code} - {account_model.name}' context['page_title'] = f'Account {account_model.code} - {account_model.name}' + context['total_debits'] = sum(x.amount for x in account_model.transactionmodel_set.filter(tx_type='debit')) + context['total_credits'] = sum(x.amount for x in account_model.transactionmodel_set.filter(tx_type='credit')) txs_qs = account_model.transactionmodel_set.all().posted().order_by( 'journal_entry__timestamp' ).select_related( @@ -1993,7 +1995,7 @@ def create_estimate(request): { "item_number": item_instance.item_number, "quantity": Decimal(item.get("quantity")), - "unit_cost": car_instance.finances.cost_price, + "unit_cost": car_instance.finances.selling_price, "unit_revenue": car_instance.finances.selling_price, "total_amount": (car_instance.finances.total_vat) * int(item.get("quantity")), @@ -2283,20 +2285,30 @@ def invoice_create(request, pk): invoice.save() unit_items = estimate.get_itemtxs_data()[0] - + vat = models.VatRate.objects.filter(is_active=True).first() + total = 0 + discount_amount = 0 + itemtxs = [] - for item in unit_items: - car = models.Car.objects.get(vin=item.item_model.name) + for item in unit_items: + car = models.Car.objects.get(vin=item.item_model.name) + + total = Decimal(car.finances.total) * Decimal(item.ce_quantity) + discount_amount = car.finances.discount_amount + + grand_total = Decimal(total) - Decimal(discount_amount) + vat_amount = round(Decimal(grand_total) * Decimal(vat.rate), 2) + grand_total += Decimal(vat_amount) + unit_cost = grand_total / Decimal(item.ce_quantity) itemtxs.append( { "item_number": item.item_model.item_number, - "unit_cost": car.finances.cost_price, - "unit_revenue": car.finances.total_vat, + "unit_cost": unit_cost, + "unit_revenue": unit_cost, "quantity": item.ce_quantity, - "total_amount": Decimal(car.finances.total_vat) - * Decimal(item.ce_quantity), + "total_amount": grand_total } - ) + ) invoice_itemtxs = { i.get("item_number"): { "unit_cost": i.get("unit_cost"), @@ -2384,9 +2396,9 @@ def PaymentCreateView(request, pk=None): vat_amount += models.Car.objects.get( vin=x.item_model.name ).finances.vat_amount * Decimal(x.quantity) - total_amount += models.Car.objects.get( - vin=x.item_model.name - ).finances.total_discount * Decimal(x.quantity) + total_amount += Decimal(x.unit_cost) * Decimal(x.quantity) + + grand_total = total_amount - Decimal(vat_amount) ledger = LedgerModel.objects.filter( name=str(invoice.pk), entity=entity @@ -2429,7 +2441,7 @@ def PaymentCreateView(request, pk=None): TransactionModel.objects.create( journal_entry=journal, account=credit_account, # Credit Accounts Receivable - amount=total_amount, # Payment amount + amount=grand_total, # Payment amount tx_type="credit", description="Payment Received", ) diff --git a/templates/ledger/coa_accounts/account_detail.html b/templates/ledger/coa_accounts/account_detail.html index 48674f76..d8164ef3 100644 --- a/templates/ledger/coa_accounts/account_detail.html +++ b/templates/ledger/coa_accounts/account_detail.html @@ -66,7 +66,8 @@ {{ _("Unit") }} {{ _("Actions") }} - {% for tx in transactions %} + + {% for tx in account.transactionmodel_set.all %} {{ tx.journal_entry.je_number }} {{ tx.journal_entry.timestamp }} @@ -85,7 +86,7 @@ @@ -105,8 +106,8 @@ Total - ${{ total_credits }} ${{ total_debits }} + ${{ total_credits }} From a956e8485f068b973863fefb3d79d6770a0206a7 Mon Sep 17 00:00:00 2001 From: gitea Date: Wed, 15 Jan 2025 13:14:31 +0000 Subject: [PATCH 2/4] some changes --- .../ledger/coa_accounts/account_detail.html | 21 ++++----- .../ledger/coa_accounts/account_list.html | 43 ------------------- 2 files changed, 9 insertions(+), 55 deletions(-) diff --git a/templates/ledger/coa_accounts/account_detail.html b/templates/ledger/coa_accounts/account_detail.html index d8164ef3..1d9f97f4 100644 --- a/templates/ledger/coa_accounts/account_detail.html +++ b/templates/ledger/coa_accounts/account_detail.html @@ -75,17 +75,14 @@ {% if tx.tx_type == 'credit' %}${{ tx.amount }}{% endif %} {{ tx.description }} {{ tx.journal_entry.entity_unit.name }} - - diff --git a/templates/ledger/coa_accounts/account_list.html b/templates/ledger/coa_accounts/account_list.html index aa2b6fe8..dc695abf 100644 --- a/templates/ledger/coa_accounts/account_list.html +++ b/templates/ledger/coa_accounts/account_list.html @@ -177,49 +177,6 @@ {% endif %} -
-
- -

{% trans "Chart of Accounts" %}

- {% trans "Add Account" %} -
-
- -
- - - - - - - - - - - - {% for account in accounts %} - - - - - - - - {% empty %} - - - - {% endfor %} - -
{% trans "Name" %}{% trans "Account Number" %}{% trans "Balance Type" %}{% trans "Active" %}{% trans "Action" %}
{{ account.name }}{{ account.code }}{{ account.balance_type|capfirst }}{{ account.active }} - - {% trans "Update" %} - -
{% trans "No Invoice Found" %}
-
-
-
{% endblock %} \ No newline at end of file From 78ffb137038401270aab1edf7e20e2ca4cb80005 Mon Sep 17 00:00:00 2001 From: gitea Date: Wed, 15 Jan 2025 13:15:17 +0000 Subject: [PATCH 3/4] some changes --- .../ledger/coa_accounts/account_detail.html | 231 +++++++++--------- 1 file changed, 109 insertions(+), 122 deletions(-) diff --git a/templates/ledger/coa_accounts/account_detail.html b/templates/ledger/coa_accounts/account_detail.html index 1d9f97f4..07798133 100644 --- a/templates/ledger/coa_accounts/account_detail.html +++ b/templates/ledger/coa_accounts/account_detail.html @@ -1,135 +1,122 @@ -{% extends "base.html" %} +{% extends 'base.html' %} {% load i18n %} -{% block title %}{{ page_title }}{% endblock title %} +{% block title %} + {{ page_title }} +{% endblock %} {% block content %} - -