- Añadir reglas de acceso para group.order.slot en ir.model.access.csv - Añadir pestaña "Pickup Slots" en el formulario de group.order con lista editable (handle de secuencia, día, etiqueta, hora inicio/fin, activo) - Corregir valores del campo weekday: de dígitos numéricos a nombres de día (Monday...Sunday) para mejor usabilidad Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
74 lines
2.1 KiB
Python
74 lines
2.1 KiB
Python
# Copyright 2026 Criptomart
|
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
|
|
|
|
from odoo import fields
|
|
from odoo import models
|
|
|
|
# Pylint: explicit 'string' attributes are intentional for readable labels in views.
|
|
# Some linters flag these as redundant; disable that specific check here.
|
|
# pylint: disable=attribute-string-redundant
|
|
|
|
|
|
class GroupOrderSlot(models.Model):
|
|
_name = "group.order.slot"
|
|
_description = "Pickup slot for a Consumer Group Order"
|
|
_order = "sequence, weekday, start_hour"
|
|
|
|
group_order_id = fields.Many2one(
|
|
"group.order",
|
|
string="Group Order",
|
|
required=True,
|
|
ondelete="cascade",
|
|
help="Consumer group order this slot belongs to",
|
|
)
|
|
|
|
weekday = fields.Selection(
|
|
[
|
|
("0", "Monday"),
|
|
("1", "Tuesday"),
|
|
("2", "Wednesday"),
|
|
("3", "Thursday"),
|
|
("4", "Friday"),
|
|
("5", "Saturday"),
|
|
("6", "Sunday"),
|
|
],
|
|
string="Weekday",
|
|
required=True,
|
|
help="Day of week for this slot (0=Monday)",
|
|
)
|
|
|
|
start_hour = fields.Float(
|
|
string="Start hour",
|
|
help="Start hour in decimal form, e.g. 9.5 = 09:30",
|
|
)
|
|
|
|
end_hour = fields.Float(
|
|
string="End hour",
|
|
help="End hour in decimal form, e.g. 14.25 = 14:15",
|
|
)
|
|
|
|
label = fields.Char(
|
|
string="Label",
|
|
help="Human readable short label for the slot (optional)",
|
|
)
|
|
|
|
sequence = fields.Integer(string="Sequence", default=10)
|
|
|
|
active = fields.Boolean(default=True)
|
|
|
|
def _get_display_label(self):
|
|
"""Return a fallback display label combining weekday and hours.
|
|
|
|
This is a small helper used by views or when a specific `label` is
|
|
not provided.
|
|
"""
|
|
self.ensure_one()
|
|
if self.label:
|
|
return self.label
|
|
# Fallback: simple numeric representation
|
|
sh = "%02d:%02d" % (
|
|
int(self.start_hour or 0),
|
|
int((self.start_hour or 0) % 1 * 60),
|
|
)
|
|
eh = "%02d:%02d" % (int(self.end_hour or 0), int((self.end_hour or 0) % 1 * 60))
|
|
return f"{self.weekday} {sh}-{eh}"
|