Sistema de gestión multisucursal sobre Odoo 19 Community: módulos matrix_*, guiones de alta de instalaciones, suite de pruebas y documentación.
84 lines
4.0 KiB
Python
84 lines
4.0 KiB
Python
# Part of Matrix. Collina Systems proprietary module.
|
||
"""Price range for services that have a floor and a ceiling, not a price.
|
||
|
||
Some salon services are like this (a hairdo priced from $500 to $900, say).
|
||
They used to be loaded at the range minimum as if it were a fixed price, and
|
||
the register offered nothing: charging the $900 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 `matrix_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(
|
||
{'matrix_precio_min', 'matrix_precio_max', 'matrix_precio_paso'})
|
||
|
||
|
||
class ProductTemplate(models.Model):
|
||
_inherit = 'product.template'
|
||
|
||
matrix_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.')
|
||
matrix_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.')
|
||
matrix_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 _matrix_tiene_rango(self):
|
||
self.ensure_one()
|
||
return self.matrix_precio_max > 0
|
||
|
||
@api.constrains('matrix_precio_min', 'matrix_precio_max',
|
||
'matrix_precio_paso', 'list_price')
|
||
def _check_matrix_rango(self):
|
||
for template in self:
|
||
if not template._matrix_tiene_rango():
|
||
continue
|
||
if template.matrix_precio_min < 0:
|
||
raise ValidationError(_('El mínimo del rango no puede ser negativo.'))
|
||
if template.matrix_precio_max <= template.matrix_precio_min:
|
||
raise ValidationError(_(
|
||
'El máximo del rango (%(maximo)s) tiene que ser mayor que '
|
||
'el mínimo (%(minimo)s).',
|
||
maximo=template.matrix_precio_max,
|
||
minimo=template.matrix_precio_min))
|
||
if template.matrix_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.matrix_precio_min <= template.list_price
|
||
<= template.matrix_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.matrix_precio_min,
|
||
maximo=template.matrix_precio_max))
|
||
|
||
@api.model
|
||
def _load_pos_data_fields(self, config):
|
||
"""The register needs the range to open the slider and bound it."""
|
||
# `matrix_especial` viaja para que la caja excluya de la
|
||
# atribución lo mismo que excluye el servidor (ADR-051): sin la
|
||
# marca, el cliente exigiría gente para un anticipo que el
|
||
# servidor no exige, o al revés — dos criterios que se separan.
|
||
return super()._load_pos_data_fields(config) + [
|
||
'matrix_precio_min', 'matrix_precio_max', 'matrix_precio_paso',
|
||
'matrix_especial']
|