Sección propia de punto de venta: cajas e histórico
This commit is contained in:
1 parent
782f918908
commit
e538bcfb40
15 files changed
+1017
-54
No files matched your search
@@ -0,0 +1,138 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { Component, onWillStart, useState } from "@odoo/owl";
|
||||
import { registry } from "@web/core/registry";
|
||||
import { useService } from "@web/core/utils/hooks";
|
||||
import { _t } from "@web/core/l10n/translation";
|
||||
|
||||
/**
|
||||
* Punto de venta · supervisión.
|
||||
*
|
||||
* Dos pantallas en un componente porque comparten alcance y formato, y porque
|
||||
* de Cajas se salta al Histórico de una caja concreta sin volver al menú. Cuál
|
||||
* abre lo dice la acción, no el usuario.
|
||||
*
|
||||
* Ninguna cifra se calcula aquí y ninguna sucursal se decide aquí: el servidor
|
||||
* resuelve las dos cosas, y de las mismas fuentes que los tableros.
|
||||
*/
|
||||
export class BeyondPos extends Component {
|
||||
static template = "beyond_pos.Pantallas";
|
||||
static props = ["*"];
|
||||
|
||||
setup() {
|
||||
this.orm = useService("orm");
|
||||
this.dialog = useService("dialog");
|
||||
this.notification = useService("notification");
|
||||
|
||||
this.state = useState({
|
||||
pantalla: this.props.action?.context?.beyond_pantalla || "cajas",
|
||||
cargando: true,
|
||||
cajas: null,
|
||||
historico: null,
|
||||
pestana: "ordenes",
|
||||
filtros: { dias: 30, branch_id: false, config_id: false, busqueda: "" },
|
||||
});
|
||||
|
||||
onWillStart(() => this.cargar());
|
||||
}
|
||||
|
||||
async cargar() {
|
||||
this.state.cargando = true;
|
||||
try {
|
||||
if (this.state.pantalla === "cajas") {
|
||||
this.state.cajas = await this.orm.call(
|
||||
"beyond.pos", "beyond_datos_cajas", []);
|
||||
} else {
|
||||
this.state.historico = await this.orm.call(
|
||||
"beyond.pos", "beyond_datos_historico",
|
||||
[{ ...this.state.filtros }]);
|
||||
}
|
||||
} finally {
|
||||
this.state.cargando = false;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Filtros ─────────────────────────────────────────────────────────
|
||||
|
||||
async filtrar(campo, valor) {
|
||||
this.state.filtros[campo] = valor;
|
||||
// Cambiar de sucursal invalida la caja elegida: es de la otra plaza.
|
||||
if (campo === "branch_id") {
|
||||
this.state.filtros.config_id = false;
|
||||
}
|
||||
await this.cargar();
|
||||
}
|
||||
|
||||
async cambiarSucursal(ev) {
|
||||
await this.filtrar("branch_id", Number(ev.target.value) || false);
|
||||
}
|
||||
|
||||
async cambiarCaja(ev) {
|
||||
await this.filtrar("config_id", Number(ev.target.value) || false);
|
||||
}
|
||||
|
||||
onBuscar(ev) {
|
||||
this.state.filtros.busqueda = ev.target.value;
|
||||
clearTimeout(this._busqueda);
|
||||
this._busqueda = setTimeout(() => this.cargar(), 250);
|
||||
}
|
||||
|
||||
/** Las cajas que se pueden elegir con la sucursal ya filtrada. */
|
||||
get cajasElegibles() {
|
||||
const todas = this.state.historico?.opciones?.cajas || [];
|
||||
const sucursal = this.state.filtros.branch_id;
|
||||
return sucursal ? todas.filter((c) => c.branch_id === sucursal) : todas;
|
||||
}
|
||||
|
||||
// ── Navegación ──────────────────────────────────────────────────────
|
||||
|
||||
async verHistoricoDe(caja) {
|
||||
this.state.pantalla = "historico";
|
||||
this.state.filtros.config_id = caja.id;
|
||||
this.state.filtros.branch_id = false;
|
||||
await this.cargar();
|
||||
}
|
||||
|
||||
async volverACajas() {
|
||||
this.state.pantalla = "cajas";
|
||||
await this.cargar();
|
||||
}
|
||||
|
||||
// ── Agregar caja ────────────────────────────────────────────────────
|
||||
|
||||
async agregarCaja(grupo) {
|
||||
const sugerido = await this.orm.call(
|
||||
"beyond.pos", "beyond_nombre_sugerido", [grupo.id]);
|
||||
const nombre = window.prompt(
|
||||
_t("¿Cómo se llama la caja nueva? Puedes cambiarlo: «Recepción», «Estética»…"),
|
||||
sugerido);
|
||||
if (nombre === null) {
|
||||
return; // se arrepintió
|
||||
}
|
||||
const caja = await this.orm.call(
|
||||
"beyond.pos", "beyond_agregar_caja", [grupo.id, nombre]);
|
||||
this.notification.add(
|
||||
_t("Caja «%s» lista para operar.", caja.nombre), { type: "success" });
|
||||
await this.cargar();
|
||||
}
|
||||
|
||||
// ── Presentación ────────────────────────────────────────────────────
|
||||
|
||||
dinero(valor) {
|
||||
return (valor || 0).toLocaleString("es-MX", {
|
||||
style: "currency", currency: "MXN" });
|
||||
}
|
||||
|
||||
numero(valor) {
|
||||
return (valor || 0).toLocaleString("es-MX");
|
||||
}
|
||||
|
||||
claseDiferencia(valor) {
|
||||
if (!valor) {
|
||||
return "text-muted";
|
||||
}
|
||||
return valor < 0 ? "text-danger fw-bold" : "text-warning fw-bold";
|
||||
}
|
||||
}
|
||||
|
||||
registry.category("actions").add("beyond_pos", BeyondPos);
|
||||
@@ -0,0 +1,22 @@
|
||||
// Supervisión: se mira, no se opera. Lo que cambia de estado se ve sin leer.
|
||||
.o_beyond_pos {
|
||||
height: 100%;
|
||||
overflow: auto;
|
||||
|
||||
.beyond_total { font-size: 1.25rem; font-weight: 600; }
|
||||
.beyond_cifra .beyond_valor {
|
||||
font-size: 1.75rem; font-weight: 600; line-height: 1.1;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.beyond_folio { font-family: var(--bs-font-monospace); font-size: .9em; }
|
||||
.beyond_tabla td, .beyond_tabla th { padding-block: .6rem; }
|
||||
.beyond_tabla .text-end { font-variant-numeric: tabular-nums; }
|
||||
|
||||
// Un punto basta para el estado: el color ya lo dice.
|
||||
.beyond_punto {
|
||||
display: inline-block; width: .6rem; height: .6rem;
|
||||
border-radius: 50%; margin-right: .5rem; vertical-align: middle;
|
||||
&.beyond_abierta { background: var(--bs-success); }
|
||||
&.beyond_cerrada { background: var(--bs-gray-400); }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,260 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates xml:space="preserve">
|
||||
<t t-name="beyond_pos.Pantallas">
|
||||
<div class="o_beyond_pos p-3">
|
||||
|
||||
<!-- ══ 1 · Cajas ══ -->
|
||||
<t t-if="state.pantalla === 'cajas'">
|
||||
<div class="d-flex flex-wrap align-items-center gap-2 mb-3">
|
||||
<h2 class="mb-0">Cajas</h2>
|
||||
<span class="text-muted">· cómo van hoy</span>
|
||||
</div>
|
||||
|
||||
<div t-if="state.cargando" class="text-muted">Cargando…</div>
|
||||
<div t-elif="!state.cajas.grupos.length" class="alert alert-info">
|
||||
No hay cajas en tu alcance todavía.
|
||||
</div>
|
||||
<t t-else="">
|
||||
<div t-foreach="state.cajas.grupos" t-as="grupo" t-key="grupo.id"
|
||||
class="card mb-3">
|
||||
<div class="card-header d-flex flex-wrap align-items-center gap-3">
|
||||
<b t-if="state.cajas.agrupado" t-esc="grupo.nombre"/>
|
||||
<b t-else="">Tus cajas</b>
|
||||
<span class="ms-auto text-muted small">hoy</span>
|
||||
<span class="beyond_total" t-esc="dinero(grupo.total)"/>
|
||||
<span class="text-muted small">
|
||||
<t t-esc="numero(grupo.tickets)"/> ticket(s)
|
||||
</span>
|
||||
<button t-if="state.cajas.puede_agregar"
|
||||
class="btn btn-sm btn-outline-secondary"
|
||||
t-on-click="() => this.agregarCaja(grupo)">
|
||||
<i class="fa fa-plus me-1"/>Agregar caja
|
||||
</button>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover align-middle mb-0 beyond_tabla">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Caja</th>
|
||||
<th>Estado</th>
|
||||
<th>Quién</th>
|
||||
<th class="text-end">Ventas de hoy</th>
|
||||
<th class="text-end">Tickets</th>
|
||||
<th/>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr t-foreach="grupo.cajas" t-as="caja" t-key="caja.id">
|
||||
<td><b t-esc="caja.nombre"/></td>
|
||||
<td>
|
||||
<!-- Un punto basta: escribir
|
||||
«abierta» al lado del verde es
|
||||
decir lo mismo dos veces. -->
|
||||
<span class="beyond_punto"
|
||||
t-att-class="caja.abierta ? 'beyond_abierta' : 'beyond_cerrada'"/>
|
||||
<span t-if="caja.abierta" class="text-muted small">
|
||||
desde <t t-esc="caja.desde"/>
|
||||
</span>
|
||||
<span t-elif="caja.cerrada_el" class="text-muted small">
|
||||
cerró <t t-esc="caja.cerrada_el"/>
|
||||
</span>
|
||||
<span t-else="" class="text-muted small">sin abrir</span>
|
||||
</td>
|
||||
<td class="text-muted" t-esc="caja.quien or '—'"/>
|
||||
<td class="text-end fw-bold" t-esc="dinero(caja.ventas)"/>
|
||||
<td class="text-end" t-esc="numero(caja.tickets)"/>
|
||||
<td class="text-end">
|
||||
<button class="btn btn-sm btn-outline-secondary"
|
||||
t-on-click="() => this.verHistoricoDe(caja)">
|
||||
Ver movimiento
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
</t>
|
||||
|
||||
<!-- ══ 2 · Histórico ══ -->
|
||||
<t t-if="state.pantalla === 'historico'">
|
||||
<div class="d-flex flex-wrap align-items-center gap-2 mb-3">
|
||||
<button class="btn btn-link px-0" t-on-click="volverACajas">
|
||||
<i class="fa fa-arrow-left me-1"/>Cajas
|
||||
</button>
|
||||
<h2 class="mb-0 ms-2">Histórico</h2>
|
||||
</div>
|
||||
|
||||
<!-- Un solo juego de filtros para las tres pestañas -->
|
||||
<div class="card card-body flex-row flex-wrap gap-3 align-items-end mb-3">
|
||||
<div>
|
||||
<label class="form-label mb-1">Periodo</label>
|
||||
<div class="btn-group d-block">
|
||||
<t t-foreach="[[7,'7 días'],[30,'30 días'],[90,'90 días'],[365,'Un año']]"
|
||||
t-as="rango" t-key="rango[0]">
|
||||
<button class="btn btn-sm"
|
||||
t-att-class="state.filtros.dias === rango[0] ? 'btn-primary' : 'btn-outline-secondary'"
|
||||
t-on-click="() => this.filtrar('dias', rango[0])"
|
||||
t-esc="rango[1]"/>
|
||||
</t>
|
||||
</div>
|
||||
</div>
|
||||
<div t-if="state.historico?.opciones.puede_elegir_sucursal">
|
||||
<label class="form-label mb-1">Sucursal</label>
|
||||
<select class="form-select" t-on-change="cambiarSucursal">
|
||||
<option value="">Todas</option>
|
||||
<option t-foreach="state.historico.opciones.sucursales"
|
||||
t-as="sucursal" t-key="sucursal.id"
|
||||
t-att-value="sucursal.id"
|
||||
t-att-selected="state.filtros.branch_id === sucursal.id"
|
||||
t-esc="sucursal.nombre"/>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="form-label mb-1">Caja</label>
|
||||
<select class="form-select" t-on-change="cambiarCaja">
|
||||
<option value="">Todas</option>
|
||||
<option t-foreach="cajasElegibles" t-as="caja" t-key="caja.id"
|
||||
t-att-value="caja.id"
|
||||
t-att-selected="state.filtros.config_id === caja.id"
|
||||
t-esc="caja.nombre"/>
|
||||
</select>
|
||||
</div>
|
||||
<div class="flex-grow-1">
|
||||
<label class="form-label mb-1">Buscar</label>
|
||||
<input type="search" class="form-control"
|
||||
placeholder="Folio o cliente" t-on-input="onBuscar"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div t-if="state.cargando" class="text-muted">Cargando…</div>
|
||||
<t t-else="">
|
||||
<div class="row g-3 mb-3">
|
||||
<div class="col-6 col-lg-3">
|
||||
<div class="card card-body beyond_cifra">
|
||||
<div class="beyond_valor" t-esc="numero(state.historico.cifras.ordenes)"/>
|
||||
<div class="text-muted small">órdenes</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-6 col-lg-3">
|
||||
<div class="card card-body beyond_cifra">
|
||||
<div class="beyond_valor" t-esc="dinero(state.historico.cifras.total)"/>
|
||||
<div class="text-muted small">total cobrado</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 col-lg-6">
|
||||
<div class="card card-body">
|
||||
<div class="text-muted small mb-1">por método de pago</div>
|
||||
<div class="d-flex flex-wrap gap-3">
|
||||
<span t-foreach="state.historico.cifras.metodos"
|
||||
t-as="metodo" t-key="metodo.nombre">
|
||||
<b t-esc="dinero(metodo.monto)"/>
|
||||
<span class="text-muted small ms-1" t-esc="metodo.nombre"/>
|
||||
</span>
|
||||
<span t-if="!state.historico.cifras.metodos.length"
|
||||
class="text-muted">Sin cobros en el periodo</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ul class="nav nav-tabs mb-3">
|
||||
<t t-foreach="[['ordenes','Órdenes'],['sesiones','Sesiones y cortes'],['pagos','Pagos']]"
|
||||
t-as="pestana" t-key="pestana[0]">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#"
|
||||
t-att-class="state.pestana === pestana[0] ? 'active' : ''"
|
||||
t-on-click.prevent="() => this.state.pestana = pestana[0]"
|
||||
t-esc="pestana[1]"/>
|
||||
</li>
|
||||
</t>
|
||||
</ul>
|
||||
|
||||
<div t-if="state.pestana === 'ordenes'" class="table-responsive">
|
||||
<table class="table table-hover align-middle beyond_tabla">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Folio</th><th>Cuándo</th><th>Sucursal</th>
|
||||
<th>Caja</th><th>Cliente</th><th>Atendió</th>
|
||||
<th>Pago</th><th class="text-end">Total</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr t-foreach="state.historico.ordenes" t-as="fila" t-key="fila.id">
|
||||
<td class="beyond_folio" t-esc="fila.folio"/>
|
||||
<td class="text-muted small" t-esc="fila.fecha"/>
|
||||
<td class="text-muted" t-esc="fila.sucursal"/>
|
||||
<td class="text-muted" t-esc="fila.caja"/>
|
||||
<td t-esc="fila.cliente"/>
|
||||
<td class="text-muted" t-esc="fila.atendio"/>
|
||||
<td class="text-muted small" t-esc="fila.metodos"/>
|
||||
<td class="text-end fw-bold" t-esc="dinero(fila.total)"/>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div t-if="!state.historico.ordenes.length" class="alert alert-info">
|
||||
Sin órdenes con esos filtros.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div t-if="state.pestana === 'sesiones'" class="table-responsive">
|
||||
<table class="table table-hover align-middle beyond_tabla">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Caja</th><th>Sucursal</th><th>Apertura</th>
|
||||
<th>Cierre</th><th>Quién</th>
|
||||
<th class="text-end">Esperado</th>
|
||||
<th class="text-end">Contado</th>
|
||||
<th class="text-end">Diferencia</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr t-foreach="state.historico.sesiones" t-as="fila" t-key="fila.id">
|
||||
<td><b t-esc="fila.caja"/></td>
|
||||
<td class="text-muted" t-esc="fila.sucursal"/>
|
||||
<td class="text-muted small" t-esc="fila.apertura"/>
|
||||
<td class="text-muted small">
|
||||
<t t-if="fila.abierta"><span class="badge text-bg-success">abierta</span></t>
|
||||
<t t-else="" t-esc="fila.cierre"/>
|
||||
</td>
|
||||
<td class="text-muted" t-esc="fila.quien"/>
|
||||
<td class="text-end" t-esc="dinero(fila.esperado)"/>
|
||||
<td class="text-end" t-esc="dinero(fila.contado)"/>
|
||||
<td class="text-end" t-att-class="claseDiferencia(fila.diferencia)"
|
||||
t-esc="dinero(fila.diferencia)"/>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div t-if="!state.historico.sesiones.length" class="alert alert-info">
|
||||
Sin sesiones en el periodo.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div t-if="state.pestana === 'pagos'" class="table-responsive">
|
||||
<table class="table align-middle beyond_tabla">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Método</th>
|
||||
<th class="text-end">Cobros</th>
|
||||
<th class="text-end">Monto</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr t-foreach="state.historico.pagos" t-as="fila" t-key="fila.nombre">
|
||||
<td><b t-esc="fila.nombre"/></td>
|
||||
<td class="text-end" t-esc="numero(fila.cobros)"/>
|
||||
<td class="text-end fw-bold" t-esc="dinero(fila.monto)"/>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div t-if="!state.historico.pagos.length" class="alert alert-info">
|
||||
Sin cobros con esos filtros.
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
</t>
|
||||
|
||||
</div>
|
||||
</t>
|
||||
</templates>
|
||||
Reference in new issue
Block a user