19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:32:12 +01:00
parent 79f83631d5
commit 73afc09215
6267 changed files with 1534193 additions and 1130106 deletions

View file

@ -5,20 +5,59 @@ from odoo import _, api, models, fields
from odoo.exceptions import ValidationError
class EventConfigurator(models.TransientModel):
class EventEventConfigurator(models.TransientModel):
_name = 'event.event.configurator'
_description = 'Event Configurator'
product_id = fields.Many2one('product.product', string="Product", readonly=True)
event_id = fields.Many2one('event.event', string="Event")
event_ticket_id = fields.Many2one('event.event.ticket', string="Event Ticket")
event_slot_id = fields.Many2one('event.slot', string="Slot", domain="[('event_id', '=', event_id)]",
compute="_compute_event_slot_id", readonly=False, store=True)
event_ticket_id = fields.Many2one('event.event.ticket', string="Ticket Type", domain="[('event_id', '=', event_id)]",
compute="_compute_event_ticket_id", readonly=False, store=True)
is_multi_slots = fields.Boolean(related="event_id.is_multi_slots")
has_available_tickets = fields.Boolean("Has Available Tickets", compute="_compute_has_available_tickets")
@api.constrains('event_id', 'event_ticket_id')
@api.constrains('event_id', 'event_slot_id', 'event_ticket_id')
def check_event_id(self):
error_messages = []
for record in self:
if record.event_id.id != record.event_ticket_id.event_id.id:
error_messages.append(
_('Invalid ticket choice "%(ticket_name)s" for event "%(event_name)s".'))
if record.event_slot_id and record.event_id.id != record.event_slot_id.event_id.id:
error_messages.append(
_('Invalid slot choice "%(slot_name)s" for event "%(event_name)s".'))
if error_messages:
raise ValidationError('\n'.join(error_messages))
@api.depends('product_id')
def _compute_has_available_tickets(self):
product_ticket_data = self.env['event.event.ticket']._read_group([
('product_id', 'in', self.product_id.ids),
('event_id.date_end', '>=', fields.Date.today())],
['product_id'],
['__count'])
mapped_data = {product: ticket_count for product, ticket_count in product_ticket_data}
for configurator in self:
configurator.has_available_tickets = bool(mapped_data.get(configurator.product_id, 0))
@api.depends("is_multi_slots")
def _compute_event_slot_id(self):
""" Pre-select the slot of the multi slots event selected if it is the only one """
for configurator in self:
if not configurator.is_multi_slots:
configurator.event_slot_id = False
else:
event_slot_ids = self.env['event.slot'].search([
('event_id', '=', configurator.event_id.id)], limit=2)
configurator.event_slot_id = event_slot_ids if len(event_slot_ids) == 1 else False
@api.depends('event_id')
def _compute_event_ticket_id(self):
""" Pre-select the ticket of the event selected if it is the only one """
for configurator in self:
event_ticket_ids = self.env['event.event.ticket'].search([
('event_id', '=', configurator.event_id.id),
('product_id', '=', configurator.product_id.id)], limit=2)
configurator.event_ticket_id = event_ticket_ids if len(event_ticket_ids) == 1 else False

View file

@ -5,7 +5,15 @@
<field name="model">event.event.configurator</field>
<field name="arch" type="xml">
<form js_class="event_configurator_form">
<group>
<field name="has_available_tickets" invisible="1"/>
<div invisible="has_available_tickets">
We could not find a matching event ticket for this product. <br/>
<a role="button" class="btn btn-link" target="_blank"
href="/odoo/action-event.action_event_view">
<i class="fa fa-arrow-right"/> Configure Events &amp; Tickets
</a>
</div>
<group invisible="not has_available_tickets">
<field
name="event_id"
domain="[
@ -15,29 +23,37 @@
required="1"
context="{'name_with_seats_availability': True}"
options="{'no_open': True, 'no_create': True}"
placeholder="All Events"
/>
<field name="event_slot_id"
domain="[('event_id', '=', event_id)]"
invisible="not is_multi_slots"
required="is_multi_slots"
context="{'name_with_seats_availability': True}"
options="{'no_open': True, 'no_create': True}"/>
<field
name="event_ticket_id"
domain="[('event_id', '=', event_id), ('product_id', '=', product_id)]"
attrs="{
'invisible': [('event_id', '=', False)],
'required': [('event_id', '!=', False)],
}"
invisible="not event_id"
required="event_id"
context="{'name_with_seats_availability': True}"
options="{'no_open': True, 'no_create': True}"
/>
options="{'no_open': True, 'no_create': True}"/>
<field name="product_id" invisible="1"/>
</group>
<footer>
<button string="Ok" class="btn-primary o_event_sale_js_event_configurator_ok" special="save" data-hotkey="v"/>
<button string="Cancel" class="btn-secondary" special="cancel" data-hotkey="z"/>
<button string="Add" invisible="not has_available_tickets"
class="btn-primary o_event_sale_js_event_configurator_ok" special="save" data-hotkey="q"/>
<button string="Discard" invisible="not has_available_tickets"
class="btn-secondary" special="cancel" data-hotkey="x"/>
<button string="Close" invisible="has_available_tickets"
class="btn-secondary" special="cancel" data-hotkey="x"/>
</footer>
</form>
</field>
</record>
<record id="event_configurator_action" model="ir.actions.act_window">
<field name="name">Configure an event</field>
<field name="name">Select an Event</field>
<field name="res_model">event.event.configurator</field>
<field name="view_mode">form</field>
<field name="target">new</field>

