diff --git a/blueprints/admin/routes_membership.py b/blueprints/admin/routes_membership.py index 4ecfd63..0de4240 100644 --- a/blueprints/admin/routes_membership.py +++ b/blueprints/admin/routes_membership.py @@ -561,6 +561,27 @@ def admin_membership_approve(app_id): ) db.add(user_company) + # Add to workflow history + history = application.workflow_history or [] + history_details = { + 'member_number': application.member_number, + 'company_id': company.id, + } + if data.get('category_id'): + history_details['category_id'] = data['category_id'] + if data.get('comment'): + history_details['comment'] = data['comment'] + history.append({ + 'event': 'approved', + 'action_label': 'Deklaracja zatwierdzona', + 'timestamp': datetime.now().isoformat(), + 'user_id': current_user.id, + 'user_name': current_user.name or current_user.email, + 'details': history_details + }) + application.workflow_history = list(history) + flag_modified(application, 'workflow_history') + db.commit() logger.info( @@ -628,6 +649,19 @@ def admin_membership_reject(app_id): application.reviewed_by_id = current_user.id application.review_comment = comment + # Add to workflow history + history = application.workflow_history or [] + history.append({ + 'event': 'rejected', + 'action_label': 'Deklaracja odrzucona', + 'timestamp': datetime.now().isoformat(), + 'user_id': current_user.id, + 'user_name': current_user.name or current_user.email, + 'details': {'comment': comment} + }) + application.workflow_history = list(history) + flag_modified(application, 'workflow_history') + db.commit() logger.info(f"Membership application {app_id} rejected by {current_user.email}: {comment}") @@ -672,6 +706,19 @@ def admin_membership_request_changes(app_id): application.reviewed_by_id = current_user.id application.review_comment = comment + # Add to workflow history + history = application.workflow_history or [] + history.append({ + 'event': 'changes_requested', + 'action_label': 'Poproszono o poprawki', + 'timestamp': datetime.now().isoformat(), + 'user_id': current_user.id, + 'user_name': current_user.name or current_user.email, + 'details': {'comment': comment} + }) + application.workflow_history = list(history) + flag_modified(application, 'workflow_history') + db.commit() logger.info(f"Changes requested for application {app_id} by {current_user.email}: {comment}") @@ -704,6 +751,20 @@ def admin_membership_start_review(app_id): application.status = 'under_review' application.reviewed_by_id = current_user.id + + # Add to workflow history + history = application.workflow_history or [] + history.append({ + 'event': 'start_review', + 'action_label': 'Rozpoczęto rozpatrywanie', + 'timestamp': datetime.now().isoformat(), + 'user_id': current_user.id, + 'user_name': current_user.name or current_user.email, + 'details': {} + }) + application.workflow_history = list(history) + flag_modified(application, 'workflow_history') + db.commit() return jsonify({'success': True}) diff --git a/blueprints/membership/routes.py b/blueprints/membership/routes.py index 73204f6..9c23cc4 100644 --- a/blueprints/membership/routes.py +++ b/blueprints/membership/routes.py @@ -191,6 +191,24 @@ def apply_step(step): # Submit application application.status = 'submitted' application.submitted_at = datetime.now() + + # Add to workflow history + history = application.workflow_history or [] + history.append({ + 'event': 'submitted', + 'action_label': 'Deklaracja złożona', + 'timestamp': datetime.now().isoformat(), + 'user_id': current_user.id, + 'user_name': current_user.name or current_user.email, + 'details': { + 'company_name': application.company_name, + 'nip': application.nip, + 'ip_address': request.remote_addr + } + }) + application.workflow_history = list(history) + flag_modified(application, 'workflow_history') + db.commit() # Wyślij notyfikacje do administratorów i kierowników biura