|
|
|
@ -879,7 +879,7 @@ async def update_equipment_acquisition_year(assetnum: str):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
p_cursor = prod_conn.cursor()
|
|
|
|
p_cursor = prod_conn.cursor()
|
|
|
|
query = """
|
|
|
|
query = """
|
|
|
|
select DATE_PART('year', a.reportdate) AS year
|
|
|
|
select DATE_PART('year', a.reportdate) AS year, a.replacecost
|
|
|
|
from wo_maximo a
|
|
|
|
from wo_maximo a
|
|
|
|
where a.asset_replacecost > 0
|
|
|
|
where a.asset_replacecost > 0
|
|
|
|
and a.asset_assetnum = %s
|
|
|
|
and a.asset_assetnum = %s
|
|
|
|
@ -916,14 +916,19 @@ async def update_equipment_acquisition_year(assetnum: str):
|
|
|
|
curr_life = int(current["design_life"])
|
|
|
|
curr_life = int(current["design_life"])
|
|
|
|
curr_target_val = current["forecasting_target_year"]
|
|
|
|
curr_target_val = current["forecasting_target_year"]
|
|
|
|
curr_target = int(curr_target_val) if curr_target_val is not None else (curr_acq + curr_life) # Fallback if none
|
|
|
|
curr_target = int(curr_target_val) if curr_target_val is not None else (curr_acq + curr_life) # Fallback if none
|
|
|
|
|
|
|
|
curr_acq_cost = float(current["acquisition_cost"]) if current["acquisition_cost"] is not None else 0.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Logic: if current_target matches the "old default" (old_acq + life), then update it too.
|
|
|
|
# Logic: if current_target matches the "old default" (old_acq + life), then update it too.
|
|
|
|
is_valid_default = (curr_target == (curr_acq + curr_life))
|
|
|
|
is_valid_default = (curr_target == (curr_acq + curr_life))
|
|
|
|
|
|
|
|
|
|
|
|
if curr_acq != first_year:
|
|
|
|
# Prepare target cost. If we fetched a new cost from WO, use it, else keep old.
|
|
|
|
print(f"Acquisition year change detected for {assetnum}: {curr_acq} -> {first_year}. Archiving history.")
|
|
|
|
# Note: first_acq_cost variable availability check
|
|
|
|
|
|
|
|
target_acq_cost = first_acq_cost if 'first_acq_cost' in locals() and first_acq_cost is not None else curr_acq_cost
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if curr_acq != first_year or curr_acq_cost != target_acq_cost:
|
|
|
|
|
|
|
|
print(f"Acquisition change detected for {assetnum}: Year {curr_acq}->{first_year}, Cost {curr_acq_cost}->{target_acq_cost}. Archiving history.")
|
|
|
|
|
|
|
|
|
|
|
|
# Define reference for history
|
|
|
|
# Define reference for history
|
|
|
|
acq_year_ref = f"{curr_acq}_{curr_target}"
|
|
|
|
acq_year_ref = f"{curr_acq}_{curr_target}"
|
|
|
|
|
|
|
|
|
|
|
|
@ -1008,16 +1013,16 @@ async def update_equipment_acquisition_year(assetnum: str):
|
|
|
|
|
|
|
|
|
|
|
|
update_q = """
|
|
|
|
update_q = """
|
|
|
|
UPDATE lcc_ms_equipment_data
|
|
|
|
UPDATE lcc_ms_equipment_data
|
|
|
|
SET acquisition_year = %s, forecasting_target_year = %s
|
|
|
|
SET acquisition_year = %s, forecasting_target_year = %s, acquisition_cost = %s
|
|
|
|
WHERE assetnum = %s
|
|
|
|
WHERE assetnum = %s
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
cursor.execute(update_q, (first_year, new_target, assetnum))
|
|
|
|
cursor.execute(update_q, (first_year, new_target, target_acq_cost, assetnum))
|
|
|
|
|
|
|
|
|
|
|
|
conn.commit()
|
|
|
|
conn.commit()
|
|
|
|
print(f"Updated acquisition_year for {assetnum}: {curr_acq} -> {first_year}. History archived.")
|
|
|
|
print(f"Updated acquisition info for {assetnum}. History archived.")
|
|
|
|
updated_acq = first_year
|
|
|
|
updated_acq = first_year
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
print(f"No acquisition year update needed for {assetnum}. Current: {curr_acq}, New: {first_year}")
|
|
|
|
print(f"No acquisition info update needed for {assetnum}.")
|
|
|
|
updated_acq = curr_acq
|
|
|
|
updated_acq = curr_acq
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
# Logic if equipment not found? Unlikely here.
|
|
|
|
# Logic if equipment not found? Unlikely here.
|
|
|
|
|