View file

@ -7,79 +7,51 @@ from odoo.exceptions import ValidationError
class RegistrationEditor(models.TransientModel):
_name = "registration.editor"
_name = 'registration.editor'
_description = 'Edit Attendee Details on Sales Confirmation'
sale_order_id = fields.Many2one('sale.order', 'Sales Order', required=True, ondelete='cascade')
event_registration_ids = fields.One2many('registration.editor.line', 'editor_id', string='Registrations to Edit')
seats_available_insufficient = fields.Boolean(
'Not enough seats for all registrations', compute='_compute_seats_available_insufficient', readonly=True)
@api.depends('event_registration_ids')
def _compute_seats_available_insufficient(self):
for editor in self:
editor.seats_available_insufficient = False
events_counts = Counter()
event_tickets_counts = defaultdict(Counter)
for registration in editor.event_registration_ids:
events_counts[registration.event_id] += 1
event_tickets_counts[registration.event_id][registration.event_ticket_id] += 1
for event, nb_seats_event in events_counts.items():
# Check nb of seats in each event for all registrations on sale order
try:
event._check_seats_availability(nb_seats_event)
except ValidationError:
editor.seats_available_insufficient = True
break
# Check nb of seats for each ticket of the event for all registrations on sale order
for ticket, nb_seats_ticket in event_tickets_counts[event].items():
try:
ticket._check_seats_availability(nb_seats_ticket)
except ValidationError:
editor.seats_available_insufficient = True
break
if editor.seats_available_insufficient:
break
@api.model
def default_get(self, fields):
res = super(RegistrationEditor, self).default_get(fields)
if not res.get('sale_order_id'):
sale_order_id = res.get('sale_order_id', self._context.get('active_id'))
sale_order_id = res.get('sale_order_id', self.env.context.get('active_id'))
res['sale_order_id'] = sale_order_id
sale_order = self.env['sale.order'].browse(res.get('sale_order_id'))
registrations = self.env['event.registration'].search([
('sale_order_id', '=', sale_order.id),
('event_slot_id', 'in', sale_order.mapped('order_line.event_slot_id').ids or [False]),
('event_ticket_id', 'in', sale_order.mapped('order_line.event_ticket_id').ids),
('state', '!=', 'cancel')])
so_lines = sale_order.order_line.filtered('event_ticket_id')
so_line_to_reg = registrations.grouped('sale_order_line_id')
attendee_list = []
for so_line in [l for l in sale_order.order_line if l.event_ticket_id]:
existing_registrations = [r for r in registrations if r.event_ticket_id == so_line.event_ticket_id and r.sale_order_line_id == so_line]
for reg in existing_registrations:
attendee_list.append([0, 0, {
'event_id': reg.event_id.id,
'event_ticket_id': reg.event_ticket_id.id,
'registration_id': reg.id,
'name': reg.name,
'email': reg.email,
'phone': reg.phone,
'mobile': reg.mobile,
'sale_order_line_id': so_line.id,
}])
for count in range(int(so_line.product_uom_qty) - len(existing_registrations)):
attendee_list.append([0, 0, {
'event_id': so_line.event_id.id,
'event_ticket_id': so_line.event_ticket_id.id,
'sale_order_line_id': so_line.id,
'name': so_line.order_partner_id.name,
'email': so_line.order_partner_id.email,
'phone': so_line.order_partner_id.phone,
'mobile': so_line.order_partner_id.mobile,
}])
for so_line in so_lines:
registrations = so_line_to_reg.get(so_line, self.env['event.registration'])
# Add existing registrations
attendee_list += [[0, 0, {
'event_id': reg.event_id.id,
'event_slot_id': reg.event_slot_id.id,
'event_ticket_id': reg.event_ticket_id.id,
'registration_id': reg.id,
'name': reg.name,
'email': reg.email,
'phone': reg.phone,
'sale_order_line_id': so_line.id,
}] for reg in registrations]
# Add new registrations
attendee_list += [[0, 0, {
'event_id': so_line.event_id.id,
'event_slot_id': so_line.event_slot_id.id,
'event_ticket_id': so_line.event_ticket_id.id,
'sale_order_line_id': so_line.id,
'name': so_line.order_partner_id.name,
'email': so_line.order_partner_id.email,
'phone': so_line.order_partner_id.phone,
}] for _count in range(int(so_line.product_uom_qty) - len(registrations))]
res['event_registration_ids'] = attendee_list
res = self._convert_to_write(res)
return res
@ -88,45 +60,48 @@ class RegistrationEditor(models.TransientModel):
self.ensure_one()
registrations_to_create = []
for registration_line in self.event_registration_ids:
values = registration_line.get_registration_data()
if registration_line.registration_id:
registration_line.registration_id.write(values)
registration_line.registration_id.write(registration_line._prepare_registration_data())
else:
registrations_to_create.append(values)
registrations_to_create.append(registration_line._prepare_registration_data(include_event_values=True))
self.env['event.registration'].create(registrations_to_create)
self.sale_order_id.order_line._update_registrations(
confirm=self.sale_order_id.amount_total == 0 and not self.seats_available_insufficient)
# Force compute after wizard so seat validation/emails happen now.
self.event_registration_ids.registration_id._compute_registration_status()
return {'type': 'ir.actions.act_window_close'}
class RegistrationEditorLine(models.TransientModel):
"""Event Registration"""
_name = "registration.editor.line"
_name = 'registration.editor.line'
_description = 'Edit Attendee Line on Sales Confirmation'
_order = "id desc"
editor_id = fields.Many2one('registration.editor')
sale_order_line_id = fields.Many2one('sale.order.line', string='Sales Order Line')
event_id = fields.Many2one('event.event', string='Event', required=True)
company_id = fields.Many2one(related="event_id.company_id")
registration_id = fields.Many2one('event.registration', 'Original Registration')
event_slot_id = fields.Many2one('event.slot', string='Event Slot')
event_ticket_id = fields.Many2one('event.event.ticket', string='Event Ticket')
email = fields.Char(string='Email')
phone = fields.Char(string='Phone')
mobile = fields.Char(string='Mobile')
name = fields.Char(string='Name')
def get_registration_data(self):
def _prepare_registration_data(self, include_event_values=False):
self.ensure_one()
return {
'event_id': self.event_id.id,
'event_ticket_id': self.event_ticket_id.id,
registration_data = {
'partner_id': self.editor_id.sale_order_id.partner_id.id,
'name': self.name or self.editor_id.sale_order_id.partner_id.name,
'phone': self.phone or self.editor_id.sale_order_id.partner_id.phone,
'mobile': self.mobile or self.editor_id.sale_order_id.partner_id.mobile,
'email': self.email or self.editor_id.sale_order_id.partner_id.email,
'sale_order_id': self.editor_id.sale_order_id.id,
'sale_order_line_id': self.sale_order_line_id.id,
}
if include_event_values:
registration_data.update({
'event_id': self.event_id.id,
'event_slot_id': self.event_slot_id.id,
'event_ticket_id': self.event_ticket_id.id,
'sale_order_id': self.editor_id.sale_order_id.id,
'sale_order_line_id': self.sale_order_line_id.id,
})
return registration_data

View file

@ -6,31 +6,25 @@
<field name="model">registration.editor</field>
<field name="arch" type="xml">
<form string="Registration">
<field name="seats_available_insufficient" invisible="1"/>
<div class="alert alert-warning m-0" role="alert" attrs="{'invisible': [('seats_available_insufficient', '=', False)]}">
<p class="my-0">
<span>Not enough seats available. All registrations were created as "Unconfirmed" and can be updated later on.</span>
</p>
</div>
<sheet>
<p>Before updating the linked registrations of <field name="sale_order_id" readonly="1" class="oe_inline"/>
please give attendee details.</p>
please provide attendee details.</p>
<field name="event_registration_ids">
<tree string="Registration" editable="top" create="false" delete="false">
<list string="Registration" editable="top" create="false" delete="false">
<field name="event_id" readonly='1' force_save="1"/>
<field name="registration_id" readonly='1' force_save="1"/>
<field name="event_slot_id" domain="[('event_id', '=', event_id)]" readonly='1' force_save="1"/>
<field name="event_ticket_id" domain="[('event_id', '=', event_id)]" readonly='1' force_save="1"/>
<field name="name"/>
<field name="email"/>
<field name="mobile" class="o_force_ltr"/>
<field name="phone" class="o_force_ltr"/>
<field name="sale_order_line_id" invisible="1"/>
</tree>
<field name="company_id" groups="base.group_multi_company" optional="hide"/>
<field name="sale_order_line_id" column_invisible="True"/>
</list>
</field>
</sheet>
<footer>
<button string="Create/Update registrations" name="action_make_registration" type="object" class="btn-primary" data-hotkey="q"/>
<button string="Skip" class="btn-secondary" special="cancel" data-hotkey="z"/>
</footer>
</form>
</field>
@ -38,7 +32,6 @@
<record id="action_sale_order_event_registration" model="ir.actions.act_window">
<field name="name">Event Registrations</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">registration.editor</field>
<field name="view_mode">form</field>
<field name="view_id" ref="view_event_registration_editor_form"/>