From e79a68d97db8ae00ecbdae8d48f7d65d46f42c7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 7 Jul 2020 08:22:48 +0000 Subject: [PATCH] [IMP] website_event_track_online: improve sponsor partner synchronization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit RATIONALE Events are sometimes held online, gathering a community. In this merge we improve Event application to better support full-online events with improved tracks, wishlists, chat rooms, ... SPECIFICATIONS: PARTNER SYNCHRONIZATION Right now, information on the sponsor page in frontend is dependent on partner through related fields. It is not possible to have contact data specific to the sponsor without modifying the related partner. In this commit we make sponsor a model based on partner while allowing to update its contact information. Name, email, mobile and phone are now computed stored based on partner and editable. A new image_512 field is introduced, as base image field is too small for a new list view of sponsors we plan to make. LINKS Community PR #53540 Enterprise PR odoo/enterprise#11384 Task ID-2252655 (Main Online Event task) Task ID-2283796 (Event B2Basics / Registration Flow) Task ID-2283738 (Sponsors -> Exhibitors upgrade) Co-Authored-By: Aurélien Warnon Co-Authored-By: David Beguin Co-Authored-By: Thibault Delavallée --- .../__manifest__.py | 3 + .../data/event_sponsor_demo.xml | 35 +++++++++++ .../models/__init__.py | 1 + .../models/event_sponsor.py | 62 +++++++++++++++++++ .../views/event_sponsor_views.xml | 62 +++++++++++++++++++ 5 files changed, 163 insertions(+) create mode 100644 addons/website_event_track_online/data/event_sponsor_demo.xml create mode 100644 addons/website_event_track_online/models/event_sponsor.py create mode 100644 addons/website_event_track_online/views/event_sponsor_views.xml diff --git a/addons/website_event_track_online/__manifest__.py b/addons/website_event_track_online/__manifest__.py index ba43d258771..c6de6027c8e 100644 --- a/addons/website_event_track_online/__manifest__.py +++ b/addons/website_event_track_online/__manifest__.py @@ -19,7 +19,9 @@ 'security/ir.model.access.csv', 'views/assets.xml', 'views/event_event_views.xml', + 'views/event_sponsor_views.xml', 'views/event_templates_registration.xml', + 'views/event_track_templates_reminder.xml', 'views/event_track_templates.xml', 'views/event_track_templates_reminder.xml', 'views/event_track_views.xml', @@ -29,6 +31,7 @@ 'views/event_menus.xml', ], 'demo': [ + 'data/event_sponsor_demo.xml', 'data/event_track_demo.xml', 'data/event_track_tag_demo.xml', 'data/event_track_visitor_demo.xml', diff --git a/addons/website_event_track_online/data/event_sponsor_demo.xml b/addons/website_event_track_online/data/event_sponsor_demo.xml new file mode 100644 index 00000000000..f2576038acf --- /dev/null +++ b/addons/website_event_track_online/data/event_sponsor_demo.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/addons/website_event_track_online/models/__init__.py b/addons/website_event_track_online/models/__init__.py index acdcaefaa1a..7553bc67199 100644 --- a/addons/website_event_track_online/models/__init__.py +++ b/addons/website_event_track_online/models/__init__.py @@ -2,6 +2,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from . import event_event +from . import event_sponsor from . import event_track_visitor from . import event_track from . import event_track_tag diff --git a/addons/website_event_track_online/models/event_sponsor.py b/addons/website_event_track_online/models/event_sponsor.py new file mode 100644 index 00000000000..16bec7c9fe4 --- /dev/null +++ b/addons/website_event_track_online/models/event_sponsor.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, fields, models +from odoo.modules.module import get_resource_path + + +class Sponsor(models.Model): + _name = 'event.sponsor' + _inherit = ['event.sponsor'] + + # contact information + name = fields.Char('Sponsor Name', compute='_compute_name', readonly=False, store=True) + email = fields.Char('Sponsor Email', compute='_compute_email', readonly=False, store=True) + phone = fields.Char('Sponsor Phone', compute='_compute_phone', readonly=False, store=True) + mobile = fields.Char('Sponsor Mobile', compute='_compute_mobile', readonly=False, store=True) + # image + image_512 = fields.Image( + string="Logo", max_width=512, max_height=512, + compute='_compute_image_512', readonly=False, store=True) + image_256 = fields.Image("Image 256", related="image_512", max_width=256, max_height=256, store=False) + image_128 = fields.Image("Image 128", related="image_512", max_width=128, max_height=128, store=False) + website_image_url = fields.Char( + string='Image URL', max_width=256, max_height=256, + compute='_compute_website_image_url', compute_sudo=True, store=False) + + @api.depends('partner_id') + def _compute_name(self): + self._synchronize_with_partner('name') + + @api.depends('partner_id') + def _compute_email(self): + self._synchronize_with_partner('email') + + @api.depends('partner_id') + def _compute_phone(self): + self._synchronize_with_partner('phone') + + @api.depends('partner_id') + def _compute_mobile(self): + self._synchronize_with_partner('mobile') + + @api.depends('partner_id') + def _compute_image_512(self): + self._synchronize_with_partner('image_512') + + @api.depends('image_256', 'partner_id.image_256') + def _compute_website_image_url(self): + for sponsor in self: + if sponsor.image_256: + sponsor.website_image_url = self.env['website'].image_url(sponsor, 'image_256', size=256) + elif sponsor.partner_id.image_256: + sponsor.website_image_url = self.env['website'].image_url(sponsor.partner_id, 'image_256', size=256) + else: + sponsor.website_image_url = get_resource_path('website_event_track', 'static/src/img', 'event_sponsor_default_%d.png' % (sponsor.id % 1)) + + def _synchronize_with_partner(self, fname): + """ Synchronize with partner if not set. Setting a value does not write + on partner as this may be event-specific information. """ + for sponsor in self: + if not sponsor[fname]: + sponsor[fname] = sponsor.partner_id[fname] diff --git a/addons/website_event_track_online/views/event_sponsor_views.xml b/addons/website_event_track_online/views/event_sponsor_views.xml new file mode 100644 index 00000000000..b229e5266a9 --- /dev/null +++ b/addons/website_event_track_online/views/event_sponsor_views.xml @@ -0,0 +1,62 @@ + + + + event.sponsor.view.search.inherit.online + event.sponsor + + + + + + + + + + + + event.sponsor.view.tree.inherit.online + event.sponsor + + + + + + + + + + + + + event.sponsor.view.form.inherit.online + event.sponsor + + + + + + +
+
+
+ + + + + + + + e.g. : https://www.odoo.com + + + + + + + +
+
+