diff options
Diffstat (limited to 'addons/event_sale/wizard')
| -rw-r--r-- | addons/event_sale/wizard/__init__.py | 2 | ||||
| -rw-r--r-- | addons/event_sale/wizard/event_configurator.py | 13 | ||||
| -rw-r--r-- | addons/event_sale/wizard/event_configurator_views.xml | 48 | ||||
| -rw-r--r-- | addons/event_sale/wizard/event_edit_registration.py | 97 | ||||
| -rw-r--r-- | addons/event_sale/wizard/event_edit_registration.xml | 40 |
5 files changed, 200 insertions, 0 deletions
diff --git a/addons/event_sale/wizard/__init__.py b/addons/event_sale/wizard/__init__.py new file mode 100644 index 00000000..b2eda10b --- /dev/null +++ b/addons/event_sale/wizard/__init__.py @@ -0,0 +1,2 @@ +from . import event_edit_registration +from . import event_configurator diff --git a/addons/event_sale/wizard/event_configurator.py b/addons/event_sale/wizard/event_configurator.py new file mode 100644 index 00000000..97fbe652 --- /dev/null +++ b/addons/event_sale/wizard/event_configurator.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models, fields + + +class EventConfigurator(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") diff --git a/addons/event_sale/wizard/event_configurator_views.xml b/addons/event_sale/wizard/event_configurator_views.xml new file mode 100644 index 00000000..db1399cd --- /dev/null +++ b/addons/event_sale/wizard/event_configurator_views.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="utf-8"?> +<odoo> + <record id="event_configurator_view_form" model="ir.ui.view"> + <field name="name">event.configurator.view.form</field> + <field name="model">event.event.configurator</field> + <field name="arch" type="xml"> + <form js_class="event_configurator_form"> + <group> + <field + name="event_id" + domain="[ + ('event_ticket_ids.product_id','=', product_id), + ('date_end','>=',time.strftime('%Y-%m-%d 00:00:00')) + ]" + required="1" + options="{'no_open': True, 'no_create': True}" + /> + <field + name="event_ticket_id" + domain="[ + ('event_id', '=', event_id), + ('product_id','=',product_id), + '|', ('seats_limited', '=', False), ('seats_available', '>', 0) + ]" + attrs="{ + 'invisible': [('event_id', '=', False)], + 'required': [('event_id', '!=', False)], + }" + 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"/> + <button string="Cancel" class="btn-secondary" special="cancel"/> + </footer> + </form> + </field> + </record> + + <record id="event_configurator_action" model="ir.actions.act_window"> + <field name="name">Configure an event</field> + <field name="res_model">event.event.configurator</field> + <field name="view_mode">form</field> + <field name="target">new</field> + <field name="view_id" ref="event_configurator_view_form"/> + </record> +</odoo> diff --git a/addons/event_sale/wizard/event_edit_registration.py b/addons/event_sale/wizard/event_edit_registration.py new file mode 100644 index 00000000..575bb1af --- /dev/null +++ b/addons/event_sale/wizard/event_edit_registration.py @@ -0,0 +1,97 @@ +# -*- coding: utf-8 -*- + +from odoo import models, fields, api + + +class RegistrationEditor(models.TransientModel): + _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') + + @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')) + 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_ticket_id', 'in', sale_order.mapped('order_line.event_ticket_id').ids), + ('state', '!=', 'cancel')]) + + 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] + 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, + }]) + res['event_registration_ids'] = attendee_list + res = self._convert_to_write(res) + return res + + def action_make_registration(self): + 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) + else: + registrations_to_create.append(values) + + self.env['event.registration'].create(registrations_to_create) + self.sale_order_id.order_line._update_registrations(confirm=self.sale_order_id.amount_total == 0) + + return {'type': 'ir.actions.act_window_close'} + + +class RegistrationEditorLine(models.TransientModel): + """Event Registration""" + _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) + registration_id = fields.Many2one('event.registration', 'Original Registration') + 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', index=True) + + def get_registration_data(self): + self.ensure_one() + return { + 'event_id': self.event_id.id, + 'event_ticket_id': self.event_ticket_id.id, + '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, + } diff --git a/addons/event_sale/wizard/event_edit_registration.xml b/addons/event_sale/wizard/event_edit_registration.xml new file mode 100644 index 00000000..897bf343 --- /dev/null +++ b/addons/event_sale/wizard/event_edit_registration.xml @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="utf-8"?> +<odoo> + + <record id="view_event_registration_editor_form" model="ir.ui.view"> + <field name="name">registration.editor.form</field> + <field name="model">registration.editor</field> + <field name="arch" type="xml"> + <form string="Registration"> + <p>Before confirming <field name="sale_order_id" readonly="1" class="oe_inline"/> + please give details about the registrations</p> + <field name="event_registration_ids"> + <tree 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_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> + <footer> + <button string="Confirm" name="action_make_registration" type="object" class="btn-primary"/> + <button string="Cancel" class="btn-secondary" special="cancel"/> + </footer> + </form> + </field> + </record> + + <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"/> + <field name="target">new</field> + <field name="context">{}</field> + </record> +</odoo> |
