filter task show main task value and main and sub task edit

This commit is contained in:
Pooja Fulari
2026-04-21 10:27:13 +05:30
parent c6f543c63f
commit e46e1e52bb
58 changed files with 412 additions and 253 deletions

View File

@@ -8,21 +8,23 @@ from app.service.logger import log_activity
def recalc_task(task):
rate = float(task.rate or 0)
qty = float(task.qty or 0)
prev_qty = float(task.previous_billed_qty or 0)
ra_qty = float(task.in_this_ra_bill_qty or 0)
# H = G * E
task.previous_billing_amount = round(prev_qty * rate, 2)
# J = I * E
task.in_this_ra_billing_amount = round(ra_qty * rate, 2)
# K = I + G
task.cumulative_billed_qty = round(prev_qty + ra_qty, 2)
# L = K * E
task.cumulative_billed_amount = round(task.cumulative_billed_qty * rate, 2)
# M = IF(K > D , K - D , 0)
if task.cumulative_billed_qty > qty:
task.variation_qty = round(task.cumulative_billed_qty - qty, 2)
else:
task.variation_qty = 0
# N = M * E
task.variation_amount = round(task.variation_qty * rate, 2)
@@ -40,116 +42,54 @@ def update_tasks_controller():
"variation_qty",
"variation_amount"
]
for key, new_value in updates.items():
if '_' not in key:
continue
field_name, task_id_str = key.rsplit('_', 1)
if not task_id_str.isdigit():
continue
task = Task.query.get(int(task_id_str))
if task:
if field_name in formula_fields:
continue
current_value = getattr(task, field_name, None)
if str(current_value) != str(new_value):
setattr(task, field_name, new_value)
recalc_task(task)
update_count += 1
log_activity(
current_user.username,
"Task Update",
f"Task ID {task.id} - {field_name} changed to {new_value}"
)
if update_count > 0:
db.session.commit()
log_activity(
current_user.username,
"Database Commit",
f"{update_count} task field(s) updated"
)
return jsonify({'message': f'count: {update_count} field(s) updated.'})
return jsonify({'message': 'No fields were updated.'})
except Exception as e:
log_activity(current_user.username, "Error", str(e))
return jsonify({'error': 'Update failed'}), 500
# # Update tasks route
# @main.route('/update_tasks', methods=['POST'])
# @login_required
# def update_tasks():
# try:
# updates = request.get_json()
# update_count = 0
# for key, new_value in updates.items():
# if '_' not in key:
# continue
# field_name, task_id_str = key.rsplit('_', 1)
# if not task_id_str.isdigit():
# continue
# task_id = int(task_id_str)
# task = db.session.query(Task).filter_by(id=task_id).first()
# if task:
# current_value = getattr(task, field_name, None)
# if current_value != new_value:
# setattr(task, field_name, new_value)
# update_count += 1
# log_activity(current_user.username, "Task Update", f"Task ID {task.id} - {field_name} changed to {new_value}")
# if update_count > 0:
# db.session.commit()
# log_activity(current_user.username, "Database Commit", f"{update_count} task field(s) updated")
# return jsonify({'message': f'count: {update_count} field(s) updated.'})
# else:
# return jsonify({'message': 'No fields were updated.'})
# except Exception as e:
# log_activity(current_user.username, "Error", f"Update tasks error: {str(e)}")
# return jsonify({'error': 'An error occurred while updating tasks.'}), 500
def display_tasks_controller():
work_details = WorkDetail.query.order_by(
WorkDetail.uploaded_at.desc()
).first()
if not work_details:
log_activity(current_user.username, "Tasks View", "No work details")
return "No work details available.", 404
tasks = Task.query.filter_by(
district=work_details.district,
village_name=work_details.name_of_village,
block_name=work_details.block
).order_by(Task.uploaded_at.desc()).all()
grouped_tasks = []
current_main_task = None
for task in tasks:
task_data = {
"id": task.id,
"task_name": task.task_name,
@@ -168,20 +108,17 @@ def display_tasks_controller():
"remark": task.remark,
"district": task.district
}
if task.serial_number:
task_data["subtasks"] = []
grouped_tasks.append(task_data)
current_main_task = task_data
elif current_main_task:
current_main_task["subtasks"].append(task_data)
log_activity(
current_user.username,
"Tasks View",
f"{work_details.name_of_village}, {work_details.block}"
)
return render_template(
'tasks_display.html',
work_details=work_details,