Files
BEYOND/addons/beyond_branch/models/product_rango.py
T
Jorem JuárezandClaude Fable 5 bf33a68e5c Selector de rango en la caja: deslizador acotado con monto editable
Tres servicios de la lista de Puebla no tienen un precio sino un piso y un
techo (peinado social $600–$1,250, diseño intermedio $180–$220, diseño full
$250–$450). Estaban cargados al mínimo como precio fijo, la pantalla no
decía que pudiera ser más, y la captura libre no tenía tope: nada impedía
teclear $5,000 (pendiente #32 del libro). Decisión del 4-sep-2026: opción C
— deslizador que avanza en el paso del servicio, con el monto en una
ventana editable; a mano se admite cualquier monto, pero SOLO dentro del
rango. Paso $50 en los tres por instrucción del cliente ("$50 siempre"); el
paso es un campo por servicio, así que cambiar el del diseño intermedio a
$10 es un dato, no código.

Tres piezas:

- beyond_branch: `beyond_precio_min/max/paso` en product.template, campos
  de RED (CAMPOS_ESTRUCTURALES, mismo candado que el precio base). Rango
  activo cuando max > 0; el precio base debe caer dentro —es lo que la caja
  prellena— y viajan al POS por _load_pos_data_fields.
- beyond_pos_theme (UI): diálogo OWL sobre `addLineToCurrentOrder`, la
  puerta única por la que entran el clic en la tarjeta y el buscador.
  Cancelar no agrega; confirmar fija `price_unit`, que el core marca manual
  y no fusiona — dos peinados pueden costar distinto. El deslizador pega el
  último tramo al techo: con rango 180–220 y paso 50 el elemento nativo
  dejaría el máximo inalcanzable.
- beyond_pos_theme (guardia): constraint en pos.order.line. El deslizador
  es pintura; `sync_from_ui` recibe lo que le manden —el modo precio del
  teclado numérico incluido— y un precio fuera del rango se rechaza en el
  servidor. Las devoluciones quedan exentas: copian el precio del ticket
  original y deben seguirlo aunque el rango cambie después.

Pruebas, todas vistas en rojo (se apagaron los dos guardias y se quitó el
disabled del XML; cada sabotaje lo atrapó su prueba):

- Modelo: rango válido, sin máximo no se exige nada, max>min, paso
  obligatorio, base dentro del rango, y el candado de red (gerente
  bloqueado, dirección no). El test-censo de CAMPOS_ESTRUCTURALES exigió
  cubrir los tres campos, como está diseñado para hacer.
- Cobro por la MISMA puerta que la caja (`sync_from_ui`, con atribución):
  dentro del rango cobra ($600, $850, $1,250), fuera se rechaza ($5,000,
  $12, $599, $1,250.01), y la contraparte — sin rango el precio sigue
  libre, para que un guardia que rechazara todo no pase por bueno.
- Lo que solo existe en el navegador, por el patrón sancionado del POS
  (guardia que lee el código, como test_theme_assets): assets en el bundle,
  deslizador con min/max/paso, ventana editable, confirmar apagado fuera
  del rango, y el parche colgado de la puerta única respetando un
  price_unit ya fijado.

Los rangos ya están puestos en beyond_dev por ID externo (BEY-SERV-040/
086/087). En beyond_prod se cargan igual cuando se decida; el libro
(pendiente #32) queda por actualizar en su rama.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-04 11:40:55 -06:00

79 lines
3.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Part of Beyond. Collina Systems proprietary module.
"""Price range for services that have a floor and a ceiling, not a price.
Three services of the Puebla list are like this (peinado social $600-$1,250,
diseño intermedio $180-$220, diseño full $250-$450). They were loaded at the
range minimum as if it were a fixed price, and the register offered nothing:
charging the $1,250 hairdo relied on the cashier remembering to raise it by
hand, and the free capture had no ceiling — nothing prevented typing $5,000.
The range lives on the product (network data, like the base price): the POS
opens a slider dialog when the product has one, and the server rejects any
line priced outside it. A range is active when `beyond_precio_max > 0`.
"""
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
from .product_models import CAMPOS_ESTRUCTURALES
# The range governs what every register in the network may charge: same
# criterion as list_price (ADR-009), so only the general admin moves it.
CAMPOS_ESTRUCTURALES.update(
{'beyond_precio_min', 'beyond_precio_max', 'beyond_precio_paso'})
class ProductTemplate(models.Model):
_inherit = 'product.template'
beyond_precio_min = fields.Float(
string='Precio mínimo del rango', default=0.0,
help='Piso del rango de cobro, con IVA incluido. Solo cuenta si el '
'máximo está definido.')
beyond_precio_max = fields.Float(
string='Precio máximo del rango', default=0.0,
help='Techo del rango de cobro, con IVA incluido. En cero, el '
'artículo se cobra a precio fijo y nada de esto aplica.')
beyond_precio_paso = fields.Float(
string='Paso del selector', default=0.0,
help='De cuánto en cuánto avanza el deslizador de la caja. La '
'captura a mano admite cualquier monto dentro del rango.')
def _beyond_tiene_rango(self):
self.ensure_one()
return self.beyond_precio_max > 0
@api.constrains('beyond_precio_min', 'beyond_precio_max',
'beyond_precio_paso', 'list_price')
def _check_beyond_rango(self):
for template in self:
if not template._beyond_tiene_rango():
continue
if template.beyond_precio_min < 0:
raise ValidationError(_('El mínimo del rango no puede ser negativo.'))
if template.beyond_precio_max <= template.beyond_precio_min:
raise ValidationError(_(
'El máximo del rango (%(maximo)s) tiene que ser mayor que '
'el mínimo (%(minimo)s).',
maximo=template.beyond_precio_max,
minimo=template.beyond_precio_min))
if template.beyond_precio_paso <= 0:
raise ValidationError(_(
'Un artículo con rango necesita el paso del selector.'))
# The base price is what the register pre-fills: outside the
# range, the very first line would already violate the range.
if not (template.beyond_precio_min <= template.list_price
<= template.beyond_precio_max):
raise ValidationError(_(
'El precio base (%(precio)s) tiene que caer dentro del '
'rango %(minimo)s–%(maximo)s: es el monto con el que la '
'caja arranca.',
precio=template.list_price,
minimo=template.beyond_precio_min,
maximo=template.beyond_precio_max))
@api.model
def _load_pos_data_fields(self, config):
"""The register needs the range to open the slider and bound it."""
return super()._load_pos_data_fields(config) + [
'beyond_precio_min', 'beyond_precio_max', 'beyond_precio_paso']