fix the calculation and some small changes

This commit is contained in:
gitea 2025-01-15 12:54:19 +00:00
parent 03a4e6e498
commit e02ae8f010
3 changed files with 32 additions and 18 deletions

1
.gitignore vendored
View File

@ -71,6 +71,7 @@ wheels/
*.egg *.egg
*.manifest *.manifest
*.spec *.spec
inventory/management/commands/run.py
# Installer logs # Installer logs
pip-log.txt pip-log.txt

View File

@ -1853,9 +1853,11 @@ class AccountDetailView(LoginRequiredMixin, DetailView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**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['header_title'] = f'Account {account_model.code} - {account_model.name}'
context['page_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( txs_qs = account_model.transactionmodel_set.all().posted().order_by(
'journal_entry__timestamp' 'journal_entry__timestamp'
).select_related( ).select_related(
@ -1993,7 +1995,7 @@ def create_estimate(request):
{ {
"item_number": item_instance.item_number, "item_number": item_instance.item_number,
"quantity": Decimal(item.get("quantity")), "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, "unit_revenue": car_instance.finances.selling_price,
"total_amount": (car_instance.finances.total_vat) "total_amount": (car_instance.finances.total_vat)
* int(item.get("quantity")), * int(item.get("quantity")),
@ -2283,20 +2285,30 @@ def invoice_create(request, pk):
invoice.save() invoice.save()
unit_items = estimate.get_itemtxs_data()[0] unit_items = estimate.get_itemtxs_data()[0]
vat = models.VatRate.objects.filter(is_active=True).first()
total = 0
discount_amount = 0
itemtxs = [] itemtxs = []
for item in unit_items: for item in unit_items:
car = models.Car.objects.get(vin=item.item_model.name) 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( itemtxs.append(
{ {
"item_number": item.item_model.item_number, "item_number": item.item_model.item_number,
"unit_cost": car.finances.cost_price, "unit_cost": unit_cost,
"unit_revenue": car.finances.total_vat, "unit_revenue": unit_cost,
"quantity": item.ce_quantity, "quantity": item.ce_quantity,
"total_amount": Decimal(car.finances.total_vat) "total_amount": grand_total
* Decimal(item.ce_quantity),
} }
) )
invoice_itemtxs = { invoice_itemtxs = {
i.get("item_number"): { i.get("item_number"): {
"unit_cost": i.get("unit_cost"), "unit_cost": i.get("unit_cost"),
@ -2384,9 +2396,9 @@ def PaymentCreateView(request, pk=None):
vat_amount += models.Car.objects.get( vat_amount += models.Car.objects.get(
vin=x.item_model.name vin=x.item_model.name
).finances.vat_amount * Decimal(x.quantity) ).finances.vat_amount * Decimal(x.quantity)
total_amount += models.Car.objects.get( total_amount += Decimal(x.unit_cost) * Decimal(x.quantity)
vin=x.item_model.name
).finances.total_discount * Decimal(x.quantity) grand_total = total_amount - Decimal(vat_amount)
ledger = LedgerModel.objects.filter( ledger = LedgerModel.objects.filter(
name=str(invoice.pk), entity=entity name=str(invoice.pk), entity=entity
@ -2429,7 +2441,7 @@ def PaymentCreateView(request, pk=None):
TransactionModel.objects.create( TransactionModel.objects.create(
journal_entry=journal, journal_entry=journal,
account=credit_account, # Credit Accounts Receivable account=credit_account, # Credit Accounts Receivable
amount=total_amount, # Payment amount amount=grand_total, # Payment amount
tx_type="credit", tx_type="credit",
description="Payment Received", description="Payment Received",
) )

View File

@ -66,7 +66,8 @@
<th class="has-text-centered">{{ _("Unit") }}</th> <th class="has-text-centered">{{ _("Unit") }}</th>
<th class="has-text-centered">{{ _("Actions") }}</th> <th class="has-text-centered">{{ _("Actions") }}</th>
</tr> </tr>
{% for tx in transactions %}
{% for tx in account.transactionmodel_set.all %}
<tr class="has-text-centered"> <tr class="has-text-centered">
<td>{{ tx.journal_entry.je_number }}</td> <td>{{ tx.journal_entry.je_number }}</td>
<td>{{ tx.journal_entry.timestamp }}</td> <td>{{ tx.journal_entry.timestamp }}</td>
@ -85,7 +86,7 @@
</button> </button>
</div> </div>
<div class="dropdown-menu" id="dropdown-menu-{{ tx.uuid }}" role="menu"> <div class="dropdown-menu" id="dropdown-menu-{{ tx.uuid }}" role="menu">
<div class="dropdown-content"> {% comment %} <div class="dropdown-content">
{# TODO: These URLs need to be replaced with the future mode method that generates it. #} {# TODO: These URLs need to be replaced with the future mode method that generates it. #}
<a href="{% url 'django_ledger:je-detail' entity_slug=entity_slug ledger_pk=tx.journal_entry.ledger.uuid je_pk=tx.journal_entry.uuid %}" <a href="{% url 'django_ledger:je-detail' entity_slug=entity_slug ledger_pk=tx.journal_entry.ledger.uuid je_pk=tx.journal_entry.uuid %}"
class="dropdown-item has-text-success">View JE</a> class="dropdown-item has-text-success">View JE</a>
@ -96,7 +97,7 @@
<a href="{% url 'django_ledger:invoice-detail' entity_slug=entity_slug invoice_pk=tx.journal_entry.ledger.invoicemodel.uuid %}" <a href="{% url 'django_ledger:invoice-detail' entity_slug=entity_slug invoice_pk=tx.journal_entry.ledger.invoicemodel.uuid %}"
class="dropdown-item has-text-info">View Invoice</a> class="dropdown-item has-text-info">View Invoice</a>
{% endif %} {% endif %}
</div> </div> {% endcomment %}
</div> </div>
</div> </div>
</td> </td>
@ -105,8 +106,8 @@
<tr class="has-text-weight-bold"> <tr class="has-text-weight-bold">
<td></td> <td></td>
<td class="has-text-right">Total</td> <td class="has-text-right">Total</td>
<td class="has-text-centered">${{ total_credits }}</td>
<td class="has-text-centered">${{ total_debits }}</td> <td class="has-text-centered">${{ total_debits }}</td>
<td class="has-text-centered">${{ total_credits }}</td>
<td></td> <td></td>
<td></td> <td></td>
<td></td> <td></td>