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:
|
||||
|
||||
@@ -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; });
|
||||
|
||||
Reference in New Issue
Block a user