changes
This commit is contained in:
@@ -2137,6 +2137,94 @@ class AuthorizerPortal(CustomerPortal):
|
||||
_logger.error(f"Error saving POD signature: {e}")
|
||||
return {'success': False, 'error': str(e)}
|
||||
|
||||
# ==================== TASK-LEVEL POD SIGNATURE ====================
|
||||
|
||||
@http.route('/my/technician/task/<int:task_id>/pod', type='http', auth='user', website=True)
|
||||
def task_pod_signature_page(self, task_id, **kw):
|
||||
"""Task-level POD signature capture page (works for all tasks including shadow)."""
|
||||
if not self._check_technician_access():
|
||||
return request.redirect('/my')
|
||||
|
||||
user = request.env.user
|
||||
Task = request.env['fusion.technician.task'].sudo()
|
||||
|
||||
try:
|
||||
task = Task.browse(task_id)
|
||||
if not task.exists() or (
|
||||
task.technician_id.id != user.id
|
||||
and user.id not in task.additional_technician_ids.ids
|
||||
):
|
||||
raise AccessError(_('You do not have access to this task.'))
|
||||
except (AccessError, MissingError):
|
||||
return request.redirect('/my/technician/tasks')
|
||||
|
||||
values = {
|
||||
'task': task,
|
||||
'has_existing_signature': bool(task.pod_signature),
|
||||
'page_name': 'task_pod_signature',
|
||||
}
|
||||
return request.render('fusion_authorizer_portal.portal_task_pod_signature', values)
|
||||
|
||||
@http.route('/my/technician/task/<int:task_id>/pod/sign', type='json', auth='user', methods=['POST'])
|
||||
def task_pod_save_signature(self, task_id, client_name, signature_data, signature_date=None, **kw):
|
||||
"""Save POD signature directly on a task."""
|
||||
if not self._check_technician_access():
|
||||
return {'success': False, 'error': 'Access denied'}
|
||||
|
||||
user = request.env.user
|
||||
Task = request.env['fusion.technician.task'].sudo()
|
||||
|
||||
try:
|
||||
task = Task.browse(task_id)
|
||||
if not task.exists() or (
|
||||
task.technician_id.id != user.id
|
||||
and user.id not in task.additional_technician_ids.ids
|
||||
):
|
||||
return {'success': False, 'error': 'Task not found'}
|
||||
|
||||
if not client_name or not client_name.strip():
|
||||
return {'success': False, 'error': 'Client name is required'}
|
||||
if not signature_data:
|
||||
return {'success': False, 'error': 'Signature is required'}
|
||||
|
||||
if ',' in signature_data:
|
||||
signature_data = signature_data.split(',')[1]
|
||||
|
||||
from datetime import datetime as dt_datetime
|
||||
sig_date = None
|
||||
if signature_date:
|
||||
try:
|
||||
sig_date = dt_datetime.strptime(signature_date, '%Y-%m-%d').date()
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
task.write({
|
||||
'pod_signature': signature_data,
|
||||
'pod_client_name': client_name.strip(),
|
||||
'pod_signature_date': sig_date,
|
||||
'pod_signed_by_user_id': user.id,
|
||||
'pod_signed_datetime': fields.Datetime.now(),
|
||||
})
|
||||
|
||||
if task.sale_order_id:
|
||||
task.sale_order_id.write({
|
||||
'x_fc_pod_signature': signature_data,
|
||||
'x_fc_pod_client_name': client_name.strip(),
|
||||
'x_fc_pod_signature_date': sig_date,
|
||||
'x_fc_pod_signed_by_user_id': user.id,
|
||||
'x_fc_pod_signed_datetime': fields.Datetime.now(),
|
||||
})
|
||||
|
||||
return {
|
||||
'success': True,
|
||||
'message': 'Signature saved successfully',
|
||||
'redirect_url': f'/my/technician/task/{task_id}',
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
_logger.error(f"Error saving task POD signature: {e}")
|
||||
return {'success': False, 'error': str(e)}
|
||||
|
||||
def _generate_signed_pod_pdf(self, order, save_to_field=True):
|
||||
"""Generate a signed POD PDF with the signature embedded.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user