- 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)
52 lines
2.1 KiB
Python
52 lines
2.1 KiB
Python
# Generated by Django on 2026-10-13
|
|
|
|
from django.db import migrations
|
|
|
|
def sync_unit_codes(apps, schema_editor):
|
|
Asset = apps.get_model('assets', 'Asset')
|
|
AssetUnit = apps.get_model('assets', 'AssetUnit')
|
|
UnitLog = apps.get_model('assets', 'UnitLog')
|
|
|
|
for asset in Asset.objects.all():
|
|
for unit in asset.units.all():
|
|
if not unit.unit_code.startswith(f"{asset.asset_code}-"):
|
|
if '-' in unit.unit_code:
|
|
suffix = unit.unit_code.rsplit('-', 1)[-1]
|
|
else:
|
|
suffix = unit.unit_code
|
|
|
|
target_code = f"{asset.asset_code}-{suffix}"
|
|
|
|
# Pastikan tidak bentrok dengan unit_code yang sudah ada di database
|
|
if AssetUnit.objects.filter(unit_code=target_code).exclude(pk=unit.pk).exists():
|
|
counter = 1
|
|
try:
|
|
base_num = int(suffix)
|
|
while AssetUnit.objects.filter(unit_code=target_code).exclude(pk=unit.pk).exists():
|
|
target_code = f"{asset.asset_code}-{base_num + counter:03d}"
|
|
counter += 1
|
|
except ValueError:
|
|
while AssetUnit.objects.filter(unit_code=target_code).exclude(pk=unit.pk).exists():
|
|
target_code = f"{asset.asset_code}-{suffix}-{counter}"
|
|
counter += 1
|
|
|
|
if unit.unit_code != target_code:
|
|
old_unit_code = unit.unit_code
|
|
unit.unit_code = target_code
|
|
unit.save(update_fields=['unit_code'])
|
|
UnitLog.objects.create(
|
|
unit=unit,
|
|
action='other',
|
|
notes=f"Sinkronisasi kode unit otomatis dari {old_unit_code} ke {target_code} mengikuti kode aset induk."
|
|
)
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
('assets', '0015_assetassignment_created_at'),
|
|
]
|
|
|
|
operations = [
|
|
migrations.RunPython(sync_unit_codes, reverse_code=migrations.RunPython.noop),
|
|
]
|