feat: implement consumable inventory module, network LAN access, and CI/CD enhancements

- Modul Consumable Item: model master, buku besar transaksi (stock ledger), purchase unit conversion, stock opname, dan transaction reversal
- Integrasi ke Employee Management, Asset Unit, dan tiket/work order
- Konfigurasi akses jaringan lokal (LAN) via 0.0.0.0:8000, ALLOWED_HOSTS, dan CSRF_TRUSTED_ORIGINS otomatis
- Script pembuka firewall Windows (buka_firewall_lan.bat) dan menu interaktif run.bat
- Skema migrasi 0019_consumableitem_consumabletransaction
- Seeder 11 item consumable riil (seed_consumables.py)
- Test suite komprehensif (41 automated tests, 100% lulus)
- Pipeline CI/CD GitHub Actions (.github/workflows/ci.yml)
This commit is contained in:
nuexn0x-9
2026-10-27 09:42:15 +07:00
commit f28983011c
110 changed files with 20296 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
import pymysql
pymysql.install_as_MySQLdb()
+16
View File
@@ -0,0 +1,16 @@
"""
ASGI config for itam_core project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'itam_core.settings')
application = get_asgi_application()
+240
View File
@@ -0,0 +1,240 @@
"""
Django settings for itam_core project.
Generated by 'django-admin startproject' using Django 5.2.17.
For more information on this file, see
https://docs.djangoproject.com/en/5.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.2/ref/settings/
"""
from pathlib import Path
import os
from dotenv import load_dotenv
load_dotenv()
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
DEBUG = os.getenv('DJANGO_DEBUG', 'False').lower() in ('true', '1', 'yes')
SECRET_KEY = os.getenv('DJANGO_SECRET_KEY')
if not SECRET_KEY:
if DEBUG:
SECRET_KEY = 'django-insecure-dev-key-change-in-production'
else:
raise ValueError("DJANGO_SECRET_KEY environment variable wajib diset ketika DEBUG=False!")
raw_hosts = os.getenv('DJANGO_ALLOWED_HOSTS', '')
if raw_hosts:
ALLOWED_HOSTS = [h.strip() for h in raw_hosts.split(',') if h.strip()]
elif DEBUG:
ALLOWED_HOSTS = ['*']
else:
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_htmx',
'assets',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django_htmx.middleware.HtmxMiddleware',
]
ROOT_URLCONF = 'itam_core.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR / 'templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'assets.context_processors.role_context',
],
},
},
]
WSGI_APPLICATION = 'itam_core.wsgi.application'
# Database
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases
import sys
db_engine = os.getenv('DB_ENGINE', 'mysql').lower()
if 'test' in sys.argv:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
}
elif db_engine in ('sqlite', 'sqlite3'):
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': os.getenv('DB_NAME', 'manajemen_aset_it'),
'USER': os.getenv('DB_USER', 'root'),
'PASSWORD': os.getenv('DB_PASSWORD', ''),
'HOST': os.getenv('DB_HOST', '127.0.0.1'),
'PORT': os.getenv('DB_PORT', '3306'),
}
}
# Password validation
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/5.2/topics/i18n/
LANGUAGE_CODE = 'id-id'
TIME_ZONE = 'Asia/Jakarta'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.2/howto/static-files/
STATIC_URL = '/static/'
# Default primary key field type
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
STATICFILES_DIRS = [BASE_DIR / 'static']
DJANGO_VITE = {
'default': {
'dev_mode': DEBUG,
}
}
STATIC_ROOT = BASE_DIR / 'staticfiles'
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' if not DEBUG else 'django.contrib.staticfiles.storage.StaticFilesStorage'
MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR / 'media'
# Security settings (enabled when DEBUG=False)
if not DEBUG:
SECURE_SSL_REDIRECT = os.getenv('SECURE_SSL_REDIRECT', 'False').lower() in ('true', '1', 'yes')
SECURE_HSTS_SECONDS = 31536000
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SECURE_CONTENT_TYPE_NOSNIFF = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
raw_csrf = os.getenv('CSRF_TRUSTED_ORIGINS', '')
CSRF_TRUSTED_ORIGINS = [orig.strip() for orig in raw_csrf.split(',') if orig.strip()]
# Tambahkan origin otomatis untuk akses LAN jika DEBUG=True
if DEBUG:
for default_origin in ['http://localhost:8000', 'http://127.0.0.1:8000', 'http://0.0.0.0:8000']:
if default_origin not in CSRF_TRUSTED_ORIGINS:
CSRF_TRUSTED_ORIGINS.append(default_origin)
try:
import socket
hostname = socket.gethostname()
local_ips = socket.gethostbyname_ex(hostname)[2]
for ip in local_ips:
origin_ip = f"http://{ip}:8000"
if origin_ip not in CSRF_TRUSTED_ORIGINS:
CSRF_TRUSTED_ORIGINS.append(origin_ip)
except Exception:
pass
# Logging
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '{asctime} {levelname} {module} {message}',
'style': '{',
},
},
'handlers': {
'file': {
'level': 'ERROR',
'class': 'logging.FileHandler',
'filename': BASE_DIR / 'error.log',
'formatter': 'verbose',
},
'console': {
'class': 'logging.StreamHandler',
'formatter': 'verbose',
},
},
'root': {
'handlers': ['file', 'console'],
'level': 'WARNING',
},
}
LOGIN_URL = 'login'
+103
View File
@@ -0,0 +1,103 @@
from django.shortcuts import render
from django.contrib import admin
from django.urls import path, re_path
from assets.views import (
profile_view, custom_404_view, login_view, logout_view, unit_qr_code, unit_public_detail,
dashboard, status_aset_list, status_aset_export_pdf, asset_list, asset_add, asset_edit,
asset_delete, asset_units, asset_units_export_pdf, unit_add, unit_edit, unit_delete,
unit_history, unit_history_export_pdf, unit_update_status, distribusi_list, distribusi_handover,
distribusi_mutation, distribusi_return, distribusi_export_pdf, distribusi_upload_doc,
employee_list, employee_export_pdf, employee_detail, employee_detail_export_pdf,
employee_create, employee_edit, employee_delete, employee_activate,
ci_list, ci_detail, ci_create, ci_edit, ci_assign, ci_remove, ci_replace, ci_report_damage,
asset_export_pdf, asset_export_excel, backup_database_view, asset_units_export_excel,
unit_history_export_excel, status_aset_export_excel, distribusi_export_excel,
employee_export_excel, employee_detail_export_excel,
consumable_list, consumable_detail, consumable_create, consumable_edit,
consumable_in, consumable_out, consumable_adjust, consumable_transaction_reverse,
consumable_export_excel, consumable_export_pdf
)
from django.conf import settings
from django.conf.urls.static import static
admin.site.site_header = "Administrasi IT All Role PT. KMH"
admin.site.site_title = "Admin Portal IT"
admin.site.index_title = "Manajemen Database Inti"
urlpatterns = [
path('profil/', profile_view, name='profile'),
path('backup/', backup_database_view, name='backup_database'),
path('404/', custom_404_view, name='test_404'),
path('login/', login_view, name='login'),
path('logout/', logout_view, name='logout'),
# path('admin/', admin.site.urls), # Django Admin dinonaktifkan
path('', dashboard, name='dashboard'),
path('aset/', asset_list, name='asset_list'),
path('aset/export/', asset_export_pdf, name='asset_export_pdf'),
path('aset/export-excel/', asset_export_excel, name='asset_export_excel'),
path('aset/add/', asset_add, name='asset_add'),
path('aset/<int:asset_id>/edit/', asset_edit, name='asset_edit'),
path('aset/<int:asset_id>/delete/', asset_delete, name='asset_delete'),
path('aset/<int:asset_id>/units/', asset_units, name='asset_units'),
path('aset/<int:asset_id>/units/export/', asset_units_export_pdf, name='asset_units_export_pdf'),
path('aset/<int:asset_id>/units/export-excel/', asset_units_export_excel, name='asset_units_export_excel'),
path('aset/<int:asset_id>/units/add/', unit_add, name='unit_add'),
path('unit/<int:unit_id>/edit/', unit_edit, name='unit_edit'),
path('unit/<int:unit_id>/delete/', unit_delete, name='unit_delete'),
path('unit/<int:unit_id>/status/', unit_update_status, name='unit_update_status'),
path('unit/<int:unit_id>/history/', unit_history, name='unit_history'),
path('unit/<int:unit_id>/history/export/', unit_history_export_pdf, name='unit_history_export_pdf'),
path('unit/<int:unit_id>/history/export-excel/', unit_history_export_excel, name='unit_history_export_excel'),
path('status-aset/', status_aset_list, name='status_aset_list'),
path('status-aset/export/', status_aset_export_pdf, name='status_aset_export_pdf'),
path('status-aset/export-excel/', status_aset_export_excel, name='status_aset_export_excel'),
path('distribusi/', distribusi_list, name='distribusi_list'),
path('distribusi/export/', distribusi_export_pdf, name='distribusi_export_pdf'),
path('distribusi/export-excel/', distribusi_export_excel, name='distribusi_export_excel'),
path('distribusi/handover/', distribusi_handover, name='distribusi_handover'),
path('distribusi/mutation/', distribusi_mutation, name='distribusi_mutation'),
path('distribusi/return/', distribusi_return, name='distribusi_return'),
path('distribusi/<int:assignment_id>/upload/', distribusi_upload_doc, name='distribusi_upload_doc'),
path('karyawan/', employee_list, name='employee_list'),
path('karyawan/export/', employee_export_pdf, name='employee_export_pdf'),
path('karyawan/export-excel/', employee_export_excel, name='employee_export_excel'),
path('karyawan/<int:emp_id>/', employee_detail, name='employee_detail'),
path('karyawan/<int:emp_id>/export/', employee_detail_export_pdf, name='employee_detail_export_pdf'),
path('karyawan/<int:emp_id>/export-excel/', employee_detail_export_excel, name='employee_detail_export_excel'),
path('karyawan/buat/', employee_create, name='employee_create'),
path('karyawan/<int:emp_id>/edit/', employee_edit, name='employee_edit'),
path('karyawan/<int:emp_id>/delete/', employee_delete, name='employee_delete'),
path('karyawan/<int:emp_id>/activate/', employee_activate, name='employee_activate'),
# Configuration Items (CI / CMDB)
path('ci/', ci_list, name='ci_list'),
path('ci/create/', ci_create, name='ci_create'),
path('ci/<int:ci_id>/', ci_detail, name='ci_detail'),
path('ci/<int:ci_id>/edit/', ci_edit, name='ci_edit'),
path('ci/<int:ci_id>/assign/', ci_assign, name='ci_assign'),
path('ci/<int:ci_id>/remove/', ci_remove, name='ci_remove'),
path('ci/<int:ci_id>/replace/', ci_replace, name='ci_replace'),
path('ci/<int:ci_id>/report-damage/', ci_report_damage, name='ci_report_damage'),
# Consumable Items (Barang Habis Pakai)
path('consumable/', consumable_list, name='consumable_list'),
path('consumable/create/', consumable_create, name='consumable_create'),
path('consumable/<int:item_id>/', consumable_detail, name='consumable_detail'),
path('consumable/<int:item_id>/edit/', consumable_edit, name='consumable_edit'),
path('consumable/in/', consumable_in, name='consumable_in'),
path('consumable/out/', consumable_out, name='consumable_out'),
path('consumable/adjust/', consumable_adjust, name='consumable_adjust'),
path('consumable/transaction/<int:trx_id>/reverse/', consumable_transaction_reverse, name='consumable_transaction_reverse'),
path('consumable/export-excel/', consumable_export_excel, name='consumable_export_excel'),
path('consumable/export-pdf/', consumable_export_pdf, name='consumable_export_pdf'),
path('qr/<uuid:uuid>/', unit_qr_code, name='unit_qr_code'),
path('public/unit/<uuid:uuid>/', unit_public_detail, name='unit_public_detail'),
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
handler404 = 'assets.views.custom_404_view'
+16
View File
@@ -0,0 +1,16 @@
"""
WSGI config for itam_core project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'itam_core.settings')
application = get_wsgi_application()