# 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']