group permission

This commit is contained in:
Flatlogic Bot 2026-02-11 03:33:51 +00:00
parent 0649b20627
commit a9b274a48f
4 changed files with 78 additions and 20 deletions

View File

@ -5,14 +5,24 @@
{% block content %} {% block content %}
<div class="container-fluid px-4"> <div class="container-fluid px-4">
<div class="d-flex justify-content-between align-items-center mb-4"> <div class="d-flex flex-column flex-md-row justify-content-between align-items-md-center mb-4 gap-3">
<div> <div>
<h2 class="fw-bold mb-0">{% trans "Supplier Payments" %}</h2> <h2 class="fw-bold mb-0">{% trans "Supplier Payments" %}</h2>
<p class="text-muted small mb-0">{% trans "History of payments made to suppliers" %}</p> <p class="text-muted small mb-0">{% trans "History of payments made to suppliers" %}</p>
</div> </div>
<a href="{% url 'purchases' %}" class="btn btn-primary rounded-3 px-4 shadow-sm">
<i class="bi bi-list-ul me-2"></i>{% trans "Purchase Invoices" %} <div class="d-flex gap-2">
</a> <form method="get" class="d-flex" role="search">
<div class="input-group">
<span class="input-group-text bg-white border-end-0"><i class="bi bi-search text-muted"></i></span>
<input class="form-control border-start-0 ps-0" type="search" name="search" placeholder="{% trans 'Search...' %}" value="{{ search_query|default:'' }}" aria-label="Search">
</div>
</form>
<a href="{% url 'purchases' %}" class="btn btn-primary rounded-3 px-4 shadow-sm text-nowrap">
<i class="bi bi-plus-lg me-2"></i>{% trans "Add Payment" %}
</a>
</div>
</div> </div>
<div class="card border-0 shadow-sm rounded-4"> <div class="card border-0 shadow-sm rounded-4">

View File

