This commit is contained in:
Suherdy Yacob 2026-01-22 15:31:44 +07:00
parent 4944a1ff24
commit f3280ebdca

View File

@ -62,7 +62,7 @@ def main():
def ensure_models(env): def ensure_models(env):
missing_models = { missing_models = {
'PERALATAN DAPUR': { 'PERALATAN DAPUR': {
'fallback': 'Peralatan Inventaris', 'fallback': 'Peralatan Dapur',
'name': 'Peralatan Dapur', 'name': 'Peralatan Dapur',
'method_number': 60, 'method_number': 60,
'method_period': '1' 'method_period': '1'
@ -144,27 +144,24 @@ def process_import(env, excel_file):
if not col_name: if not col_name:
continue continue
acq_date = row[7] acquisition_date = row[7]
if isinstance(acq_date, datetime): if isinstance(acquisition_date, datetime):
acq_date = acq_date.date() acquisition_date = acquisition_date.date()
if not isinstance(acq_date, date): if not isinstance(acquisition_date, date):
continue continue
if acq_date > CUTOFF_DATE: # Check if asset is newer than cutoff
if acquisition_date > CUTOFF_DATE:
if skipped_count < 5: # Limit detailed skip logs if skipped_count < 5: # Limit detailed skip logs
print(f"Skipping '{col_name}': Acquired {acq_date} (After Cutoff)") print(f"Skipping '{col_name}': Acquired {acquisition_date} (After Cutoff)")
skipped_count += 1 skipped_count += 1
continue continue
original_value = row[8] original_value = row[13] # Column N Saldo Akhir
if not isinstance(original_value, (int, float)): if not isinstance(original_value, (int, float)):
original_value = 0.0 original_value = 0.0
accum_depr_dec31 = row[17]
if not isinstance(accum_depr_dec31, (int, float)):
accum_depr_dec31 = 0.0
if not current_category_name: if not current_category_name:
continue continue
@ -188,23 +185,31 @@ def process_import(env, excel_file):
# Calculate Logic # Calculate Logic
# Determine total duration in months # Determine total duration in months
# OVERRIDE: Enforce specific durations for certain categories
DURATION_OVERRIDES = {
'RENOVASI BANGUNAN': 60,
'PATENT & MERK': 120,
'PERALATAN DAPUR': 60,
}
effective_method_number = model.method_number
if current_category_name in DURATION_OVERRIDES:
effective_method_number = DURATION_OVERRIDES[current_category_name]
period_multiple = int(model.method_period) # 1 or 12 period_multiple = int(model.method_period) # 1 or 12
total_months = model.method_number * period_multiple total_months = effective_method_number * period_multiple
end_date = acq_date + relativedelta(months=total_months) # Calculated Depr
# Calculate months passed from acquisition to CUTOFF_DATE
delta = relativedelta(CUTOFF_DATE, acquisition_date)
months_passed = delta.years * 12 + delta.months + (1 if delta.days > 0 else 0) # Include current month if any days passed
if end_date <= CUTOFF_DATE: # Ensure months_passed does not exceed total_months
# Asset should be fully depreciated by Cutoff months_passed = min(months_passed, total_months)
accum_depr_oct31 = accum_depr_dec31
# Sanity check: Should ideally be equal to original_value, but use Excel data. # Calculate accumulated depreciation up to CUTOFF_DATE
else:
# Asset is still active or naturally finishes after Cutoff
# We need to back-calculate from Dec 31
monthly_depr = original_value / total_months if total_months > 0 else 0 monthly_depr = original_value / total_months if total_months > 0 else 0
accum_depr_oct31 = monthly_depr * months_passed
# Adjustment for Nov, Dec (2 months)
adjustment = 2 * monthly_depr
accum_depr_oct31 = accum_depr_dec31 - adjustment
# Clamp values # Clamp values
if accum_depr_oct31 < 0: if accum_depr_oct31 < 0:
@ -216,10 +221,10 @@ def process_import(env, excel_file):
'name': col_name, 'name': col_name,
'asset_code': col_1, # Added Asset Code 'asset_code': col_1, # Added Asset Code
'original_value': original_value, 'original_value': original_value,
'acquisition_date': acq_date, 'acquisition_date': acquisition_date,
'model_id': model.id, 'model_id': model.id,
'method': model.method, 'method': model.method,
'method_number': model.method_number, 'method_number': effective_method_number,
'method_period': model.method_period, 'method_period': model.method_period,
'prorata_computation_type': model.prorata_computation_type, 'prorata_computation_type': model.prorata_computation_type,
'already_depreciated_amount_import': accum_depr_oct31, 'already_depreciated_amount_import': accum_depr_oct31,