From a4244e0dfd07d0345a1406cc9b7dc9bbf4ed5fda Mon Sep 17 00:00:00 2001 From: Patrick Hoste Date: Thu, 29 Apr 2021 13:32:36 +0000 Subject: [PATCH] [ADD] website_event_booth_exhibitor: allow sponsor creation with booths reservation PURPOSE This module integrates the Exhibitor module which allows the event manager to automatically create a sponsor after a booth registration. To enable that feature an option has to be set on the booth category. The event manager can also choose what kind of sponsor will be created at the registration. The frontend flow changes a bit to allow the user to provide his sponsor informations. LINKS Task-2318655 Closes : odoo/odoo#71104 --- .../website_event_booth_exhibitor/__init__.py | 5 ++ .../__manifest__.py | 32 ++++++++ .../controllers/__init__.py | 4 + .../controllers/event_booth.py | 41 ++++++++++ .../data/event_booth_category_data.xml | 16 ++++ .../models/__init__.py | 5 ++ .../models/event_booth.py | 54 +++++++++++++ .../models/event_booth_category.py | 24 ++++++ .../static/src/js/booth_sponsor_details.js | 29 +++++++ .../tours/website_event_booth_exhibitor.js | 62 +++++++++++++++ .../tests/__init__.py | 4 + .../tests/test_wevent_booth_exhibitor.py | 17 +++++ .../views/event_booth_category_views.xml | 51 +++++++++++++ .../event_booth_registration_templates.xml | 75 +++++++++++++++++++ .../views/event_booth_templates.xml | 10 +++ .../views/event_booth_views.xml | 30 ++++++++ .../views/mail_templates.xml | 13 ++++ 17 files changed, 472 insertions(+) create mode 100644 addons/website_event_booth_exhibitor/__init__.py create mode 100644 addons/website_event_booth_exhibitor/__manifest__.py create mode 100644 addons/website_event_booth_exhibitor/controllers/__init__.py create mode 100644 addons/website_event_booth_exhibitor/controllers/event_booth.py create mode 100644 addons/website_event_booth_exhibitor/data/event_booth_category_data.xml create mode 100644 addons/website_event_booth_exhibitor/models/__init__.py create mode 100644 addons/website_event_booth_exhibitor/models/event_booth.py create mode 100644 addons/website_event_booth_exhibitor/models/event_booth_category.py create mode 100644 addons/website_event_booth_exhibitor/static/src/js/booth_sponsor_details.js create mode 100644 addons/website_event_booth_exhibitor/static/tests/tours/website_event_booth_exhibitor.js create mode 100644 addons/website_event_booth_exhibitor/tests/__init__.py create mode 100644 addons/website_event_booth_exhibitor/tests/test_wevent_booth_exhibitor.py create mode 100644 addons/website_event_booth_exhibitor/views/event_booth_category_views.xml create mode 100644 addons/website_event_booth_exhibitor/views/event_booth_registration_templates.xml create mode 100644 addons/website_event_booth_exhibitor/views/event_booth_templates.xml create mode 100644 addons/website_event_booth_exhibitor/views/event_booth_views.xml create mode 100644 addons/website_event_booth_exhibitor/views/mail_templates.xml diff --git a/addons/website_event_booth_exhibitor/__init__.py b/addons/website_event_booth_exhibitor/__init__.py new file mode 100644 index 00000000000..7d34c7c054a --- /dev/null +++ b/addons/website_event_booth_exhibitor/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import controllers +from . import models diff --git a/addons/website_event_booth_exhibitor/__manifest__.py b/addons/website_event_booth_exhibitor/__manifest__.py new file mode 100644 index 00000000000..52ce1a08f43 --- /dev/null +++ b/addons/website_event_booth_exhibitor/__manifest__.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- + +{ + 'name': 'Booths/Exhibitors Bridge', + 'category': 'Marketing/Events', + 'version': '1.0', + 'summary': 'Event Booths, automatically create a sponsor.', + 'description': """ +Automatically create a sponsor when renting a booth. + """, + 'depends': ['website_event_exhibitor', 'website_event_booth'], + 'data': [ + 'data/event_booth_category_data.xml', + + 'views/event_booth_category_views.xml', + 'views/event_booth_views.xml', + + 'views/event_booth_registration_templates.xml', + 'views/event_booth_templates.xml', + 'views/mail_templates.xml' + ], + 'auto_install': True, + 'assets': { + 'web.assets_frontend': [ + '/website_event_booth_exhibitor/static/src/js/booth_sponsor_details.js', + ], + 'web.assets_tests': [ + 'website_event_booth_exhibitor/static/tests/tours/website_event_booth_exhibitor.js', + ], + }, + 'license': 'LGPL-3', +} diff --git a/addons/website_event_booth_exhibitor/controllers/__init__.py b/addons/website_event_booth_exhibitor/controllers/__init__.py new file mode 100644 index 00000000000..1e9f6c7c1c1 --- /dev/null +++ b/addons/website_event_booth_exhibitor/controllers/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import event_booth diff --git a/addons/website_event_booth_exhibitor/controllers/event_booth.py b/addons/website_event_booth_exhibitor/controllers/event_booth.py new file mode 100644 index 00000000000..e43b53aa8b2 --- /dev/null +++ b/addons/website_event_booth_exhibitor/controllers/event_booth.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +import base64 + +from odoo.addons.website_event.controllers.main import WebsiteEventController +from odoo.tools import plaintext2html + + +class WebsiteEventBoothController(WebsiteEventController): + + def _prepare_booth_registration_values(self, event, kwargs): + booth_values = super(WebsiteEventBoothController, self)._prepare_booth_registration_values(event, kwargs) + if not booth_values.get('contact_email'): + booth_values['contact_email'] = kwargs.get('sponsor_email') + if not booth_values.get('contact_name'): + booth_values['contact_name'] = kwargs.get('sponsor_name') + if not booth_values.get('contact_mobile'): + booth_values['contact_mobile'] = kwargs.get('sponsor_mobile') + if not booth_values.get('contact_phone'): + booth_values['contact_phone'] = kwargs.get('sponsor_phone') + + booth_values.update(**self._prepare_booth_registration_sponsor_values(event, booth_values, kwargs)) + return booth_values + + def _prepare_booth_registration_partner_values(self, event, kwargs): + if not kwargs.get('contact_email') and kwargs.get('sponsor_email'): + kwargs['contact_email'] = kwargs['sponsor_email'] + return super(WebsiteEventBoothController, self)._prepare_booth_registration_partner_values(event, kwargs) + + def _prepare_booth_registration_sponsor_values(self, event, booth_values, kwargs): + sponsor_values = { + 'sponsor_name': kwargs.get('sponsor_name') or booth_values.get('contact_name'), + 'sponsor_email': kwargs.get('sponsor_email') or booth_values.get('contact_email'), + 'sponsor_mobile': kwargs.get('sponsor_mobile') or booth_values.get('contact_mobile'), + 'sponsor_phone': kwargs.get('sponsor_phone') or booth_values.get('contact_phone'), + 'sponsor_subtitle': kwargs.get('sponsor_slogan'), + 'sponsor_website_description': plaintext2html(kwargs.get('sponsor_description')) if kwargs.get('sponsor_description') else '', + 'sponsor_image_512': base64.b64encode(kwargs['sponsor_image'].read()) if kwargs.get('sponsor_image') else False, + } + return sponsor_values diff --git a/addons/website_event_booth_exhibitor/data/event_booth_category_data.xml b/addons/website_event_booth_exhibitor/data/event_booth_category_data.xml new file mode 100644 index 00000000000..01deefe94d7 --- /dev/null +++ b/addons/website_event_booth_exhibitor/data/event_booth_category_data.xml @@ -0,0 +1,16 @@ + + + + + + + exhibitor + + + + + + online + + + diff --git a/addons/website_event_booth_exhibitor/models/__init__.py b/addons/website_event_booth_exhibitor/models/__init__.py new file mode 100644 index 00000000000..81b1903ec93 --- /dev/null +++ b/addons/website_event_booth_exhibitor/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import event_booth +from . import event_booth_category diff --git a/addons/website_event_booth_exhibitor/models/event_booth.py b/addons/website_event_booth_exhibitor/models/event_booth.py new file mode 100644 index 00000000000..8e9d7f99381 --- /dev/null +++ b/addons/website_event_booth_exhibitor/models/event_booth.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import fields, models + + +class EventBooth(models.Model): + _inherit = 'event.booth' + + use_sponsor = fields.Boolean(related='booth_category_id.use_sponsor') + sponsor_type_id = fields.Many2one(related='booth_category_id.sponsor_type_id') + sponsor_id = fields.Many2one('event.sponsor', string='Sponsor', copy=False) + sponsor_name = fields.Char(string='Sponsor Name', related='sponsor_id.name') + sponsor_email = fields.Char(string='Sponsor Email', related='sponsor_id.email') + sponsor_mobile = fields.Char(string='Sponsor Mobile', related='sponsor_id.mobile') + sponsor_phone = fields.Char(string='Sponsor Phone', related='sponsor_id.phone') + sponsor_subtitle = fields.Char(string='Sponsor Slogan', related='sponsor_id.subtitle') + sponsor_website_description = fields.Html(string='Sponsor Description', related='sponsor_id.website_description') + sponsor_image_512 = fields.Image(string='Sponsor Logo', related='sponsor_id.image_512') + + def action_view_sponsor(self): + action = self.env['ir.actions.act_window']._for_xml_id('website_event_exhibitor.event_sponsor_action') + action['views'] = [(False, 'form')] + action['res_id'] = self.sponsor_id.id + return action + + def _get_or_create_sponsor(self, vals): + self.ensure_one() + sponsor_id = self.env['event.sponsor'].sudo().search([ + ('partner_id', '=', self.partner_id.id), + ('sponsor_type_id', '=', self.sponsor_type_id.id), + ('exhibitor_type', '=', self.booth_category_id.exhibitor_type), + ('event_id', '=', self.event_id.id), + ], limit=1) + if not sponsor_id: + values = { + 'event_id': self.event_id.id, + 'sponsor_type_id': self.sponsor_type_id.id, + 'exhibitor_type': self.booth_category_id.exhibitor_type, + 'partner_id': self.partner_id.id, + **{key.partition('sponsor_')[2]: value for key, value in vals.items() if key.startswith('sponsor_')}, + } + if self.booth_category_id.exhibitor_type == 'online': + values.update({ + 'room_name': 'odoo-exhibitor-%s' % self.partner_id.name, + }) + sponsor_id = self.env['event.sponsor'].sudo().create(values) + return sponsor_id.id + + def _action_post_confirm(self, write_vals): + for booth in self: + if booth.use_sponsor and booth.partner_id: + booth.sponsor_id = booth._get_or_create_sponsor(write_vals) + super(EventBooth, self)._action_post_confirm(write_vals) diff --git a/addons/website_event_booth_exhibitor/models/event_booth_category.py b/addons/website_event_booth_exhibitor/models/event_booth_category.py new file mode 100644 index 00000000000..e7e818f4d27 --- /dev/null +++ b/addons/website_event_booth_exhibitor/models/event_booth_category.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, fields, models + + +class EventBoothCategory(models.Model): + _inherit = 'event.booth.category' + + @api.model + def _get_exhibitor_type(self): + return self.env['event.sponsor']._fields['exhibitor_type'].selection + + use_sponsor = fields.Boolean(string='Create Sponsor', help="If set, when booking a booth a sponsor will be created for the user") + sponsor_type_id = fields.Many2one('event.sponsor.type', string='Sponsor Level') + exhibitor_type = fields.Selection(_get_exhibitor_type, string='Sponsor Type') + + @api.onchange('use_sponsor') + def _onchange_use_sponsor(self): + if self.use_sponsor: + if not self.sponsor_type_id: + self.sponsor_type_id = self.env['event.sponsor.type'].search([], order="sequence desc", limit=1).id + if not self.exhibitor_type: + self.exhibitor_type = self._get_exhibitor_type()[0][0] diff --git a/addons/website_event_booth_exhibitor/static/src/js/booth_sponsor_details.js b/addons/website_event_booth_exhibitor/static/src/js/booth_sponsor_details.js new file mode 100644 index 00000000000..df5d359a68f --- /dev/null +++ b/addons/website_event_booth_exhibitor/static/src/js/booth_sponsor_details.js @@ -0,0 +1,29 @@ +odoo.define('website_event_booth_exhibitor.booth_sponsor_details', function (require) { +'use strict'; + +var publicWidget = require('web.public.widget'); + +publicWidget.registry.boothSponsorDetails = publicWidget.Widget.extend({ + selector: '#o_wbooth_contact_details_form', + events: { + 'click input[id="contact_details"]': '_onClickContactDetails', + }, + + //-------------------------------------------------------------------------- + // Handler + //-------------------------------------------------------------------------- + + _onClickContactDetails(ev) { + this.useContactDetails = ev.currentTarget.checked; + this.$('#o_wbooth_contact_details').toggleClass('d-none', !this.useContactDetails); + this.$('label[for="sponsor_name"] > .mandatory_mark, label[for="sponsor_email"] > .mandatory_mark').toggleClass('d-none', this.useContactDetails); + this.$('input[name="contact_name"], input[name="contact_email"]').attr('required', this.useContactDetails); + }, + +}); + + return { + boothSponsorDetails: publicWidget.registry.boothSponsorDetails, + }; + +}); diff --git a/addons/website_event_booth_exhibitor/static/tests/tours/website_event_booth_exhibitor.js b/addons/website_event_booth_exhibitor/static/tests/tours/website_event_booth_exhibitor.js new file mode 100644 index 00000000000..4b46b399976 --- /dev/null +++ b/addons/website_event_booth_exhibitor/static/tests/tours/website_event_booth_exhibitor.js @@ -0,0 +1,62 @@ +odoo.define("website_event_booth_exhibitor.tour_steps", function (require) { + "use strict"; + + var core = require('web.core'); + + var FinalSteps = core.Class.extend({ + + _getSteps: function () { + return [{ + trigger: 'h3:contains("Booth Registration completed!")', + run: function() {}, + }]; + }, + + }); + + return FinalSteps; + +}); +odoo.define("website_event_booth_exhibitor.tour", function (require) { + "use strict"; + + var tour = require("web_tour.tour"); + var FinalSteps = require('website_event_booth_exhibitor.tour_steps'); + + + tour.register("webooth_exhibitor_register", { + test: true, + url: "/event", + }, [{ + content: 'Go on "Online Reveal" page', + trigger: 'a[href*="/event"]:contains("Online Reveal"):first', + }, { + content: 'Browse Booths', + trigger: 'a:contains("Get A Booth")', + }, { + content: 'Choose Premium Booths', + trigger: 'img[title="Premium Booth"]', + }, { + content: 'Choose Booth', + trigger: 'div:contains("OpenWood Demonstrator 2") input', + }, { + content: "Validate attendees details", + trigger: 'button:contains("Book my Booths")', + run: 'click', + }, { + content: "Fill booth details", + trigger: 'form[id="o_wbooth_contact_details_form"]', + run: function () { + $("input[name='sponsor_name']").val("Patrick Sponsor"); + $("input[name='sponsor_email']").val("patrick.sponssor@test.example.com"); + $("input[name='sponsor_phone']").val("+32456001122"); + $("input[name='sponsor_slogan']").val("Patrick is Your Sponsor"); + $("textarea[name='sponsor_description']").text("Really eager to meet you !"); + }, + }, { + content: "Validate booth details", + extra_trigger: "input[name='sponsor_name'], input[name='sponsor_email'], input[name='sponsor_phone']", + trigger: 'button:contains("Book my Booths")', + run: 'click', + }, ...new FinalSteps()._getSteps()].filter(Boolean)); +}); diff --git a/addons/website_event_booth_exhibitor/tests/__init__.py b/addons/website_event_booth_exhibitor/tests/__init__.py new file mode 100644 index 00000000000..7358a417c50 --- /dev/null +++ b/addons/website_event_booth_exhibitor/tests/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import test_wevent_booth_exhibitor diff --git a/addons/website_event_booth_exhibitor/tests/test_wevent_booth_exhibitor.py b/addons/website_event_booth_exhibitor/tests/test_wevent_booth_exhibitor.py new file mode 100644 index 00000000000..49729e762be --- /dev/null +++ b/addons/website_event_booth_exhibitor/tests/test_wevent_booth_exhibitor.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo.addons.base.tests.common import HttpCaseWithUserDemo, HttpCaseWithUserPortal +from odoo.tests import tagged + + +@tagged('post_install', '-at_install') +class TestWEventBoothExhibitorCommon(HttpCaseWithUserDemo, HttpCaseWithUserPortal): + + def test_register(self): + self.browser_js( + '/event', + 'odoo.__DEBUG__.services["web_tour.tour"].run("webooth_exhibitor_register")', + 'odoo.__DEBUG__.services["web_tour.tour"].tours.webooth_exhibitor_register.ready', + login='admin' + ) diff --git a/addons/website_event_booth_exhibitor/views/event_booth_category_views.xml b/addons/website_event_booth_exhibitor/views/event_booth_category_views.xml new file mode 100644 index 00000000000..e33cda8a57f --- /dev/null +++ b/addons/website_event_booth_exhibitor/views/event_booth_category_views.xml @@ -0,0 +1,51 @@ + + + + + event.booth.category.view.form.inherit.website.event.booth.exhibitor + event.booth.category + + + + + + + + + + + + + + + event.booth.category.view.tree.inherit.website.event.booth.exhibitor + event.booth.category + + 5 + + + + + + + + + + + event.booth.category.view.search.inherit.website.event.booth.exhibitor + event.booth.category + + + + + + + + + + + + + + + diff --git a/addons/website_event_booth_exhibitor/views/event_booth_registration_templates.xml b/addons/website_event_booth_exhibitor/views/event_booth_registration_templates.xml new file mode 100644 index 00000000000..a39eafe0b00 --- /dev/null +++ b/addons/website_event_booth_exhibitor/views/event_booth_registration_templates.xml @@ -0,0 +1,75 @@ + + + +