[UPDT] ASSET: added notify toggle and removed owner field and added category field to edit form

This commit is contained in:
Horilla
2025-10-14 14:24:44 +05:30
parent ac3cda18f4
commit 0ad6a3f566
2 changed files with 20 additions and 3 deletions

View File

@@ -21,6 +21,7 @@ from horilla_views.generic.cbv.views import (
HorillaFormView,
HorillaNavView,
)
from horilla_views.views import HorillaDeleteConfirmationView
@method_decorator(login_required, name="dispatch")
@@ -66,14 +67,16 @@ class AssetFormView(HorillaFormView):
model = Asset
new_display_title = _("Asset Creation")
dynamic_create_fields = [("asset_lot_number_id", DynamicCreateBatchNo)]
template_name = "cbv/asset/asset_form.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
asset_category_id = self.kwargs.get("asset_category_id")
self.form.fields["asset_category_id"].initial = asset_category_id
self.form.fields["asset_category_id"].widget = forms.HiddenInput()
if self.form.instance.pk:
self.form_class.verbose_name = _("Asset Update")
else:
self.form.fields["asset_category_id"].widget = forms.HiddenInput()
return context
def form_valid(self, form: AssetForm) -> HttpResponse:
@@ -256,3 +259,10 @@ class AssetCategoryNav(HorillaNavView):
""",
}
)
class AssetDeleteConfirmationView(HorillaDeleteConfirmationView):
def post(self, *args, **kwargs):
super().post(*args, **kwargs)
return HorillaFormView.HttpResponse(targets_to_reload=["#applyFilter"])

View File

@@ -48,13 +48,17 @@ class AssetForm(ModelForm):
class Meta:
model = Asset
fields = "__all__"
exclude = ["is_active"]
exclude = ["is_active", "owner"]
widgets = {
"asset_purchase_date": forms.DateInput(
attrs={"type": "date", "class": "oh-input w-100"}
),
"expiry_date": forms.DateInput(
attrs={"type": "date", "class": "oh-input w-100"}
attrs={
"type": "date",
"class": "oh-input w-100",
"onchange": "toggleNotify($(this))",
}
),
"asset_lot_number_id": forms.Select(
attrs={"onchange": "batchNoChange($(this))"}
@@ -81,6 +85,9 @@ class AssetForm(ModelForm):
super().__init__(*args, **kwargs)
if self.instance.pk is None:
self.fields["expiry_date"].initial = None
uuid_map = {
field: str(uuid.uuid4())
for field in ["asset_category_id", "asset_lot_number_id", "asset_status"]