bill queryset resolved

This commit is contained in:
Faheedkhan 2025-09-02 16:29:18 +03:00
parent a079ceec6d
commit ee8d8cf287
3 changed files with 11 additions and 16 deletions

View File

@ -494,8 +494,13 @@ def po_item_formset_table(context, po_model, itemtxs_formset, user):
@register.inclusion_tag("bill/tags/bill_item_formset.html", takes_context=True) @register.inclusion_tag("bill/tags/bill_item_formset.html", takes_context=True)
def bill_item_formset_table(context, item_formset): def bill_item_formset_table(context, item_formset):
bill = BillModel.objects.get(uuid=context["view"].kwargs["bill_pk"]) bill = BillModel.objects.get(uuid=context["view"].kwargs["bill_pk"])
for form in item_formset.forms:
form.fields["item_model"].queryset = form.fields["item_model"].queryset.exclude(
item_role="product"
)
for item in item_formset: for item in item_formset:
if item: if item:
print(item.fields["item_model"])
item.initial["quantity"] = item.instance.po_quantity item.initial["quantity"] = item.instance.po_quantity
item.initial["unit_cost"] = item.instance.po_unit_cost item.initial["unit_cost"] = item.instance.po_unit_cost
# print(item.instance.po_quantity) # print(item.instance.po_quantity)

View File

@ -2,19 +2,9 @@
{% load static %} {% load static %}
{% load django_ledger %} {% load django_ledger %}
{% load widget_tweaks %} {% load widget_tweaks %}
{% if bill.get_itemtxs_data.1.total_amount__sum > 0 %}
<form id="bill-update-form" <form id="bill-update-form"
action="{% url 'bill-update-items' dealer_slug=dealer_slug entity_slug=entity_slug bill_pk=bill_pk %}" action="{% url 'bill-update-items' dealer_slug=dealer_slug entity_slug=entity_slug bill_pk=bill_pk %}"
method="post"> method="post">
{% else %}
<form id="bill-update-form"
hx-trigger="load delay:300ms"
hx-swap="outerHTML"
hx-target="#bill-update-form"
hx-select="#bill-update-form"
hx-post="{% url 'bill-update-items' dealer_slug=dealer_slug entity_slug=entity_slug bill_pk=bill_pk %}"
method="post">
{% endif %}
<div class="container-fluid py-4"> <div class="container-fluid py-4">
<!-- Page Header --> <!-- Page Header -->
<div class="row mb-4"> <div class="row mb-4">
@ -125,13 +115,13 @@
<div class="row mt-4"> <div class="row mt-4">
<div class="col-12"> <div class="col-12">
<div class="d-flex justify-content-start gap-2"> <div class="d-flex justify-content-start gap-2">
{% if not item_formset.has_po %} {% comment %} {% if not item_formset.has_po %}
<a href="{% url 'django_ledger:product-create' entity_slug=entity_slug %}" <a href="{% url 'django_ledger:product-create' entity_slug=entity_slug %}"
class="btn btn-phoenix-primary"> class="btn btn-phoenix-primary">
<i class="fas fa-plus me-1"></i> <i class="fas fa-plus me-1"></i>
{% trans 'New Item' %} {% trans 'New Item' %}
</a> </a>
{% endif %} {% endif %} {% endcomment %}
<button type="submit" class="btn btn-phoenix-primary"> <button type="submit" class="btn btn-phoenix-primary">
<i class="fas fa-save me-1"></i> <i class="fas fa-save me-1"></i>
{% trans 'Save Changes' %} {% trans 'Save Changes' %}

View File

@ -50,15 +50,15 @@
{% trans 'Filters' %} <i class="fas fa-sliders-h ms-2"></i> {% trans 'Filters' %} <i class="fas fa-sliders-h ms-2"></i>
</h2> </h2>
<form method="GET" class="row g-3 align-items-end"> <form method="GET" class="row g-3 align-items-end">
<div class="col-md-3"> <div class="col-md-4">
<label for="start_date" class="form-label">{% trans 'Start Date' %}</label> <label for="start_date" class="form-label">{% trans 'Start Date' %}</label>
<input type="date" class="form-control" id="start_date" name="start_date" value="{{ start_date|default_if_none:'' }}"> <input type="date" class="form-control" id="start_date" name="start_date" value="{{ start_date|default_if_none:'' }}">
</div> </div>
<div class="col-md-3"> <div class="col-md-4">
<label for="end_date" class="form-label">{% trans 'End Date' %}</label> <label for="end_date" class="form-label">{% trans 'End Date' %}</label>
<input type="date" class="form-control" id="end_date" name="end_date" value="{{ end_date|default_if_none:'' }}"> <input type="date" class="form-control" id="end_date" name="end_date" value="{{ end_date|default_if_none:'' }}">
</div> </div>
<div class="col-md-2"> <div class="col-md-4">
<button type="submit" class="btn btn-primary w-100"> <button type="submit" class="btn btn-primary w-100">
<i class="fas fa-filter me-2"></i>{% trans 'Filter' %} <i class="fas fa-filter me-2"></i>{% trans 'Filter' %}
</button> </button>