From 670db75fcd8104e34c91a52422dc8df3a439fdf9 Mon Sep 17 00:00:00 2001 From: consultoria-as Date: Thu, 2 Jul 2026 14:45:25 +0000 Subject: [PATCH] fix(workshop): show autorizada for workshop/mechanic and hide delivery statuses --- pos/blueprints/service_order_bp.py | 23 ++++++++++++------ pos/static/js/workshop.js | 39 +++++++++++++++++------------- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/pos/blueprints/service_order_bp.py b/pos/blueprints/service_order_bp.py index 7b12e20..c9e0e2c 100644 --- a/pos/blueprints/service_order_bp.py +++ b/pos/blueprints/service_order_bp.py @@ -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: diff --git a/pos/static/js/workshop.js b/pos/static/js/workshop.js index 3fcf7ec..3b9d823 100644 --- a/pos/static/js/workshop.js +++ b/pos/static/js/workshop.js @@ -196,13 +196,16 @@ var Workshop = (function() { document.querySelectorAll('.restricted-hide').forEach(function(el) { el.style.display = 'none'; }); var searchInput = document.getElementById('filterSearch'); if (searchInput) searchInput.placeholder = 'Buscar orden'; - // Limit status filter to the only status taller accounts can see. + // Remove statuses that workshop/mechanic cannot see from the status filter. var statusSel = document.getElementById('filterStatus'); if (statusSel) { + var hiddenStatuses = isMechanic + ? ['cotizada','por_autorizar','autorizacion_parcial','por_facturar','facturada','por_entregar','entregado','por_enviar','enviado','por_recolectar'] + : ['por_entregar','entregado','por_enviar','enviado','por_recolectar']; Array.from(statusSel.options).forEach(function(opt) { - if (opt.value && opt.value !== 'autorizada') opt.remove(); + if (opt.value && hiddenStatuses.indexOf(opt.value) !== -1) opt.remove(); }); - statusSel.value = 'autorizada'; + statusSel.value = ''; } } if (hidePrices) { @@ -261,17 +264,18 @@ var Workshop = (function() { .then(function(d) { var cards = document.querySelectorAll('#statsRow .summary-card'); if (isRestricted) { - // Taller accounts only see authorized orders. + // Taller accounts: hide delivery/logistics card; show work-in-progress summary. cards.forEach(function(card, idx) { - if (idx === 0) { - card.style.display = ''; - var label = card.querySelector('.summary-card__label'); - if (label) label.textContent = 'Autorizadas'; - } else { - card.style.display = 'none'; - } + card.style.display = (idx === 2) ? 'none' : ''; // hide "Por entregar" }); - document.getElementById('statReceived').textContent = fmt(d.autorizada || 0); + document.getElementById('statReceived').textContent = fmt(d.por_revisar || 0); + document.getElementById('statRepair').textContent = fmt( + (d.en_reparacion || 0) + (d.en_revision || 0) + (d.revisada || 0) + + (d.cotizada || 0) + (d.por_autorizar || 0) + + (d.autorizada || 0) + (d.autorizacion_parcial || 0) + ); + document.getElementById('statReady').textContent = '0'; + document.getElementById('statOverdue').textContent = fmt(d.overdue || 0); return; } cards.forEach(function(card) { card.style.display = ''; }); @@ -404,11 +408,12 @@ var Workshop = (function() { var board = document.getElementById('kanbanBoard'); board.innerHTML = ''; var hiddenCols = []; - if (isRestricted) { - // Taller accounts only see the "autorizada" column. - hiddenCols = COLUMNS.filter(function(c) { return c.key !== 'autorizada'; }).map(function(c) { return c.key; }); - } else if (isMechanic) { - hiddenCols = ['cotizada','por_autorizar','autorizada','autorizacion_parcial','por_facturar','facturada']; + if (isMechanic) { + // Mechanic sees everything except commercial and delivery/logistics statuses. + hiddenCols = ['cotizada','por_autorizar','autorizacion_parcial','por_facturar','facturada','por_entregar','entregado','por_enviar','enviado','por_recolectar']; + } else if (role === 'workshop') { + // Workshop sees everything except delivery/logistics statuses. + hiddenCols = ['por_entregar','entregado','por_enviar','enviado','por_recolectar']; } COLUMNS.filter(function(col) { return hiddenCols.indexOf(col.key) === -1; }).forEach(function(col) { var colOrders = orders.filter(function(o) { return o.status === col.key; });