@ -311,16 +311,21 @@
<tbody> <tbody>
{% regroup permissions by content_type as perm_list %} {% regroup permissions by content_type as perm_list %}
{% for g in perm_list %} {% for g in perm_list %}
<tr> <tr class="permission-row" data-module-id="{{ g.grouper.id }}">
<td class="ps-3 py-3"> <td class="ps-3 py-3">
<div class="fw-bold text-dark">{{ g.grouper.name|capfirst }}</div> <div class="form-check">
<div class="text-muted small">{{ g.grouper.app_label }}</div> <input class="form-check-input module-select-all" type="checkbox" data-target="{{ g.grouper.id }}">
<label class="form-check-label ps-1">
<div class="fw-bold text-dark">{{ g.grouper.name|capfirst }}</div>
<div class="text-muted small">{{ g.grouper.app_label }}</div>
</label>
</div>
</td> </td>
<td class="text-center"> <td class="text-center">
{% for perm in g.list %} {% for perm in g.list %}
{% if "view" in perm.codename %} {% if "view" in perm.codename %}
<div class="form-check d-inline-block"> <div class="form-check d-inline-block">
<input class="form-check-input" type="checkbox" name="permissions" value="{{ perm.id }}" id="perm_{{ perm.id }}"> <input class="form-check-input perm-check module-{{ g.grouper.id }}" type="checkbox" name="permissions" value="{{ perm.id }}" id="perm_{{ perm.id }}">
</div> </div>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
@ -329,7 +334,7 @@
{% for perm in g.list %} {% for perm in g.list %}
{% if "add" in perm.codename %} {% if "add" in perm.codename %}
<div class="form-check d-inline-block"> <div class="form-check d-inline-block">
<input class="form-check-input" type="checkbox" name="permissions" value="{{ perm.id }}" id="perm_{{ perm.id }}"> <input class="form-check-input perm-check module-{{ g.grouper.id }}" type="checkbox" name="permissions" value="{{ perm.id }}" id="perm_{{ perm.id }}">
</div> </div>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
@ -338,7 +343,7 @@
{% for perm in g.list %} {% for perm in g.list %}
{% if "change" in perm.codename %} {% if "change" in perm.codename %}
<div class="form-check d-inline-block"> <div class="form-check d-inline-block">
<input class="form-check-input" type="checkbox" name="permissions" value="{{ perm.id }}" id="perm_{{ perm.id }}"> <input class="form-check-input perm-check module-{{ g.grouper.id }}" type="checkbox" name="permissions" value="{{ perm.id }}" id="perm_{{ perm.id }}">
</div> </div>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
@ -347,7 +352,7 @@
{% for perm in g.list %} {% for perm in g.list %}
{% if "delete" in perm.codename %} {% if "delete" in perm.codename %}
<div class="form-check d-inline-block"> <div class="form-check d-inline-block">
<input class="form-check-input" type="checkbox" name="permissions" value="{{ perm.id }}" id="perm_{{ perm.id }}"> <input class="form-check-input perm-check module-{{ g.grouper.id }}" type="checkbox" name="permissions" value="{{ perm.id }}" id="perm_{{ perm.id }}">
</div> </div>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
@ -401,16 +406,21 @@
<tbody> <tbody>
{% regroup permissions by content_type as perm_list %} {% regroup permissions by content_type as perm_list %}
{% for g in perm_list %} {% for g in perm_list %}
<tr> <tr class="permission-row">
<td class="ps-3 py-3"> <td class="ps-3 py-3">
<div class="fw-bold text-dark">{{ g.grouper.name|capfirst }}</div> <div class="form-check">
<div class="text-muted small">{{ g.grouper.app_label }}</div> <input class="form-check-input module-select-all-edit" type="checkbox" data-target="{{ g.grouper.id }}">
<label class="form-check-label ps-1">
<div class="fw-bold text-dark">{{ g.grouper.name|capfirst }}</div>
<div class="text-muted small">{{ g.grouper.app_label }}</div>
</label>
</div>
</td> </td>
<td class="text-center"> <td class="text-center">
{% for perm in g.list %} {% for perm in g.list %}
{% if "view" in perm.codename %} {% if "view" in perm.codename %}
<div class="form-check d-inline-block"> <div class="form-check d-inline-block">
<input class="form-check-input edit-group-perm" type="checkbox" name="permissions" value="{{ perm.id }}" id="edit_perm_{{ perm.id }}"> <input class="form-check-input edit-group-perm module-edit-{{ g.grouper.id }}" type="checkbox" name="permissions" value="{{ perm.id }}" id="edit_perm_{{ perm.id }}">
</div> </div>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
@ -419,7 +429,7 @@
{% for perm in g.list %} {% for perm in g.list %}
{% if "add" in perm.codename %} {% if "add" in perm.codename %}
<div class="form-check d-inline-block"> <div class="form-check d-inline-block">
<input class="form-check-input edit-group-perm" type="checkbox" name="permissions" value="{{ perm.id }}" id="edit_perm_{{ perm.id }}"> <input class="form-check-input edit-group-perm module-edit-{{ g.grouper.id }}" type="checkbox" name="permissions" value="{{ perm.id }}" id="edit_perm_{{ perm.id }}">
</div> </div>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
@ -428,7 +438,7 @@
{% for perm in g.list %} {% for perm in g.list %}
{% if "change" in perm.codename %} {% if "change" in perm.codename %}
<div class="form-check d-inline-block"> <div class="form-check d-inline-block">
<input class="form-check-input edit-group-perm" type="checkbox" name="permissions" value="{{ perm.id }}" id="edit_perm_{{ perm.id }}"> <input class="form-check-input edit-group-perm module-edit-{{ g.grouper.id }}" type="checkbox" name="permissions" value="{{ perm.id }}" id="edit_perm_{{ perm.id }}">
</div> </div>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
@ -437,7 +447,7 @@
{% for perm in g.list %} {% for perm in g.list %}
{% if "delete" in perm.codename %} {% if "delete" in perm.codename %}
<div class="form-check d-inline-block"> <div class="form-check d-inline-block">
<input class="form-check-input edit-group-perm" type="checkbox" name="permissions" value="{{ perm.id }}" id="edit_perm_{{ perm.id }}"> <input class="form-check-input edit-group-perm module-edit-{{ g.grouper.id }}" type="checkbox" name="permissions" value="{{ perm.id }}" id="edit_perm_{{ perm.id }}">
</div> </div>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
@ -511,6 +521,8 @@ document.addEventListener('DOMContentLoaded', function() {
// Reset checkboxes // Reset checkboxes
document.querySelectorAll('.edit-group-perm').forEach(cb => cb.checked = false); document.querySelectorAll('.edit-group-perm').forEach(cb => cb.checked = false);
// Reset Select All checkboxes in Edit Modal
document.querySelectorAll('.module-select-all-edit').forEach(cb => cb.checked = false);
// Fetch group permissions // Fetch group permissions
fetch(`/api/group-details/${id}/`) fetch(`/api/group-details/${id}/`)
@ -525,6 +537,24 @@ document.addEventListener('DOMContentLoaded', function() {
}); });
}); });
}); });
// Handle "Select All" for Add Group Modal
document.querySelectorAll('.module-select-all').forEach(master => {
master.addEventListener('change', function() {
const moduleId = this.dataset.target;
const checkboxes = document.querySelectorAll(`.module-${moduleId}`);
checkboxes.forEach(cb => cb.checked = this.checked);
});
});
// Handle "Select All" for Edit Group Modal
document.querySelectorAll('.module-select-all-edit').forEach(master => {
master.addEventListener('change', function() {
const moduleId = this.dataset.target;
const checkboxes = document.querySelectorAll(`.module-edit-${moduleId}`);
checkboxes.forEach(cb => cb.checked = this.checked);
});
});
}); });
</script> </script>
{% endblock %} {% endblock %}

View File

@ -851,10 +851,28 @@ def delete_purchase(request, pk):
messages.success(request, _("Purchase deleted.")) messages.success(request, _("Purchase deleted."))
return redirect('purchases') return redirect('purchases')
@login_required
@login_required @login_required
def supplier_payments(request): def supplier_payments(request):
payments = PurchasePayment.objects.all().order_by('-payment_date') payments = PurchasePayment.objects.select_related('purchase', 'purchase__supplier', 'created_by').all().order_by('-payment_date')
return render(request, 'core/supplier_payments.html', {'payments': payments})
search_query = request.GET.get('search', '')
if search_query:
payments = payments.filter(
Q(purchase__invoice_number__icontains=search_query) |
Q(purchase__supplier__name__icontains=search_query) |
Q(notes__icontains=search_query) |
Q(payment_method_name__icontains=search_query)
)
paginator = Paginator(payments, 20)
page_number = request.GET.get('page')
page_obj = paginator.get_page(page_number)
return render(request, 'core/supplier_payments.html', {
'payments': page_obj,
'search_query': search_query
})
# --- Purchase Returns --- # --- Purchase Returns ---