This commit is contained in:
gitea 2025-01-15 10:15:19 +00:00
parent 28e051a061
commit 3608ee53d9
6 changed files with 40 additions and 84 deletions

View File

@ -29,16 +29,16 @@ class LogUserActivityMiddleware:
return request.META.get('REMOTE_ADDR')
class InjectParamsMiddleware:
def __init__(self, get_response):
self.get_response = get_response
# class InjectParamsMiddleware:
# def __init__(self, get_response):
# self.get_response = get_response
def __call__(self, request):
try:
request.entity = request.user.dealer.entity
except Exception as e:
pass
# def __call__(self, request):
# try:
# request.entity = request.user.dealer.entity
# except Exception as e:
# pass
response = self.get_response(request)
# response = self.get_response(request)
return response
# return response

View File

@ -153,29 +153,7 @@ def create_ledger_entity(sender, instance, created, **kwargs):
name=_("Employee Advance"),
balance_type="debit",
active=True,
)
# Inventory Account
asset_ca_inventory = entity.create_account(
coa_model=coa,
code="1106",
role=roles.ASSET_CA_INVENTORY,
name=_("Inventory"),
balance_type="debit",
active=True,
)
asset_ca_inventory.role_default = True
asset_ca_inventory.save()
# VAT Payable Account
liability_ltl_vat_receivable = entity.create_account(
coa_model=coa,
code="1107",
role=roles.ASSET_CA_RECEIVABLES,
name=_("VAT Receivable"),
balance_type="debit",
active=True,
)
)
# Buildings Accumulated Depreciation Account
asset_ppe_buildings_accum_depreciation = entity.create_account(
@ -249,7 +227,6 @@ def create_ledger_entity(sender, instance, created, **kwargs):
)
asset_ppe_buildings.role_default = True
asset_ppe_buildings.save()
# Accounts Payable Account
@ -336,7 +313,7 @@ def create_ledger_entity(sender, instance, created, **kwargs):
# Mortgage Payable Account
liability_ltl_mortgage_payable = entity.create_account(
coa_model=coa,
code="2202",
code="2203",
role=roles.LIABILITY_LTL_MORTGAGE_PAYABLE,
name=_("Mortgage Payable"),
balance_type="credit",

View File

@ -2232,28 +2232,15 @@ class PaidInvoiceModelUpdateFormView(LoginRequiredMixin, UpdateView):
@login_required
def invoice_mark_as(request, pk):
invoice = get_object_or_404(InvoiceModel, pk=pk)
entity = EntityModel.objects.first() # will change later
user = entity.admin
dealer = get_user_type(request)
mark = request.GET.get("mark")
if mark:
if mark == "accept":
if not invoice.can_approve():
messages.error(request, "invoice is not ready for approval")
return redirect("invoice_detail", pk=invoice.pk)
invoice.mark_as_approved(entity_slug=entity.slug, user_model=user)
# invoice.post_ledger()
invoice.save()
ledger = (
entity.get_ledgers().filter(name=f"Invoice {str(invoice.pk)}").first()
)
if not ledger:
ledger = entity.create_ledger(name=f"Invoice {str(invoice.pk)}")
ledger.invoicemodel = invoice
ledger.save()
# elif mark == "complete":
# if not invoice.can_complete():
# messages.error(request, "invoice is not ready for completion")
if mark and mark == "accept":
if not invoice.can_approve():
messages.error(request, "invoice is not ready for approval")
return redirect("invoice_detail", pk=invoice.pk)
invoice.mark_as_approved(entity_slug=dealer.entity.slug, user_model=dealer.entity.admin)
invoice.save()
return redirect("invoice_detail", pk=invoice.pk)
def invoice_create(request, pk):
@ -2280,7 +2267,7 @@ def invoice_create(request, pk):
itemtxs.append(
{
"item_number": item.item_model.item_number,
"unit_cost": car.finances.total_vat,
"unit_cost": car.finances.cost_price,
"unit_revenue": car.finances.total_vat,
"quantity": item.ce_quantity,
"total_amount": Decimal(car.finances.total_vat)
@ -2363,9 +2350,7 @@ def PaymentCreateView(request, pk=None):
if form.is_valid():
amount = form.cleaned_data.get("amount")
invoice = form.cleaned_data.get("invoice")
payment_method = form.cleaned_data.get("payment_method")
ledger = None
payment_method = form.cleaned_data.get("payment_method")
try:
vat_amount = 0
total_amount = 0
@ -2374,10 +2359,10 @@ def PaymentCreateView(request, pk=None):
for x in invoice.get_itemtxs_data()[0].all():
vat_amount += models.Car.objects.get(
vin=x.item_model.name
).finances.vat_amount
).finances.vat_amount * Decimal(x.quantity)
total_amount += models.Car.objects.get(
vin=x.item_model.name
).finances.total_discount
).finances.total_discount * Decimal(x.quantity)
ledger = LedgerModel.objects.filter(
name=str(invoice.pk), entity=entity
@ -2436,11 +2421,13 @@ def PaymentCreateView(request, pk=None):
invoice.make_payment(amount)
invoice.save()
messages.success(request, "Payment created successfully!")
return redirect("invoice_detail", pk=invoice.pk)
except Exception as e:
messages.error(request, f"Error creating payment: {str(e)}")
else:
messages.error(request, f"Invalid form data: {str(form.errors)}")
return redirect("invoice_detail", pk=invoice.pk)
else:
messages.error(request, f"Invalid form data: {form.errors.as_text()}")
form = forms.PaymentForm()
form.initial["amount"] = invoice.amount_due

View File

@ -203,7 +203,7 @@
<li class="nav-item">
<a class="nav-link" href="{% url 'account_list' %}">
<div class="d-flex align-items-center">
<span class="nav-link-icon"><span data-feather="users"></span></span><span class="nav-link-text">{% trans 'Accounts'|capfirst %}</span>
<span class="nav-link-icon"><span data-feather="users"></span></span><span class="nav-link-text">{% trans 'Chart of Accounts'|capfirst %}</span>
</div>
</a>
</li>

View File

@ -1,13 +1,13 @@
{% extends "base.html" %}
{% load i18n static %}
{% block title %}{{ _("Accounts") }}{% endblock title %}
{% block title %}{{ _("Chart of Accounts") }}{% endblock title %}
{% block content %}
<div class="row mt-4 mx-4">
<div class="d-flex justify-content-between mb-2 p-6">
<span></span>
<h3 class="text-center">{% trans "Accounts" %}</h3>
<h3 class="text-center">{% trans "Chart of Accounts" %}</h3>
<a href="{% url 'account_create' %}" class="btn btn-sm btn-success ">{% trans "Add Account" %}</a>
</div>
<div class="mx-n4 px-4 mx-lg-n6 px-lg-6 bg-body-emphasis pt-7 border-y">

View File

@ -13,10 +13,12 @@
<thead>
<tr>
<th class="sort white-space-nowrap align-middle" scope="col">{% trans "Invoice Number" %}</th>
<th class="sort white-space-nowrap align-middle" scope="col">{% trans "Customer" %}</th>
<th class="sort white-space-nowrap align-middle" scope="col">{% trans "Customer" %}</th>
<th class="sort white-space-nowrap align-middle" scope="col">{% trans "Date" %}</th>
<th class="sort white-space-nowrap align-middle" scope="col">{% trans "Due Date" %}</th>
<th class="sort white-space-nowrap align-middle" scope="col">{% trans "Paid" %}</th>
<th class="sort white-space-nowrap align-middle" scope="col">{% trans "Due" %}</th>
<th class="sort white-space-nowrap align-middle" scope="col">{% trans "Status" %}</th>
<th class="sort white-space-nowrap align-middle" scope="col">{% trans "Status Date" %}</th>
<th class="sort white-space-nowrap align-middle" scope="col">{% trans "Created" %}</th>
<th class="sort white-space-nowrap align-middle" scope="col">{% trans "Actions" %}</th>
</tr>
</thead>
@ -25,6 +27,10 @@
<tr class="hover-actions-trigger btn-reveal-trigger position-static">
<td class="align-middle product white-space-nowrap py-0">{{ invoice.invoice_number }}</td>
<td class="align-middle product white-space-nowrap">{{ invoice.customer }}</td>
<td class="align-middle product white-space-nowrap">{{ invoice.created }}</td>
<td class="align-middle product white-space-nowrap">{{ invoice.date_due }}</td>
<td class="align-middle product white-space-nowrap">{{ invoice.amount_paid }}</td>
<td class="align-middle product white-space-nowrap">{{ invoice.amount_due }}</td>
<td class="align-middle product white-space-nowrap text-success">
{% if invoice.is_past_due %}
<span class="badge badge-phoenix badge-phoenix-danger">{% trans "Past Due" %}</span>
@ -40,20 +46,6 @@
<span class="badge badge-phoenix badge-phoenix-success">{% trans "Paid" %}</span>
{% endif %}
</td>
<td class="align-middle product white-space-nowrap">
{% if invoice.invoice_status == "in_review" %}
{{ invoice.date_in_review }}
{% elif invoice.invoice_status == "approved" %}
{{ invoice.date_approved }}
{% elif invoice.invoice_status == "canceled" %}
{{ invoice.date_canceled }}
{% elif invoice.invoice_status == "draft" %}
{{ invoice.date_draft }}
{% elif invoice.invoice_status == "paid" %}
{{ invoice.date_paid }}
{% endif %}
</td>
<td class="align-middle product white-space-nowrap">{{ invoice.created }}</td>
<td class="text-center">
<a href="{% url 'invoice_detail' invoice.pk %}"
class="btn btn-sm btn-phoenix-success">