diff --git a/import_fixed_assets.py b/import_fixed_assets.py index 7002b1c..445817d 100644 --- a/import_fixed_assets.py +++ b/import_fixed_assets.py @@ -62,7 +62,7 @@ def main(): def ensure_models(env): missing_models = { 'PERALATAN DAPUR': { - 'fallback': 'Peralatan Inventaris', + 'fallback': 'Peralatan Dapur', 'name': 'Peralatan Dapur', 'method_number': 60, 'method_period': '1' @@ -144,27 +144,24 @@ def process_import(env, excel_file): if not col_name: continue - acq_date = row[7] - if isinstance(acq_date, datetime): - acq_date = acq_date.date() + acquisition_date = row[7] + if isinstance(acquisition_date, datetime): + acquisition_date = acquisition_date.date() - if not isinstance(acq_date, date): + if not isinstance(acquisition_date, date): 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 - print(f"Skipping '{col_name}': Acquired {acq_date} (After Cutoff)") + print(f"Skipping '{col_name}': Acquired {acquisition_date} (After Cutoff)") skipped_count += 1 continue - original_value = row[8] + original_value = row[13] # Column N Saldo Akhir if not isinstance(original_value, (int, float)): 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: continue @@ -188,23 +185,31 @@ def process_import(env, excel_file): # Calculate Logic # 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 - total_months = model.method_number * period_multiple + total_months = effective_method_number * period_multiple - end_date = acq_date + relativedelta(months=total_months) - - if end_date <= CUTOFF_DATE: - # Asset should be fully depreciated by Cutoff - accum_depr_oct31 = accum_depr_dec31 - # Sanity check: Should ideally be equal to original_value, but use Excel data. - 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 - - # Adjustment for Nov, Dec (2 months) - adjustment = 2 * monthly_depr - accum_depr_oct31 = accum_depr_dec31 - adjustment + # 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 + + # Ensure months_passed does not exceed total_months + months_passed = min(months_passed, total_months) + + # Calculate accumulated depreciation up to CUTOFF_DATE + monthly_depr = original_value / total_months if total_months > 0 else 0 + accum_depr_oct31 = monthly_depr * months_passed # Clamp values if accum_depr_oct31 < 0: @@ -216,10 +221,10 @@ def process_import(env, excel_file): 'name': col_name, 'asset_code': col_1, # Added Asset Code 'original_value': original_value, - 'acquisition_date': acq_date, + 'acquisition_date': acquisition_date, 'model_id': model.id, 'method': model.method, - 'method_number': model.method_number, + 'method_number': effective_method_number, 'method_period': model.method_period, 'prorata_computation_type': model.prorata_computation_type, 'already_depreciated_amount_import': accum_depr_oct31,