diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/website_event_track/models/website.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/website_event_track/models/website.py')
| -rw-r--r-- | addons/website_event_track/models/website.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/addons/website_event_track/models/website.py b/addons/website_event_track/models/website.py new file mode 100644 index 00000000..f6f21d5e --- /dev/null +++ b/addons/website_event_track/models/website.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + + +from PIL import Image + +from odoo import api, fields, models +from odoo.exceptions import ValidationError +from odoo.tools import ImageProcess +from odoo.tools.translate import _ + + +class Website(models.Model): + _inherit = "website" + + app_icon = fields.Image(string='Website App Icon', compute='_compute_app_icon', store=True, readonly=True, help='This field holds the image used as mobile app icon on the website (PNG format).') + events_app_name = fields.Char(string='Events App Name', compute='_compute_events_app_name', store=True, readonly=False, help="This fields holds the Event's Progressive Web App name.") + + @api.depends('name') + def _compute_events_app_name(self): + for website in self: + if not website.events_app_name: + website.events_app_name = _('%s Events') % website.name + + @api.constrains('events_app_name') + def _check_events_app_name(self): + for website in self: + if not website.events_app_name: + raise ValidationError(_('"Events App Name" field is required.')) + + @api.depends('favicon') + def _compute_app_icon(self): + """ Computes a squared image based on the favicon to be used as mobile webapp icon. + App Icon should be in PNG format and size of at least 512x512. + """ + for website in self: + if not website.favicon: + website.app_icon = False + continue + image = ImageProcess(website.favicon) + w, h = image.image.size + square_size = w if w > h else h + image.crop_resize(square_size, square_size) + image.image = image.image.resize((512, 512)) + image.operationsCount += 1 + website.app_icon = image.image_base64(output_format='PNG') |
