diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2024-01-29 14:26:39 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2024-01-29 14:26:39 +0700 |
| commit | 3877bf37dae2db272b869f829ed52ef77689cc5d (patch) | |
| tree | 46523b9c4306b5457924420f53e832da1c296224 | |
| parent | 4a35b0d5432ed38395fa8f8cb6ebcfb5e0887f28 (diff) | |
| parent | d62a28e8760c86e2c0a6cb7469f626d9447272be (diff) | |
Merge branch 'production' of https://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/account_move.py | 2 | ||||
| -rw-r--r-- | indoteknik_custom/models/base_import_import.py | 27 | ||||
| -rwxr-xr-x | indoteknik_custom/models/product_template.py | 92 | ||||
| -rwxr-xr-x | indoteknik_custom/models/purchase_order_line.py | 32 | ||||
| -rwxr-xr-x | indoteknik_custom/models/purchase_pricelist.py | 4 | ||||
| -rw-r--r-- | indoteknik_custom/models/stock_picking.py | 2 |
10 files changed, 125 insertions, 99 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/account_move.py b/indoteknik_custom/models/account_move.py index 592a3ae7..a9db212f 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -38,7 +38,7 @@ class AccountMove(models.Model): sale_id = fields.Many2one('sale.order', string='Sale Order') reklas_id = fields.Many2one('account.move', string='Nomor CAB', domain="[('partner_id', '=', partner_id)]") new_invoice_day_to_due = fields.Integer(string="New Day Due", compute="_compute_invoice_day_to_due") - date_efaktur_upload = fields.Datetime(string='eFaktur Upload Date') + date_efaktur_upload = fields.Datetime(string='eFaktur Upload Date', tracking=True) @api.constrains('efaktur_document') def _constrains_date_efaktur(self): 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() diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index bdbc391d..30d89356 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -74,32 +74,34 @@ class ProductTemplate(models.Model): @api.constrains('name', 'default_code') def _check_duplicate_product(self): for product in self: - if not self.env.user.is_purchasing_manager and not self.env.user.is_editor_product and self.env.user.id not in [1, 25]: - domain = [('default_code', '!=', False)] - - if product.product_variant_ids: - domain.extend([ - '|', - ('name', 'in', [variants.name for variants in product.product_variant_ids]), - ('default_code', 'in', [variants.default_code for variants in product.product_variant_ids]) - ]) - else: - domain.extend([ - '|', - ('name', 'in', [product.name]), - ('default_code', 'in', [product.default_code]) - ]) - - domain.append(('id', '!=', product.id)) - - if product.write_date == product.create_date: - message = "SKU atau Name yang Anda gunakan sudah digunakan di produk lain" - elif all(day_product > 0 for day_product in product.day_product_to_edit()): - domain = [('id', '=', product.id)] - message = "Hanya Pak Tyas yang dapat merubah data produk" - existing_purchase = self.search(domain, limit=1) - if existing_purchase: - raise UserError(message) + if self.env.user.is_purchasing_manager or self.env.user.is_editor_product or self.env.user.id in [1, 25]: + continue + + domain = [('default_code', '!=', False)] + + if product.product_variant_ids: + domain.extend([ + '|', + ('name', 'in', [variants.name for variants in product.product_variant_ids]), + ('default_code', 'in', [variants.default_code for variants in product.product_variant_ids]) + ]) + else: + domain.extend([ + '|', + ('name', 'in', [product.name]), + ('default_code', 'in', [product.default_code]) + ]) + + domain.append(('id', '!=', product.id)) + + if product.write_date == product.create_date: + message = "SKU atau Name yang Anda gunakan sudah digunakan di produk lain" + elif all(day_product > 0 for day_product in product.day_product_to_edit()): + domain = [('id', '=', product.id)] + message = "Anda tidak berhak merubah data produk ini" + existing_purchase = self.search(domain, limit=1) + if existing_purchase: + raise UserError(message) @api.constrains('name') def _validate_name(self): @@ -379,24 +381,26 @@ class ProductProduct(models.Model): @api.constrains('name','default_code') def _check_duplicate_product(self): for product in self: - if not self.env.user.is_purchasing_manager and not self.env.user.is_editor_product and self.env.user.id not in [1, 25]: - if product.write_date == product.create_date: - domain = [ - ('default_code', '!=', False), - '|', - ('name', 'in', [template.name for template in product.product_tmpl_id] or [product.name]), - ('default_code', 'in', [template.default_code for template in product.product_tmpl_id] or [product.default_code])] - - domain.append(('id', '!=', product.id)) - massage="SKU atau Name yang anda pakai sudah digunakan di product lain" - existing_purchase = self.search(domain, limit=1) - if existing_purchase: - raise UserError(massage) - elif all(day_product > 0 for day_product in product.day_product_to_edit()): - domain = [('id', '=', product.id)] - existing_purchase = self.search(domain) - if existing_purchase: - raise UserError('Hanya Pak Tyas Yang Dapat Merubah Data Product') + if self.env.user.is_purchasing_manager or self.env.user.is_editor_product or self.env.user.id in [1, 25]: + continue + + if product.write_date == product.create_date: + domain = [ + ('default_code', '!=', False), + '|', + ('name', 'in', [template.name for template in product.product_tmpl_id] or [product.name]), + ('default_code', 'in', [template.default_code for template in product.product_tmpl_id] or [product.default_code])] + + domain.append(('id', '!=', product.id)) + massage="SKU atau Name yang anda pakai sudah digunakan di product lain" + existing_purchase = self.search(domain, limit=1) + if existing_purchase: + raise UserError(massage) + elif all(day_product > 0 for day_product in product.day_product_to_edit()): + domain = [('id', '=', product.id)] + existing_purchase = self.search(domain) + if existing_purchase: + raise UserError('Anda tidak berhak merubah data product ini') @api.constrains('name') def _validate_name(self): diff --git a/indoteknik_custom/models/purchase_order_line.py b/indoteknik_custom/models/purchase_order_line.py index c7da0e24..465944d5 100755 --- a/indoteknik_custom/models/purchase_order_line.py +++ b/indoteknik_custom/models/purchase_order_line.py @@ -2,6 +2,7 @@ from odoo import fields, models, api, _ from odoo.exceptions import AccessError, UserError, ValidationError from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT import logging +from datetime import datetime _logger = logging.getLogger(__name__) @@ -103,24 +104,19 @@ class PurchaseOrderLine(models.Model): return res def _get_valid_purchase_price(self, purchase_price): - p_price = 0 - taxes = False - - if purchase_price.system_price > 0 and purchase_price.product_price > 0: - if purchase_price.human_last_update > purchase_price.system_last_update: - p_price = purchase_price.product_price - taxes = purchase_price.taxes_product_id - else: - p_price = purchase_price.system_price - taxes = purchase_price.taxes_system_id - elif purchase_price.system_price > 0 and purchase_price.product_price == 0: - p_price = purchase_price.system_price - taxes = purchase_price.taxes_system_id - elif purchase_price.system_price == 0 and purchase_price.product_price > 0: - p_price = purchase_price.product_price - taxes = purchase_price.taxes_product_id - - return p_price, taxes + price = 0 + taxes = None + human_last_update = purchase_price.human_last_update or datetime.min + system_last_update = purchase_price.system_last_update or datetime.min + + if system_last_update > human_last_update: + price = purchase_price.system_price + taxes = [purchase.taxes_system_id.id for purchase in purchase_price ] + else: + price = purchase_price.product_price + taxes = [purchase.taxes_product_id.id for purchase in purchase_price ] + + return price, taxes def compute_item_margin(self): sum_so_margin = sum_sales_price = sum_margin = 0 diff --git a/indoteknik_custom/models/purchase_pricelist.py b/indoteknik_custom/models/purchase_pricelist.py index c756c301..805ebc89 100755 --- a/indoteknik_custom/models/purchase_pricelist.py +++ b/indoteknik_custom/models/purchase_pricelist.py @@ -34,7 +34,11 @@ class PurchasePricelist(models.Model): @api.constrains('system_last_update','system_price','product_price','human_last_update','taxes_system_id','taxes_product_id') def _contrains_include_price(self): + price_unit, taxes = self._get_valid_price() + if price_unit == 0: + self.include_price = 0 + return # taxes = self.taxes_system_id or self.taxes_product_id # price_unit = self.system_price or self.product_price tax_include = taxes.price_include diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 8ff782ba..33946f86 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -81,7 +81,7 @@ class StockPicking(models.Model): status_printed = fields.Selection([ ('not_printed', 'Belum Print'), ('printed', 'Printed') - ], string='Printed SJ?', copy=False) + ], string='Printed?', copy=False) date_unreserve = fields.Datetime(string="Date Unreserved", copy=False, tracking=True) date_availability = fields.Datetime(string="Date Availability", copy=False, tracking=True) |
