diff --git a/asset/cbv/asset.py b/asset/cbv/asset.py new file mode 100644 index 000000000..38a6361ef --- /dev/null +++ b/asset/cbv/asset.py @@ -0,0 +1,67 @@ +from typing import Any + +from django.utils.decorators import method_decorator +from django.utils.translation import gettext_lazy as _ + +from horilla_views.cbv_methods import login_required, permission_required +from horilla_views.generic.cbv.views import HorillaDetailedView, HorillaListView + +from asset.filters import AssetFilter +from asset.models import Asset + + +@method_decorator(login_required, name="dispatch") +@method_decorator(permission_required("asset.view_assetlot"), name="dispatch") +class AssetListView(HorillaListView): + """ + list view for batch number + """ + + model = Asset + filter_class = AssetFilter + columns = ["asset_name", "asset_status", "asset_tracking_id", "asset_lot_number_id"] + show_filter_tags = False + bulk_select_option = False + action_method = "action_column" + + def get_queryset(self, queryset=None, filtered=False, *args, **kwargs): + return ( + super() + .get_queryset(queryset, filtered, *args, **kwargs) + .filter(asset_category_id=self.kwargs["cat_id"]) + ) + + row_attrs = """ + hx-get='{asset_detail}?instance_ids={ordered_ids}' + hx-target="#genericModalBody" + data-target="#genericModal" + data-toggle="oh-modal-toggle" + """ + + +class AssetInformationView(HorillaDetailedView): + """ + Detail view of the page + """ + + def get_context_data(self, **kwargs: Any): + """ + Return context data with the title set to the contract's name. + """ + + context = super().get_context_data(**kwargs) + asset_name = context["asset"].asset_name + context["title"] = asset_name + return context + + model = Asset + header = False + action_method = "detail_view_action" + body = [ + "asset_tracking_id", + "asset_purchase_date", + "asset_purchase_cost", + "asset_status", + "asset_lot_number_id", + "asset_category_id", + ] diff --git a/asset/cbv/asset_batch_no.py b/asset/cbv/asset_batch_no.py index 5450be450..7d3b2135b 100644 --- a/asset/cbv/asset_batch_no.py +++ b/asset/cbv/asset_batch_no.py @@ -40,20 +40,19 @@ class AssetBatchNoListView(HorillaListView): list view for batch number """ + model = AssetLot + filter_class = AssetBatchNoFilter + columns = [ + "lot_number", + "lot_description", + (_("Assets"), "assets_column"), + ] + def __init__(self, **kwargs: Any) -> None: super().__init__(**kwargs) self.search_url = reverse("asset-batch-list") self.view_id = "AssetBatchList" - model = AssetLot - filter_class = AssetBatchNoFilter - - columns = [ - (_("Batch Number"), "lot_number"), - (_("Description"), "lot_description"), - (_("Assets"), "assets_column"), - ] - header_attrs = { "action": """ style = "width:180px !important" @@ -142,34 +141,5 @@ class AssetBatchDetailView(HorillaDetailedView): title = _("Details") header = False model = AssetLot - body = { - (_("Batch Number"), "lot_number"), - (_("Assets"), "assets_column"), - (_("Description"), "lot_description"), - } - action_method = "deatil_actions" - # actions = [ - # { - # "action": _("Edit"), - # "icon": "create-outline", - # "attrs": """ - # class="oh-btn oh-btn--info w-100" - # hx-get='{get_update_url}?instance_ids={ordered_ids}' - - -# hx-target="#genericModalBody" -# data-toggle="oh-modal-toggle" -# data-target="#genericModal" -# """, -# }, -# { -# "action": _("Delete"), -# "icon": "trash-outline", -# "attrs": """ -# class="oh-btn oh-btn--danger w-100" -# hx-confirm="Do you want to delete this batch number?" -# hx-post="{get_delete_url}?instance_ids={ordered_ids}" -# hx-target="#AssetBatchList" -# """, -# }, -# ] + body = ["lot_number", (_("Asset"), "assets_column"), "lot_description"] + action_method = "detail_actions" diff --git a/asset/cbv/asset_category.py b/asset/cbv/asset_category.py index d3079cb18..32b222a80 100644 --- a/asset/cbv/asset_category.py +++ b/asset/cbv/asset_category.py @@ -214,12 +214,43 @@ class AssetCategoryNav(HorillaNavView): def __init__(self, **kwargs: Any) -> None: super().__init__(**kwargs) self.search_url = reverse("asset-category-view-search-filter") - self.create_attrs = f""" + self.actions = [] + if self.request.user.has_perm("add_assetcategory"): + self.create_attrs = f""" + data-toggle="oh-modal-toggle" + data-target="#genericModal" + hx-get="{reverse('asset-category-creation')}" + hx-target="#genericModalBody" + """ + if self.request.user.has_perm("add_assetcategory"): + self.actions.append( + { + "action": _("Import"), + "attrs": f""" + onclick="getAssetImportTemplate();" + data-toggle="oh-modal-toggle" + data-target="#objectCreateModal" + hx-get="{reverse('asset-import')}" + hx-target="#objectCreateModalTarget" + style="cursor: pointer;" + """, + }, + ) + + if self.request.user.has_perm("view_asset"): + self.actions.append( + { + "action": _("Export"), + "attrs": f""" data-toggle="oh-modal-toggle" - data-target="#genericModal" - hx-get="{reverse('asset-category-creation')}" - hx-target="#genericModalBody" - """ + data-target="#objectCreateModal" + hx-get="{reverse('asset-export-excel')}" + hx-target="#objectCreateModalTarget" + style="cursor: pointer;" + """, + } + ) + # if self.request.user.has_perm( # "attendance.add_attendanceovertime" # ) or is_reportingmanager(self.request): @@ -250,55 +281,3 @@ class AssetCategoryNav(HorillaNavView): filter_instance = AssetFilter() filter_form_context_name = "form" search_swap_target = "#assetCategoryList" - - -class AssetCategoryDetailView(HorillaDetailedView): - """ - Detail view of the page - """ - - def get_context_data(self, **kwargs: Any): - """ - Return context data with the title set to the contract's name. - """ - - context = super().get_context_data(**kwargs) - asset_name = context["asset"].asset_name - context["title"] = asset_name - return context - - model = Asset - header = False - template_name = "cbv/asset_category/detail_view_action.html" - body = [ - (_("Tracking Id"), "asset_tracking_id"), - (_("Purchase Date"), "asset_purchase_date"), - (_("Cost"), "asset_purchase_cost"), - (_("Status"), "get_status_display"), - (_("Batch No"), "asset_lot_number_id__lot_number"), - (_("Category"), "asset_category_id"), - ] - - actions = [ - { - "action": _("Edit"), - "icon": "create-outline", - "attrs": """ - class="oh-btn oh-btn--info w-100" - hx-get='{get_update_url}?instance_ids={ordered_ids}' - hx-target="#genericModalBody" - data-toggle="oh-modal-toggle" - data-target="#genericModal" - """, - }, - { - "action": _("Delete"), - "icon": "trash-outline", - "attrs": """ - class="oh-btn oh-btn--danger w-100" - hx-confirm="Do you want to delete this asset?" - hx-post="{get_delete_url}?instance_ids={ordered_ids}" - hx-target="#genericModalBody" - """, - }, - ] diff --git a/asset/models.py b/asset/models.py index 8f74b3e93..29a9ccda7 100644 --- a/asset/models.py +++ b/asset/models.py @@ -104,9 +104,9 @@ class AssetLot(HorillaModel): context={"instance": self}, ) - def deatil_actions(self): + def detail_actions(self): return render_template( - path="cbv/asset_batch_no/deatil_actions.html", + path="cbv/asset_batch_no/detail_actions.html", context={"instance": self}, ) @@ -183,11 +183,10 @@ class Asset(HorillaModel): def __str__(self): return f"{self.asset_name}-{self.asset_tracking_id}" - def get_status_display(self): - """ - Display status - """ - return dict(self.ASSET_STATUS).get(self.asset_status) + def action_column(self): + return render_template( + path="asset/action_column.html", context={"instance": self} + ) def detail_view_action(self): """ @@ -195,10 +194,14 @@ class Asset(HorillaModel): """ return render_template( - path="cbv/asset_category/detail_view_action.html", + path="cbv/asset/detail_action.html", context={"instance": self}, ) + def asset_detail(self): + url = reverse_lazy("asset-information", kwargs={"pk": self.pk}) + return url + def get_update_url(self): """ This method to get update url diff --git a/asset/templates/asset/action_column.html b/asset/templates/asset/action_column.html new file mode 100644 index 000000000..d1653d5fa --- /dev/null +++ b/asset/templates/asset/action_column.html @@ -0,0 +1,36 @@ +{% load static i18n %} +{% if perms.asset.change_asset %} + +{% endif %} +{% if perms.asset.add_asset %} + +{% endif %} +{% if asset.assetassignment_set.all %} + +{% else %} + +{% endif %} +{% if perms.asset.delete_asset %} +
+{% endif %} \ No newline at end of file diff --git a/asset/templates/cbv/asset/detail_action.html b/asset/templates/cbv/asset/detail_action.html new file mode 100644 index 000000000..67bc9dc7f --- /dev/null +++ b/asset/templates/cbv/asset/detail_action.html @@ -0,0 +1,27 @@ +{% load static i18n %} +{% if perms.asset.change_assetlot %} + + + +{% endif %} + +{% if perms.asset.delete_assetlot %} + + + +{% endif %} diff --git a/asset/templates/cbv/asset_batch_no/deatil_actions.html b/asset/templates/cbv/asset_batch_no/detail_actions.html similarity index 83% rename from asset/templates/cbv/asset_batch_no/deatil_actions.html rename to asset/templates/cbv/asset_batch_no/detail_actions.html index ec8d84cad..af8c258d9 100644 --- a/asset/templates/cbv/asset_batch_no/deatil_actions.html +++ b/asset/templates/cbv/asset_batch_no/detail_actions.html @@ -2,7 +2,7 @@ {% if perms.asset.change_assetlot %}