coa acccounts add fixes

This commit is contained in:
Faheed 2025-09-07 14:53:20 +03:00
parent 094deebf58
commit 40abbdbdaf
5 changed files with 129 additions and 79 deletions

View File

@ -1129,7 +1129,6 @@ class ChartOfAccountModelCreateView(ChartOfAccountModelModelBaseViewMixIn, Creat
},
)
class ChartOfAccountModelUpdateView(ChartOfAccountModelModelBaseViewMixIn, UpdateView):
context_object_name = "coa_model"
slug_url_kwarg = "coa_slug"

View File

@ -4360,7 +4360,8 @@ class AccountListView(LoginRequiredMixin, PermissionRequiredMixin, ListView):
def get_queryset(self):
query = self.request.GET.get("q")
dealer = get_user_type(self.request)
accounts = dealer.entity.get_all_accounts()
coa = ChartOfAccountModel.objects.get(entity=dealer.entity,pk=self.kwargs["coa_pk"]) or self.request.entity.get_default_coa()
accounts = coa.get_coa_accounts()
return apply_search_filters(accounts, query)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
@ -4410,9 +4411,20 @@ class AccountCreateView(
permission_required = ["django_ledger.add_accountmodel"]
def form_valid(self, form):
dealer = get_user_type(self.request)
dealer = get_user_type(self.request)
instance = form.save(commit=False)
coa = ChartOfAccountModel.objects.get(entity=dealer.entity,pk=self.kwargs["coa_pk"]) or self.request.entity.get_default_coa()
# coa.insert_account(account_model=instance)
account = coa.entity.create_account(
coa_model=coa,
code=instance.code,
name=instance.name,
role=instance.role,
balance_type=_(instance.balance_type),
active=True,
)
form.instance.entity_model = dealer.entity
form.instance.coa_model = dealer.entity.get_default_coa()
form.instance.coa_model = coa
form.instance.depth = 0
form.instance.path = form.instance.code
return super().form_valid(form)
@ -4420,13 +4432,15 @@ class AccountCreateView(
def get_form_kwargs(self):
dealer = get_user_type(self.request)
kwargs = super().get_form_kwargs()
kwargs["coa_model"] = dealer.entity.get_default_coa()
coa = ChartOfAccountModel.objects.get(entity=dealer.entity,pk=self.kwargs["coa_pk"]) or self.request.entity.get_default_coa()
kwargs["coa_model"] = coa
return kwargs
def get_form(self, form_class=None):
form = super().get_form(form_class)
entity = get_user_type(self.request).entity
form.initial["coa_model"] = entity.get_default_coa()
coa = ChartOfAccountModel.objects.get(entity=entity,pk=self.kwargs["coa_pk"]) or self.request.entity.get_default_coa()
form.initial["coa_model"] = coa
return form
def get_success_url(self):
@ -4436,12 +4450,13 @@ class AccountCreateView(
def get_context_data(self,**kwargs):
context = super().get_context_data(**kwargs)
context["url_kwargs"] = self.kwargs
coa_pk = context["url_kwargs"]["coa_pk"]
coa_pk = context["url_kwargs"]["coa_pk"]
try:
kwargs["coa_model"] = ChartOfAccountModel.objects.get(pk=coa_pk) or self.request.entity.get_default_coa()
context["coa_model"] = ChartOfAccountModel.objects.get(entity=self.request.entity,pk=coa_pk)
except Exception:
kwargs["coa_model"] = self.request.entity.get_default_coa()
context["coa_model"] = self.request.entity.get_default_coa()
return context
class AccountDetailView(LoginRequiredMixin, PermissionRequiredMixin, DetailView):
"""
Represents the detailed view for an account with additional context data related to account
@ -4540,7 +4555,11 @@ class AccountUpdateView(
form.fields["_ref_node_id"].widget = HiddenInput()
form.fields["_position"].widget = HiddenInput()
return form
def form_valid(self, form):
form.instance.coa_model = ChartOfAccountModel.objects.get(pk=self.kwargs['coa_pk']) or self.request.entity.get_default_coa()
return super().form_valid(form)
def get_success_url(self):
return reverse_lazy(
"account_list", kwargs={"dealer_slug": self.kwargs["dealer_slug"],"coa_pk":self.kwargs["coa_pk"]}
@ -4551,9 +4570,9 @@ class AccountUpdateView(
context["url_kwargs"] = self.kwargs
coa_pk = context["url_kwargs"]["coa_pk"]
try:
kwargs["coa_model"] = ChartOfAccountModel.objects.get(pk=coa_pk) or self.request.entity.get_default_coa()
context["coa_model"] = ChartOfAccountModel.objects.get(pk=coa_pk) or self.request.entity.get_default_coa()
except Exception:
kwargs["coa_model"] = self.request.entity.get_default_coa()
context["coa_model"] = self.request.entity.get_default_coa()
return context
@login_required
@permission_required("django_ledger.delete_accountmodel")
@ -11421,7 +11440,10 @@ def staff_password_reset_view(request, dealer_slug, user_pk):
if request.method == 'POST':
form = forms.CustomSetPasswordForm(staff.user, request.POST)
if form.is_valid():
print(form.cleaned_data['new_password1'])
print(form.cleaned_data['new_password2'])
form.save()
messages.success(request, _('Your password has been set. You may go ahead and log in now.'))
return redirect('user_detail',dealer_slug=dealer_slug,slug=staff.slug)
@ -11662,12 +11684,12 @@ def ticket_update(request, ticket_id):
})
class ChartOfAccountModelListView(ChartOfAccountModelListViewBase):
template_name = 'chart_of_accounts/coa_list.html'
permission_required = 'django_ledger.view_chartofaccountmodel'
# class ChartOfAccountModelListView(ChartOfAccountModelListViewBase):
# template_name = 'chart_of_accounts/coa_list.html'
# permission_required = 'django_ledger.view_chartofaccountmodel'
class ChartOfAccountModelCreateView(ChartOfAccountModelCreateViewBase):
template_name = 'chart_of_accounts/coa_create.html'
permission_required = 'django_ledger.add_chartofaccountmodel'
permission_required = 'django_ledger.add_chartofaccountmodel'
class ChartOfAccountModelListView(ChartOfAccountModelListViewBase):
template_name = 'chart_of_accounts/coa_list.html'
permission_required = 'django_ledger.view_chartofaccountmodel'

View File

@ -12,7 +12,7 @@
<div class="card-header bg-gradient py-4 border-0 rounded-top-4">
<h3 class="mb-0 fs-4 fw-bold text-center">
{% trans 'Create Chart of Accounts' %}
<i class="fa-solid fa-chart-pie ms-2"></i>
<i class="fa-solid fa-chart-pie ms-2"></i>
</h3>
</div>
<div class="card-body p-4 p-md-5">

View File

@ -20,7 +20,7 @@
{% else %}
{% trans "Add New Account" %}
<i class="fa-solid fa-book ms-2"></i>
{% endif %}
{% endif %}
</h3>
</div>
<div class="card-body p-4 p-md-5">

View File

@ -1,79 +1,108 @@
{% extends "base.html" %}
{% load i18n %}
{% block title %}
{% trans 'Order Details' %}
{% endblock %}
{% block title %}{% trans 'Order Details' %}{% endblock %}
{% block head %}
<script>
$(function () {
$('a.invoice').click(function () {
$('a.invoice-link').on('click', function (event) {
event.preventDefault();
window.open($(this).attr('href'), 'plans_invoice_{{ invoice.id }}', 'width=860,resizable=1,location=0,status=0,titlebar=1');
window.open($(this).attr('href'), 'invoice_' + $(this).data('invoice-id'), 'width=860,resizable=1,location=0,status=0,titlebar=1');
});
});
</script>
{% endblock %}
{% block body %}
<h1 class="mt-4">
{% blocktrans with object.id as order_id and object.get_status_display as order_status %}Order #{{ order_id }}
(status: {{ order_status }}){% endblocktrans %}
</h1>
{# You should provide displaying django messages in this template #}
{% with object as order %}
{% include "plans/order_detail_table.html" %}
{% endwith %}
<div class="max-w-4xl mx-auto">
<div class="flex items-center justify-between mb-6">
<h1 class="text-3xl font-bold text-gray-800">
{% blocktrans with object.id as order_id %}Order #{{ order_id }}{% endblocktrans %}
</h1>
<span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium
{% if object.status == object.STATUS.COMPLETED %}bg-green-100 text-green-800{% elif object.status == object.STATUS.PENDING %}bg-yellow-100 text-yellow-800{% else %}bg-gray-100 text-gray-800{% endif %}">
<i class="fas {% if object.status == object.STATUS.COMPLETED %}fa-check-circle{% elif object.status == object.STATUS.PENDING %}fa-clock{% else %}fa-info-circle{% endif %} mr-2"></i>
{{ object.get_status_display }}
</span>
</div>
{# Order Summary Section #}
<div class="rounded-xl shadow-sm overflow-hidden mb-6">
<div class="px-6 py-4">
<h2 class="text-xl font-semibold text-gray-800 mb-4">{% trans "Order Summary" %}</h2>
{% with object as order %}
{% include "plans/order_detail_table.html" %}
{% endwith %}
</div>
</div>
{# Printable Documents Section #}
{% if object.get_all_invoices.count %}
<h2 class="mt-4">{% trans "Printable documents" %}</h2>
<ul id="order_printable_documents">
{% for invoice in object.get_all_invoices %}
<div class="rounded-xl shadow-sm overflow-hidden mb-6">
<div class="px-6 py-4">
<h2 class="text-xl font-semibold text-gray-800 mb-4">
<i class="fas fa-file-pdf text-gray-400 mr-2"></i> {% trans "Printable documents" %}
</h2>
<ul class="space-y-2">
{% for invoice in object.get_all_invoices %}
<li>
<a href="{{ invoice.get_absolute_url }}" class="invoice">{{ invoice.get_type_display }} {{ invoice }}</a>
<a href="{{ invoice.get_absolute_url }}" data-invoice-id="{{ invoice.id }}" class="invoice-link text-blue-600 hover:text-blue-800 font-medium transition-colors duration-200">
{{ invoice.get_type_display }} {{ invoice }}
</a>
</li>
{% endfor %}
</ul>
{% endif %}
<h2 class="mt-4">{% trans "Payment" %}</h2>
{% if object.completed %}
<p class="alert alert-phoenix-success mt-2">
{% blocktrans with object.completed as completed %}
Payment completed on: {{ completed }}
{% endblocktrans %}
</p>
{% else %}
{% if object.is_ready_for_payment %}
{% block payment_method %}
<p class="mt-2">
Here should go bindings to your payment. We recommend using <a href="https://github.com/cypreess/django-getpaid">django-getpaid</a> for payment processing.
Use a fake payment below to simulate paying for an order:
</div>
</div>
{% endif %}
{# Payment Section #}
<div class="rounded-xl overflow-hidden mb-6">
<div class="px-6 py-4">
<h2 class="text-xl font-semibold text-gray-800 mb-4">
<i class="fas fa-credit-card text-gray-400 mr-2"></i> {% trans "Payment" %}
</h2>
{% if object.completed %}
<div class="bg-green-50 text-green-700 px-4 py-3 rounded-lg flex items-center">
<i class="fas fa-check-circle mr-3 text-lg"></i>
<p class="text-sm font-medium">
{% blocktrans with object.completed as completed %}
Payment completed on: {{ completed|date:"F j, Y" }}
{% endblocktrans %}
</p>
<a class="btn btn-phoenix-success"
role="button"
href="{% url "fake_payments" pk=object.id %}">Pay using
FakePayments™ ;</a>
{# An example code snippet for accepting payments using django-getpaid #}
{# <form action="{% url "getpaid-new-payment" currency=object.currency %}" method="post"#}
{# class="standard_form payment_form">#}
{# {% csrf_token %}#}
{# <ul>{{ payment_form.as_ul }}</ul>#}
{# <p><label>&nbsp;</label><input type="submit"
value="{% trans "Pay the order" %}"
class="submit_button">#}
{# </p>#}
{# </form>#}
{% endblock %}
</div>
{% else %}
<p class="alert alert-phoenix-warning mt-2">
{% blocktrans %}
This order is expired. It will accept an incoming payment made earlier, but new payment cannot be
initialized. Please make a new order if necessary.
{% endblocktrans %}
</p>
{% if object.is_ready_for_payment %}
<p class="text-gray-600 mb-4">
You can use a fake payment below to simulate paying for this order.
</p>
<a class="inline-flex items-center px-6 py-3 border border-transparent text-base font-medium rounded-lg shadow-sm text-white bg-green-600 hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500 transition-colors duration-200"
role="button"
href="{% url "fake_payments" pk=object.id %}">
<i class="fas fa-money-bill-wave mr-2"></i>
Pay using FakePayments&trade;
</a>
{% else %}
<div class="bg-yellow-50 text-yellow-700 px-4 py-3 rounded-lg flex items-center">
<i class="fas fa-exclamation-triangle mr-3 text-lg"></i>
<p class="text-sm font-medium">
{% blocktrans %}
This order is expired. New payments cannot be initialized. Please make a new order if necessary.
{% endblocktrans %}
</p>
</div>
{% endif %}
{% endif %}
{% endif %}
{% if object.status == object.STATUS.NOT_VALID %}
<p class="alert alert-phoenix-danger">
{% blocktrans %}
This order could not be processed as it is not valid. Please contact with customer service.
{% endblocktrans %}
</p>
{% endif %}
{% endblock %}
{% if object.status == object.STATUS.NOT_VALID %}
<div class="bg-red-50 text-red-700 px-4 py-3 rounded-lg mt-4 flex items-center">
<i class="fas fa-times-circle mr-3 text-lg"></i>
<p class="text-sm font-medium">
{% blocktrans %}
This order could not be processed as it is not valid. Please contact customer service.
{% endblocktrans %}
</p>
</div>
{% endif %}
</div>
</div>
</div>
{% endblock %}