fix(workshop): show autorizada for workshop/mechanic and hide delivery statuses
This commit is contained in:
@@ -43,13 +43,18 @@ _WORKSHOP_VIEW_ROLES = {'owner', 'admin', 'counter', 'cashier', 'workshop', 'mec
|
||||
_WORKSHOP_EDIT_ROLES = {'owner', 'admin', 'counter', 'cashier'}
|
||||
|
||||
# Statuses that mechanics are not allowed to see (single shared mechanic account).
|
||||
# 'autorizada' is intentionally NOT hidden because mechanics must work on authorized orders.
|
||||
# Delivery/logistics statuses are hidden for both workshop and mechanic.
|
||||
_MECHANIC_HIDDEN_STATUSES = {
|
||||
'cotizada', 'por_autorizar', 'autorizada', 'autorizacion_parcial',
|
||||
'por_facturar', 'facturada'
|
||||
'cotizada', 'por_autorizar', 'autorizacion_parcial',
|
||||
'por_facturar', 'facturada',
|
||||
'por_entregar', 'entregado', 'por_enviar', 'enviado', 'por_recolectar'
|
||||
}
|
||||
|
||||
# Statuses visible to workshop/mechanic accounts (taller only works on authorized orders).
|
||||
_TALLER_ALLOWED_STATUSES = {'autorizada'}
|
||||
# Statuses hidden for workshop accounts (delivery/logistics only).
|
||||
_WORKSHOP_HIDDEN_STATUSES = {
|
||||
'por_entregar', 'entregado', 'por_enviar', 'enviado', 'por_recolectar'
|
||||
}
|
||||
|
||||
|
||||
def _can_view_workshop():
|
||||
@@ -146,10 +151,10 @@ def list_orders():
|
||||
)
|
||||
if _is_restricted_workshop_viewer():
|
||||
result['data'] = [_redact_order_for_mechanic(o) for o in result.get('data', [])]
|
||||
# Workshop/mechanic accounts only see orders ready to be worked on.
|
||||
hidden_statuses = _MECHANIC_HIDDEN_STATUSES if g.employee_role == 'mechanic' else _WORKSHOP_HIDDEN_STATUSES
|
||||
result['data'] = [
|
||||
o for o in result.get('data', [])
|
||||
if o.get('status') in _TALLER_ALLOWED_STATUSES
|
||||
if o.get('status') not in hidden_statuses
|
||||
]
|
||||
return jsonify(result)
|
||||
finally:
|
||||
@@ -239,8 +244,10 @@ def get_order(so_id):
|
||||
order = get_service_order(conn, so_id)
|
||||
if not order:
|
||||
return jsonify({'error': 'Service order not found'}), 404
|
||||
# Workshop/mechanic accounts can only view orders that are ready to be worked on.
|
||||
if _is_restricted_workshop_viewer() and order.get('status') not in _TALLER_ALLOWED_STATUSES:
|
||||
# Workshop/mechanic accounts cannot view delivery/logistics (and mechanic also commercial) statuses.
|
||||
if g.employee_role == 'mechanic' and order.get('status') in _MECHANIC_HIDDEN_STATUSES:
|
||||
return jsonify({'error': 'No tienes acceso a esta orden'}), 403
|
||||
if g.employee_role == 'workshop' and order.get('status') in _WORKSHOP_HIDDEN_STATUSES:
|
||||
return jsonify({'error': 'No tienes acceso a esta orden'}), 403
|
||||
return jsonify(_redact_order_for_mechanic(order))
|
||||
finally:
|
||||
|
||||
Reference in New Issue
Block a user