[UPDT] ASSET: Asset update method condition check if contains asset_ids
This commit is contained in:
@@ -5,6 +5,7 @@ Asset Management Forms
|
||||
This module contains Django ModelForms for handling various aspects of asset management,
|
||||
including asset creation, allocation, return, category assignment, and batch handling.
|
||||
"""
|
||||
|
||||
from datetime import date
|
||||
import uuid
|
||||
from django import forms
|
||||
@@ -13,7 +14,15 @@ from django.core.exceptions import ValidationError
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from employee.forms import MultipleFileField
|
||||
from employee.models import Employee
|
||||
from asset.models import Asset, AssetDocuments, AssetReport, AssetRequest, AssetAssignment, AssetCategory, AssetLot
|
||||
from asset.models import (
|
||||
Asset,
|
||||
AssetDocuments,
|
||||
AssetReport,
|
||||
AssetRequest,
|
||||
AssetAssignment,
|
||||
AssetCategory,
|
||||
AssetLot,
|
||||
)
|
||||
from base.methods import reload_queryset
|
||||
from django.template.loader import render_to_string
|
||||
|
||||
@@ -100,11 +109,13 @@ class AssetForm(ModelForm):
|
||||
|
||||
def clean(self):
|
||||
instance = self.instance
|
||||
prev_instance = Asset.objects.filter(id=instance.pk).first()
|
||||
if instance.pk:
|
||||
if asset_in_use := instance.assetassignment_set.filter(
|
||||
return_status__isnull=True
|
||||
):
|
||||
raise ValidationError('Asset in use you can"t change the status')
|
||||
if self.cleaned_data.get("asset_status",None) and self.cleaned_data.get("asset_status",None) != prev_instance.asset_status:
|
||||
if asset_in_use := instance.assetassignment_set.filter(return_status__isnull=True):
|
||||
raise ValidationError(
|
||||
{"asset_status": 'Asset in use you can"t change the status'}
|
||||
)
|
||||
if (
|
||||
Asset.objects.filter(asset_tracking_id=self.data["asset_tracking_id"])
|
||||
.exclude(id=instance.pk)
|
||||
@@ -116,22 +127,32 @@ class AssetForm(ModelForm):
|
||||
|
||||
|
||||
class DocumentForm(forms.ModelForm):
|
||||
file = forms.FileField(widget = forms.TextInput(attrs={
|
||||
"name": "file",
|
||||
"type": "File",
|
||||
"class": "form-control",
|
||||
"multiple": "True",
|
||||
}))
|
||||
file = forms.FileField(
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
"name": "file",
|
||||
"type": "File",
|
||||
"class": "form-control",
|
||||
"multiple": "True",
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = AssetDocuments
|
||||
fields = ['file',]
|
||||
fields = [
|
||||
"file",
|
||||
]
|
||||
|
||||
|
||||
class AssetReportForm(ModelForm):
|
||||
|
||||
class Meta:
|
||||
model = AssetReport
|
||||
fields = ['title', 'asset_id',]
|
||||
fields = [
|
||||
"title",
|
||||
"asset_id",
|
||||
]
|
||||
|
||||
# def __init__(self, *args, **kwargs):
|
||||
# super(AssetReportForm, self).__init__(*args, **kwargs)
|
||||
@@ -146,7 +167,6 @@ class AssetReportForm(ModelForm):
|
||||
# return table_html
|
||||
|
||||
|
||||
|
||||
class AssetCategoryForm(ModelForm):
|
||||
"""
|
||||
A form for creating and updating AssetCategory instances.
|
||||
@@ -256,7 +276,7 @@ class AssetAllocationForm(ModelForm):
|
||||
self.fields["asset_id"].queryset = Asset.objects.filter(
|
||||
asset_status="Available"
|
||||
)
|
||||
|
||||
|
||||
self.fields["assign_images"] = MultipleFileField()
|
||||
self.fields["assign_images"].required = True
|
||||
|
||||
@@ -323,7 +343,7 @@ class AssetReturnForm(ModelForm):
|
||||
attrs={"class": "oh-select oh-select-2", "required": "true"},
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(AssetReturnForm, self).__init__(*args, **kwargs)
|
||||
self.fields["return_date"].initial = date.today()
|
||||
|
||||
@@ -1,28 +1,33 @@
|
||||
{% load i18n %}
|
||||
|
||||
<div class="oh-modal__dialog-header">
|
||||
<span class="oh-modal__dialog-title" id="assetModalLabel">{{asset.asset_name}}</span>
|
||||
<button class="oh-modal__close" aria-label="Close" style="top:17px" >
|
||||
<ion-icon name="close-outline"></ion-icon>
|
||||
</button>
|
||||
</div>
|
||||
<div class="oh-modal__dialog-body oh-modal__dialog-relative">
|
||||
{% if request.GET.requests_ids %}
|
||||
<div class="oh-modal__dialog oh-modal__dialog--navigation m-0 p-0">
|
||||
<button hx-get="{% url 'asset-information' previous %}?requests_ids={{requests_ids}}&asset_info=true" hx-target = "#assetInfomation" class="oh-modal__diaglog-nav oh-modal__nav-prev">
|
||||
<button hx-get="{% url 'asset-information' previous %}?requests_ids={{requests_ids}}&asset_info=true" hx-target = "#objectDetailsModalTarget" class="oh-modal__diaglog-nav oh-modal__nav-prev">
|
||||
<ion-icon name="chevron-back-outline" class="md hydrated" role="img"
|
||||
aria-label="chevron back outline"></ion-icon>
|
||||
</button>
|
||||
|
||||
<button hx-get="{% url 'asset-information' next %}?requests_ids={{requests_ids}}&asset_info=true" hx-target = "#assetInfomation" class="oh-modal__diaglog-nav oh-modal__nav-next">
|
||||
<button hx-get="{% url 'asset-information' next %}?requests_ids={{requests_ids}}&asset_info=true" hx-target = "#objectDetailsModalTarget" class="oh-modal__diaglog-nav oh-modal__nav-next">
|
||||
<ion-icon name="chevron-forward-outline" class="md hydrated" role="img"
|
||||
aria-label="chevron forward outline"></ion-icon>
|
||||
</button>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="oh-modal__section-head fw-bold">{% trans "Asset Information" %}</div>
|
||||
<div class="row">
|
||||
<div class="col-12 col-md-12 col-lg-12">
|
||||
{% comment %} <div class="col-12 col-md-12 col-lg-12">
|
||||
<div class="oh-modal__group mt-2">
|
||||
<label class="oh-timeoff-modal__stat-title">{% trans "Asset Name" %}</label>
|
||||
<label class="oh-timeoff-modal__stat-count">{{asset.asset_name}}</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div> {% endcomment %}
|
||||
{% if asset.asset_description %}
|
||||
<div class="col-12 col-md-12 col-lg-12 mt-3">
|
||||
<div class="oh-modal__group">
|
||||
<label class="oh-timeoff-modal__stat-title">{% trans "Description" %}</label>
|
||||
@@ -31,6 +36,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="col-12 col-md-12 col-lg-6 mt-3">
|
||||
<div class="oh-modal__group">
|
||||
@@ -96,7 +102,7 @@
|
||||
<div class="oh-modal__button-container text-center mt-3">
|
||||
|
||||
<div class="oh-btn-group">
|
||||
<a hx-get="{% url 'asset-update' asset_id=asset.id %}?asset_under=info&{{pg}}"
|
||||
<a hx-get="{% url 'asset-update' asset_id=asset.id %}?{{pg}}&requests_ids={{requests_ids}}"
|
||||
data-toggle="oh-modal-toggle"
|
||||
data-target="#assetUpdate"
|
||||
hx-target="#assetUpdateBody"
|
||||
@@ -110,4 +116,5 @@
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -30,11 +30,11 @@
|
||||
<div class="oh-sticky-table__tbody" id="assetPaginatorTarget">
|
||||
{% for asset in assets %}
|
||||
<div class="oh-sticky-table__tr oh-multiple-table-sort__movable"
|
||||
id="assetDelete{{asset.id}}"
|
||||
data-toggle="oh-modal-toggle"
|
||||
data-target="#assetInfoModal"
|
||||
hx-get="{% url 'asset-information' asset_id=asset.id %}?requests_ids={{requests_ids}}"
|
||||
hx-target="#assetInfomation">
|
||||
id="assetDelete{{asset.id}}"
|
||||
data-toggle="oh-modal-toggle"
|
||||
data-target="#objectDetailsModal"
|
||||
hx-get="{% url 'asset-information' asset_id=asset.id %}?requests_ids={{requests_ids}}"
|
||||
hx-target="#objectDetailsModalTarget">
|
||||
<div class="oh-sticky-table__sd">
|
||||
<div class="oh-profile oh-profile--md">
|
||||
<div class="oh-profile__avatar mr-1">
|
||||
@@ -56,10 +56,10 @@
|
||||
<a
|
||||
class="oh-btn oh-btn--light-bkg w-100"
|
||||
data-toggle="oh-modal-toggle"
|
||||
data-target="#AssetCategoryModal"
|
||||
data-target="#assetUpdate"
|
||||
hx-get="{% url 'asset-update' asset_id=asset.id %}?asset_under=asset_filter&{{pg}}"
|
||||
title="{% trans 'Update' %}"
|
||||
hx-target="#AssetModal"
|
||||
hx-target="#assetUpdateBody"
|
||||
onclick="event.stopPropagation()"
|
||||
id="oh-btn-asset-update-modal">
|
||||
<ion-icon name="create-outline" role="img" class="md hydrated" aria-label="create outline"></ion-icon>
|
||||
@@ -85,16 +85,16 @@
|
||||
{% else %}
|
||||
{% if perms.asset.change_asset %}
|
||||
<a
|
||||
class="oh-btn oh-btn--light-bkg w-100 "
|
||||
data-toggle="oh-modal-toggle"
|
||||
data-target="#AssetCategoryModal"
|
||||
hx-get="{% url 'asset-update' asset_id=asset.id %}?{{pg}}"
|
||||
title="{% trans 'Update' %}"
|
||||
hx-target="#AssetModal"
|
||||
onclick="event.stopPropagation()"
|
||||
id="oh-btn-asset-update-modal">
|
||||
<ion-icon name="create-outline" role="img" class="md hydrated" aria-label="create outline"></ion-icon>
|
||||
</a>
|
||||
class="oh-btn oh-btn--light-bkg w-100 "
|
||||
data-toggle="oh-modal-toggle"
|
||||
data-target="#assetUpdate"
|
||||
hx-get="{% url 'asset-update' asset_id=asset.id %}?{{pg}}"
|
||||
title="{% trans 'Update' %}"
|
||||
hx-target="#assetUpdateBody"
|
||||
onclick="event.stopPropagation()"
|
||||
id="oh-btn-asset-update-modal">
|
||||
<ion-icon name="create-outline" role="img" class="md hydrated" aria-label="create outline"></ion-icon>
|
||||
</a>
|
||||
<a
|
||||
class="oh-btn oh-btn--light-bkg w-100"
|
||||
data-toggle="oh-modal-toggle"
|
||||
|
||||
@@ -11,9 +11,15 @@
|
||||
</div>
|
||||
{% endfor %}
|
||||
<script>
|
||||
setTimeout(function () {
|
||||
{% if requests_ids %}
|
||||
setTimeout(function () {
|
||||
$('.oh-modal__close--custom').click()
|
||||
}, 1000);
|
||||
{% else %}
|
||||
setTimeout(function () {
|
||||
$('.oh-modal__close').click()
|
||||
}, 1000);
|
||||
{% endif %}
|
||||
</script>
|
||||
</div>
|
||||
{% endif %}
|
||||
@@ -32,37 +38,48 @@
|
||||
<!-- end of messages -->
|
||||
|
||||
<div class="oh-modal__dialog-header">
|
||||
{% if asset_under == 'asset_filter' %}
|
||||
<button
|
||||
type="button" class="oh-modal__close "
|
||||
id="asset_update_close_btn_asset_list"
|
||||
data-dismiss="oh-modal"
|
||||
aria-label="Close"
|
||||
hx-get="{%url 'asset-list' cat_id=0 %}?asset_list=asset_filter&{{pg}}"
|
||||
hx-target="#assetCategoryList">
|
||||
<ion-icon name="close-outline"></ion-icon>
|
||||
</button>
|
||||
{% elif asset_under == "info" %}
|
||||
<button class="oh-modal__close--custom" aria-label="Close" onclick="$('#assetUpdate').removeClass('oh-modal--show')">
|
||||
<ion-icon name="close-outline"></ion-icon>
|
||||
</button>
|
||||
{% if messages %}
|
||||
{% if asset_under == 'asset_filter' %}
|
||||
<button
|
||||
type="button" class="oh-modal__close"
|
||||
id="asset_update_close_btn_asset_list"
|
||||
data-dismiss="oh-modal"
|
||||
aria-label="Close"
|
||||
hx-get="{%url 'asset-list' cat_id=0 %}?asset_list=asset_filter&{{pg}}"
|
||||
hx-target="#assetCategoryList">
|
||||
<ion-icon name="close-outline"></ion-icon>
|
||||
</button>
|
||||
{% elif requests_ids %}
|
||||
<button class="oh-modal__close--custom" aria-label="Close"
|
||||
hx-get="{% url 'asset-information' asset_id=asset_form.instance.id %}?requests_ids={{requests_ids}}"
|
||||
hx-target="#objectDetailsModalTarget"
|
||||
onclick="$(this).parents().closest('.oh-modal--show').toggleClass('oh-modal--show')"
|
||||
>
|
||||
<ion-icon name="close-outline"></ion-icon>
|
||||
</button>
|
||||
{% else %}
|
||||
<button
|
||||
type="button"
|
||||
class="oh-modal__close asset_update_close_btn"
|
||||
id="asset_update_close_btn_category"
|
||||
data-dismiss="oh-modal"
|
||||
aria-label="Close"
|
||||
hx-get="{%url 'asset-list' cat_id=asset_form.instance.asset_category_id.id %}?{{pg}}"
|
||||
hx-target="#assetList{{asset_form.instance.asset_category_id.id}}">
|
||||
<ion-icon name="close-outline"></ion-icon>
|
||||
</button>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="oh-modal__close asset_update_close_btn"
|
||||
id="asset_update_close_btn_category"
|
||||
data-dismiss="oh-modal"
|
||||
aria-label="Close"
|
||||
hx-get="{%url 'asset-list' cat_id=asset_form.instance.asset_category_id.id %}?{{pg}}"
|
||||
hx-target="#assetList{{asset_form.instance.asset_category_id.id}}">
|
||||
<ion-icon name="close-outline"></ion-icon>
|
||||
</button>
|
||||
<button type="button" class="oh-modal__close--custom" data-dismiss="oh-modal" aria-label="Close"
|
||||
onclick="$(this).parents().closest('.oh-modal--show').toggleClass('oh-modal--show')"
|
||||
>
|
||||
<ion-icon name="close-outline"></ion-icon>
|
||||
</button>
|
||||
{% endif %}
|
||||
<span class="oh-modal__dialog-title " id="addEmployeeObjectiveModalLabel"> {% trans "Asset Update" %}</span>
|
||||
</div>
|
||||
<div class="oh-modal__dialog-body">
|
||||
<form hx-post="{%url 'asset-update' asset_id=asset_form.instance.id %}?{{pg}}" hx-target="#AssetModal">
|
||||
<form hx-post="{%url 'asset-update' asset_id=asset_form.instance.id %}?requests_ids={{requests_ids}}&{{pg}}" hx-target="#assetUpdateBody">
|
||||
{% if asset_under == 'asset_filter' %}
|
||||
<input type="hidden" name="asset_under" value="asset_filter">
|
||||
{%endif %}
|
||||
|
||||
@@ -169,18 +169,26 @@ def asset_update(request, asset_id):
|
||||
instance = Asset.objects.get(id=asset_id)
|
||||
asset_form = AssetForm(instance=instance)
|
||||
previous_data = request.GET.urlencode()
|
||||
context = {
|
||||
"asset_form": asset_form,
|
||||
"asset_under": asset_under,
|
||||
"pg": previous_data,
|
||||
}
|
||||
|
||||
if request.method == "POST":
|
||||
asset_form = AssetForm(request.POST, instance=instance)
|
||||
if asset_form.is_valid():
|
||||
asset_form.save()
|
||||
messages.success(request, _("Asset Updated"))
|
||||
context["asset_form"] = asset_form
|
||||
return render(request, "asset/asset_update.html", context)
|
||||
context = {
|
||||
"asset_form": asset_form,
|
||||
"asset_under": asset_under,
|
||||
"pg": previous_data,
|
||||
}
|
||||
requests_ids_json = request.GET.get("requests_ids")
|
||||
if requests_ids_json:
|
||||
requests_ids = json.loads(requests_ids_json)
|
||||
request_copy = request.GET.copy()
|
||||
request_copy.pop("requests_ids", None)
|
||||
previous_data = request_copy.urlencode()
|
||||
context["requests_ids"] = requests_ids
|
||||
context["pd"] = previous_data
|
||||
return render(request, "asset/asset_update.html", context=context)
|
||||
|
||||
|
||||
@login_required
|
||||
@@ -321,9 +329,7 @@ def asset_list(request, cat_id):
|
||||
paginator = Paginator(asset_list, 20)
|
||||
page_number = request.GET.get("page")
|
||||
page_obj = paginator.get_page(page_number)
|
||||
requests_ids = json.dumps(
|
||||
[instance.id for instance in page_obj.object_list]
|
||||
)
|
||||
requests_ids = json.dumps([instance.id for instance in page_obj.object_list])
|
||||
data_dict = parse_qs(previous_data)
|
||||
get_key_instances(Asset, data_dict)
|
||||
context = {
|
||||
@@ -333,7 +339,7 @@ def asset_list(request, cat_id):
|
||||
"asset_under": asset_under,
|
||||
"asset_count": len(assets_in_category) or None,
|
||||
"filter_dict": data_dict,
|
||||
"requests_ids":requests_ids,
|
||||
"requests_ids": requests_ids,
|
||||
}
|
||||
return render(request, "asset/asset_list.html", context)
|
||||
|
||||
@@ -913,12 +919,8 @@ def filter_pagination_asset_request_allocation(request):
|
||||
[instance.id for instance in asset_allocation_filtered.object_list]
|
||||
)
|
||||
|
||||
assets_ids = paginator_qry(
|
||||
assets_filtered.qs, request.GET.get("page")
|
||||
)
|
||||
assets_id = json.dumps(
|
||||
[instance.id for instance in assets_ids.object_list]
|
||||
)
|
||||
assets_ids = paginator_qry(assets_filtered.qs, request.GET.get("page"))
|
||||
assets_id = json.dumps([instance.id for instance in assets_ids.object_list])
|
||||
asset_paginator = Paginator(assets_filtered.qs, get_pagination())
|
||||
asset_request_paginator = Paginator(asset_request_filtered, get_pagination())
|
||||
asset_allocation_paginator = Paginator(asset_allocation_filtered, get_pagination())
|
||||
@@ -954,7 +956,7 @@ def filter_pagination_asset_request_allocation(request):
|
||||
"allocation_field": allocation_field,
|
||||
"requests_ids": requests_ids,
|
||||
"allocations_ids": allocations_ids,
|
||||
"asset_ids":assets_id,
|
||||
"asset_ids": assets_id,
|
||||
}
|
||||
|
||||
|
||||
@@ -1004,7 +1006,7 @@ def asset_request_alloaction_view_search_filter(request):
|
||||
|
||||
|
||||
@login_required
|
||||
def own_asset_individual_view(request,id):
|
||||
def own_asset_individual_view(request, id):
|
||||
"""
|
||||
This function is responsible for view the individual own asset
|
||||
|
||||
@@ -1542,7 +1544,7 @@ def asset_history(request):
|
||||
"filter_dict": data_dict,
|
||||
"gp_fields": AssetHistoryReGroup().fields,
|
||||
"pd": previous_data,
|
||||
"requests_ids":requests_ids,
|
||||
"requests_ids": requests_ids,
|
||||
}
|
||||
return render(request, "asset_history/asset_history_view.html", context)
|
||||
|
||||
@@ -1607,7 +1609,7 @@ def asset_history_search(request):
|
||||
requests_ids = json.dumps(list(id_list))
|
||||
else:
|
||||
asset_assignments = paginator_qry(asset_assignments, request.GET.get("page"))
|
||||
|
||||
|
||||
requests_ids = json.dumps(
|
||||
[instance.id for instance in asset_assignments.object_list]
|
||||
)
|
||||
@@ -1622,6 +1624,6 @@ def asset_history_search(request):
|
||||
"filter_dict": data_dict,
|
||||
"field": field,
|
||||
"pd": previous_data,
|
||||
"requests_ids":requests_ids,
|
||||
"requests_ids": requests_ids,
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user