|
|
|
|
@ -423,19 +423,30 @@ async def update(
|
|
|
|
|
|
|
|
|
|
data = equipment_in.model_dump()
|
|
|
|
|
update_data = equipment_in.model_dump(exclude_defaults=True)
|
|
|
|
|
|
|
|
|
|
# Check if proportion from AcquisitionData changed and recalculate acquisition_cost
|
|
|
|
|
if "proportion" in update_data or "category_no" in update_data:
|
|
|
|
|
category_no = update_data.get("category_no", equipment.category_no)
|
|
|
|
|
proportion = update_data.get("proportion", equipment.proportion)
|
|
|
|
|
|
|
|
|
|
print(f"DEBUG: Detected change - category_no={category_no}, proportion={proportion}")
|
|
|
|
|
|
|
|
|
|
acquisition_data_query = Select(AcquisitionData).filter(
|
|
|
|
|
AcquisitionData.category_no == category_no
|
|
|
|
|
)
|
|
|
|
|
acquisition_data_result = await db_session.execute(acquisition_data_query)
|
|
|
|
|
acquisition_data = acquisition_data_result.scalars().one_or_none()
|
|
|
|
|
|
|
|
|
|
print(f"DEBUG: AcquisitionData found: {acquisition_data is not None}")
|
|
|
|
|
if acquisition_data:
|
|
|
|
|
print(f"DEBUG: cost_unit_3={acquisition_data.cost_unit_3}")
|
|
|
|
|
|
|
|
|
|
if acquisition_data and acquisition_data.cost_unit_3:
|
|
|
|
|
new_proportion = update_data.get("proportion")
|
|
|
|
|
if new_proportion is not None:
|
|
|
|
|
equipment.acquisition_cost = (new_proportion * 0.01) * acquisition_data.cost_unit_3
|
|
|
|
|
new_acquisition_cost = (proportion * 0.01) * acquisition_data.cost_unit_3
|
|
|
|
|
print(f"DEBUG: Calculated new_acquisition_cost={new_acquisition_cost}")
|
|
|
|
|
equipment.acquisition_cost = new_acquisition_cost
|
|
|
|
|
else:
|
|
|
|
|
print(f"DEBUG: No acquisition_data or cost_unit_3 available")
|
|
|
|
|
|
|
|
|
|
for field in data:
|
|
|
|
|
if field in update_data:
|
|
|
|
|
|