diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2024-01-29 13:45:54 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2024-01-29 13:45:54 +0700 |
| commit | d62a28e8760c86e2c0a6cb7469f626d9447272be (patch) | |
| tree | ad04486638950309ac33d642ed7759eb8e15db5d | |
| parent | a142137887530c904c158859889f340c42fe78e1 (diff) | |
| parent | a08c05d892dc01cad4acaa24c7e1eab16f4a9639 (diff) | |
Merge branch 'production' of bitbucket.org:altafixco/indoteknik-addons into production
| -rw-r--r-- | indoteknik_api/controllers/controller.py | 65 | ||||
| -rw-r--r-- | indoteknik_api/static/src/images/logo-indoteknik-footer.png | bin | 0 -> 17722 bytes | |||
| -rw-r--r-- | indoteknik_api/static/src/images/logo-indoteknik-gray.png | bin | 0 -> 29514 bytes | |||
| -rw-r--r-- | indoteknik_api/static/src/images/logo-indoteknik.png | bin | 29514 -> 33475 bytes | |||
| -rw-r--r-- | indoteknik_custom/models/base_import_import.py | 27 |
5 files changed, 57 insertions, 35 deletions
diff --git a/indoteknik_api/controllers/controller.py b/indoteknik_api/controllers/controller.py index bd763e00..fb07708e 100644 --- a/indoteknik_api/controllers/controller.py +++ b/indoteknik_api/controllers/controller.py @@ -1,17 +1,17 @@ -from array import array -import datetime import base64 +import datetime +import functools +import io import json +from array import array -from odoo import http, tools +import jwt +from odoo import http from odoo.http import request -from odoo.tools.config import config from odoo.modules import get_module_resource +from odoo.tools.config import config +from PIL import Image from pytz import timezone -from PIL import Image, ImageDraw, ImageFont -import jwt -import functools -import io class Controller(http.Controller): @@ -187,15 +187,14 @@ class Controller(http.Controller): @http.route('/api/image/<model>/<field>/<id>', auth='public', methods=['GET']) def get_image(self, model, field, id, **kw): model_name = model - model = request.env[model].sudo().search([('id', '=', id)], limit=1) - image = model[field] if model[field] else '' + image = model[field] if field in model else '' - model_with_watermark = ['product.template', 'product.product'] - watermark = kw.get('watermark', '') - if watermark.lower() == 'true' or model_name in model_with_watermark: + if model_name in ['product.template', 'product.product']: + version = '2' if field not in ['image_256', 'image_512', 'image_1024', 'image_1920'] else '1' ratio = kw.get('ratio', '') - image = self.add_watermark_to_image(image, ratio) + image = model['image_512'] or '' + image = self.add_watermark_to_image(image, ratio, version) response_headers = [ ('Content-Type', 'image/jpg'), @@ -207,29 +206,49 @@ class Controller(http.Controller): response_headers ) - def add_watermark_to_image(self, image, ratio): - logo_path = get_module_resource('indoteknik_api', 'static', 'src', 'images', 'logo-indoteknik.png') - logo_img = Image.open(logo_path) - logo_img = logo_img.convert('RGBA') + + def add_watermark_to_image(self, image, ratio, version = '1'): + if not image: return '' + + LOGO_FILENAME = { + '1': 'logo-indoteknik-gray.png', + '2': 'logo-indoteknik.png' + } + + logo_path = get_module_resource('indoteknik_api', 'static', 'src', 'images', LOGO_FILENAME.get(version)) + logo_img = Image.open(logo_path).convert('RGBA') img_data = io.BytesIO(base64.b64decode(image)) - img = Image.open(img_data) - img = img.convert('RGBA') + img = Image.open(img_data).convert('RGBA') img_width, img_height = img.size - logo_img.thumbnail((img_width // 2.2, img_height // 2.2)) + longest_wh = max(img_height, img_width) + + # Resize logo image + logo_img_w = img_width // 2.2 + logo_img_h = img_height // 2.2 new_img = img + if version == '2': + logo__footer_path = get_module_resource('indoteknik_api', 'static', 'src', 'images', 'logo-indoteknik-footer.png') + logo__footer_img = Image.open(logo__footer_path).convert('RGBA') + logo__footer_img.thumbnail((img_width, img_height // 1)) + logo_footer_w, logo_footer_h = logo__footer_img.size + new_img.paste(logo__footer_img, (0, img_height - logo_footer_h), logo__footer_img) + + logo_img_w = img_width // 1.8 + logo_img_h = img_height // 1.8 + if ratio == 'square': - longest_wh = max(img_height, img_width) - new_img = Image.new('RGBA', (longest_wh, longest_wh), (255, 255, 255, 255)) paste_x = (longest_wh - img_width) // 2 paste_y = (longest_wh - img_height) // 2 new_img.paste(img, (paste_x, paste_y), img) + + logo_img.thumbnail((logo_img_w, logo_img_h)) # Add watermark new_img.paste(logo_img, (12, 10), logo_img) diff --git a/indoteknik_api/static/src/images/logo-indoteknik-footer.png b/indoteknik_api/static/src/images/logo-indoteknik-footer.png Binary files differnew file mode 100644 index 00000000..4ebda906 --- /dev/null +++ b/indoteknik_api/static/src/images/logo-indoteknik-footer.png diff --git a/indoteknik_api/static/src/images/logo-indoteknik-gray.png b/indoteknik_api/static/src/images/logo-indoteknik-gray.png Binary files differnew file mode 100644 index 00000000..3039ca38 --- /dev/null +++ b/indoteknik_api/static/src/images/logo-indoteknik-gray.png diff --git a/indoteknik_api/static/src/images/logo-indoteknik.png b/indoteknik_api/static/src/images/logo-indoteknik.png Binary files differindex 3039ca38..e669699c 100644 --- a/indoteknik_api/static/src/images/logo-indoteknik.png +++ b/indoteknik_api/static/src/images/logo-indoteknik.png diff --git a/indoteknik_custom/models/base_import_import.py b/indoteknik_custom/models/base_import_import.py index 9cffa6e6..bc3b0e37 100644 --- a/indoteknik_custom/models/base_import_import.py +++ b/indoteknik_custom/models/base_import_import.py @@ -1,6 +1,8 @@ +from datetime import datetime + from odoo import models from odoo.exceptions import UserError -from datetime import datetime + class Import(models.TransientModel): _inherit = 'base_import.import' @@ -8,8 +10,8 @@ class Import(models.TransientModel): def _get_config_enable_import(self): return self.env['ir.config_parameter'].sudo().get_param('base_import.import.enable_import', '') - def _get_config_restrict_model(self): - return self.env['ir.config_parameter'].sudo().get_param('base_import.import.restrict_model', '') + def _get_config_allowed_model(self): + return self.env['ir.config_parameter'].sudo().get_param('base_import.import.allowed_model', '') def _check_time_range(self, config_string): current_time = datetime.now().time() @@ -27,19 +29,20 @@ class Import(models.TransientModel): def _check_enable_import(self): enable_import = self._get_config_enable_import() - restrict_model = self._get_config_restrict_model() - - if self.res_model not in restrict_model: - return True + allowed_model = self._get_config_allowed_model() - if enable_import.lower() == 'true': - return True - elif enable_import.lower() == 'false': + is_allowed = False + if (allowed_model != '-' and self.res_model in allowed_model) or allowed_model == 'ALL': + is_allowed = True + + if enable_import.lower() == 'false': return False - elif '-' in enable_import: + elif enable_import.lower() == 'true' and is_allowed: + return True + elif '-' in enable_import and is_allowed: return self._check_time_range(enable_import) - return True + return False def _unable_import_notif(self): enable_import_config = self._get_config_enable_import() |
