feat: Include acquisition cost in equipment update logic and database updates.

rest-api
MrWaradana 1 month ago
parent c42c54aad1
commit 4a0fc31925

@ -879,7 +879,7 @@ async def update_equipment_acquisition_year(assetnum: str):
try:
p_cursor = prod_conn.cursor()
query = """
select DATE_PART('year', a.reportdate) AS year
select DATE_PART('year', a.reportdate) AS year, a.replacecost
from wo_maximo a
where a.asset_replacecost > 0
and a.asset_assetnum = %s
@ -916,14 +916,19 @@ async def update_equipment_acquisition_year(assetnum: str):
curr_life = int(current["design_life"])
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_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.
is_valid_default = (curr_target == (curr_acq + curr_life))
if curr_acq != first_year:
print(f"Acquisition year change detected for {assetnum}: {curr_acq} -> {first_year}. Archiving history.")
# Prepare target cost. If we fetched a new cost from WO, use it, else keep old.
# 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
acq_year_ref = f"{curr_acq}_{curr_target}"
@ -1008,16 +1013,16 @@ async def update_equipment_acquisition_year(assetnum: str):
update_q = """
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
"""
cursor.execute(update_q, (first_year, new_target, assetnum))
cursor.execute(update_q, (first_year, new_target, target_acq_cost, assetnum))
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
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
else:
# Logic if equipment not found? Unlikely here.

Loading…
Cancel
Save