From d4913c30c804c20024584182d9b70d4c87544340 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 2 Feb 2024 14:07:12 +0700 Subject: Add role permission feature --- indoteknik_api/controllers/__init__.py | 1 + indoteknik_api/controllers/export.py | 46 ++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 indoteknik_api/controllers/export.py (limited to 'indoteknik_api') diff --git a/indoteknik_api/controllers/__init__.py b/indoteknik_api/controllers/__init__.py index 237f4135..34bba89f 100644 --- a/indoteknik_api/controllers/__init__.py +++ b/indoteknik_api/controllers/__init__.py @@ -1,4 +1,5 @@ from . import controller +from . import export from . import api_v1 from . import api_v2 from . import api_v3 \ No newline at end of file diff --git a/indoteknik_api/controllers/export.py b/indoteknik_api/controllers/export.py new file mode 100644 index 00000000..c29c82c7 --- /dev/null +++ b/indoteknik_api/controllers/export.py @@ -0,0 +1,46 @@ +import json + +from odoo.tools import pycompat +from odoo.exceptions import Warning +from odoo import http +from odoo.http import request +from odoo.addons.web.controllers.main import ExportFormat, GroupExportXlsxWriter, ExportXlsxWriter, serialize_exception, clean_action + +class Export(ExportFormat, http.Controller): + @http.route('/web/export/xlsx', type='http', auth="public", csrf=False) + @serialize_exception + def export_xlsx(self, data, token, **kw): + data_obj = json.loads(data) + model = data_obj['model'] + can_export = request.env.user.check_access(model, 'export') + + if not can_export: + raise Warning('You are not allowed to export') + + return self.base(data, token) + + @property + def content_type(self): + return 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' + + def filename(self, base): + return base + '.xlsx' + + def from_group_data(self, fields, groups): + with GroupExportXlsxWriter(fields, groups.count) as xlsx_writer: + x, y = 1, 0 + for group_name, group in groups.children.items(): + x, y = xlsx_writer.write_group(x, y, group_name, group) + + return xlsx_writer.value + + def from_data(self, fields, rows): + with ExportXlsxWriter(fields, len(rows)) as xlsx_writer: + for row_index, row in enumerate(rows): + for cell_index, cell_value in enumerate(row): + if isinstance(cell_value, (list, tuple)): + cell_value = pycompat.to_text(cell_value) + xlsx_writer.write_cell(row_index + 1, cell_index, cell_value) + + return xlsx_writer.value + \ No newline at end of file -- cgit v1.2.3 From 953c3e611af5c57a8f7d57b5f2f651314c2a92a3 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Wed, 7 Feb 2024 13:53:16 +0700 Subject: Revert image api style --- indoteknik_api/controllers/controller.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'indoteknik_api') diff --git a/indoteknik_api/controllers/controller.py b/indoteknik_api/controllers/controller.py index 50e86b68..fe0f1203 100644 --- a/indoteknik_api/controllers/controller.py +++ b/indoteknik_api/controllers/controller.py @@ -210,7 +210,12 @@ class Controller(http.Controller): def add_watermark_to_image(self, image, ratio, version = '1'): if not image: return '' - logo_path = get_module_resource('indoteknik_api', 'static', 'src', 'images', 'logo-indoteknik-gray.png') + 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)) @@ -238,13 +243,15 @@ class Controller(http.Controller): 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 - 20), logo_footer_img) + 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 logo_img.thumbnail((logo_img_w, logo_img_h)) - if version == '1': - # Add watermark - new_img.paste(logo_img, (12, 10), logo_img) + # Add watermark + new_img.paste(logo_img, (12, 10), logo_img) buffered = io.BytesIO() new_img.save(buffered, format="PNG") -- cgit v1.2.3 From f300408a52eab119568a331c46c1288f18bd7c8e Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 12 Feb 2024 10:48:37 +0700 Subject: bug fix flashsale price, forgot to divide tax --- indoteknik_api/models/product_product.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'indoteknik_api') diff --git a/indoteknik_api/models/product_product.py b/indoteknik_api/models/product_product.py index 1db58d8e..4400ad08 100644 --- a/indoteknik_api/models/product_product.py +++ b/indoteknik_api/models/product_product.py @@ -278,11 +278,14 @@ class ProductProduct(models.Model): discount = 0 price_flashsale = 0 + default_divide_tax = float(1.11) if item.price_discount > 0: discount = item.price_discount price_flashsale = base_price - (base_price * discount // 100) + price_flashsale = price_flashsale / default_divide_tax elif item.fixed_price > 0: price_flashsale = item.fixed_price # ask darren for include or exclude + # price_flashsale = price_flashsale / default_divide_tax # darren must fill the fixed price with price exclude discount = (base_price - price_flashsale) // base_price * 100 if price_for == 'odoo': -- cgit v1.2.3 From 0060d2789962593280e91d8ea4251a7c18d6115c Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 12 Feb 2024 11:14:02 +0700 Subject: bug fix tax in flashsale price if using fixed price --- indoteknik_api/models/product_product.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'indoteknik_api') diff --git a/indoteknik_api/models/product_product.py b/indoteknik_api/models/product_product.py index 4400ad08..bd6f516d 100644 --- a/indoteknik_api/models/product_product.py +++ b/indoteknik_api/models/product_product.py @@ -279,14 +279,17 @@ class ProductProduct(models.Model): discount = 0 price_flashsale = 0 default_divide_tax = float(1.11) + default_tax = float(11) if item.price_discount > 0: discount = item.price_discount price_flashsale = base_price - (base_price * discount // 100) price_flashsale = price_flashsale / default_divide_tax elif item.fixed_price > 0: price_flashsale = item.fixed_price # ask darren for include or exclude - # price_flashsale = price_flashsale / default_divide_tax # darren must fill the fixed price with price exclude + price_flashsale = price_flashsale + (price_flashsale * default_tax / 100) discount = (base_price - price_flashsale) // base_price * 100 + price_flashsale = item.fixed_price + # price_flashsale = price_flashsale / default_divide_tax # darren must fill the fixed price with price exclude if price_for == 'odoo': base_price = self._v2_get_website_price_exclude_tax() -- cgit v1.2.3 From fb5ef1ffd3a52997044a4bcd1f6bef8cc70861ff Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 12 Feb 2024 16:37:46 +0700 Subject: bug fix discount zero in flash sale --- indoteknik_api/models/product_product.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indoteknik_api') diff --git a/indoteknik_api/models/product_product.py b/indoteknik_api/models/product_product.py index bd6f516d..3ecad627 100644 --- a/indoteknik_api/models/product_product.py +++ b/indoteknik_api/models/product_product.py @@ -287,7 +287,8 @@ class ProductProduct(models.Model): elif item.fixed_price > 0: price_flashsale = item.fixed_price # ask darren for include or exclude price_flashsale = price_flashsale + (price_flashsale * default_tax / 100) - discount = (base_price - price_flashsale) // base_price * 100 + discount = (base_price - price_flashsale) * 100 / base_price + discount = (math.ceil(discount*100)/100) price_flashsale = item.fixed_price # price_flashsale = price_flashsale / default_divide_tax # darren must fill the fixed price with price exclude -- cgit v1.2.3 From 5cf60908a43f8c74281111438415581f997efa96 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 16 Feb 2024 09:39:38 +0700 Subject: Add get all voucher api --- indoteknik_api/controllers/api_v1/voucher.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'indoteknik_api') diff --git a/indoteknik_api/controllers/api_v1/voucher.py b/indoteknik_api/controllers/api_v1/voucher.py index 3c056ecd..1888fe29 100644 --- a/indoteknik_api/controllers/api_v1/voucher.py +++ b/indoteknik_api/controllers/api_v1/voucher.py @@ -1,31 +1,39 @@ -from .. import controller +from bs4 import BeautifulSoup from odoo import http from odoo.http import request -from bs4 import BeautifulSoup + +from .. import controller class Voucher(controller.Controller): - prefix = '/api/v1/' + PREFIX_API = '/api/v1/' + + @http.route(PREFIX_API + 'voucher', auth='public', methods=['GET', 'OPTIONS']) + @controller.Controller.must_authorized() + def get_vouchers(self, **kw): + vouchers = request.env['voucher'].get_active_voucher([('visibility', 'in', ['public'])]) + vouchers = vouchers.res_format() + return self.response(vouchers) - @http.route(prefix + 'user//voucher', auth='public', methods=['GET', 'OPTIONS']) + @http.route(PREFIX_API + 'user//voucher', auth='public', methods=['GET', 'OPTIONS']) @controller.Controller.must_authorized(private=True, private_key='user_id') - def get_vouchers(self, **kw): + def get_vouchers_by_user_id(self, **kw): cart = request.env['website.user.cart'] code = kw.get('code') user_id = int(kw.get('user_id', 0)) source = kw.get('source') visibility = ['public'] - parameter = [] + domain = [] if code: visibility.append('private') - parameter += [('code', '=', code)] + domain += [('code', '=', code)] user_pricelist = request.env.context.get('user_pricelist') if user_pricelist: - parameter += [('excl_pricelist_ids', 'not in', [user_pricelist.id])] + domain += [('excl_pricelist_ids', 'not in', [user_pricelist.id])] - parameter += [('visibility', 'in', visibility)] - vouchers = request.env['voucher'].get_active_voucher(parameter) + domain += [('visibility', 'in', visibility)] + vouchers = request.env['voucher'].get_active_voucher(domain) checkout = cart.get_user_checkout(user_id, source=source) products = checkout['products'] -- cgit v1.2.3 From 899aa7d32ed7df8672dd7a7415500b44242dd89c Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Mon, 19 Feb 2024 10:16:20 +0700 Subject: Fix create or update cart api --- indoteknik_api/controllers/api_v1/cart.py | 38 +++++++++++++++++-------------- 1 file changed, 21 insertions(+), 17 deletions(-) (limited to 'indoteknik_api') diff --git a/indoteknik_api/controllers/api_v1/cart.py b/indoteknik_api/controllers/api_v1/cart.py index 907c8288..5948a277 100644 --- a/indoteknik_api/controllers/api_v1/cart.py +++ b/indoteknik_api/controllers/api_v1/cart.py @@ -52,6 +52,9 @@ class Cart(controller.Controller): if not user_id: return self.response(code=400, description='user_id is required') + if not product_id and not program_line_id: + return self.response(code=400, description='product_id or program_line_id is required') + website_user_cart = request.env['website.user.cart'] # Remove previous 'buy' entries for the user @@ -68,32 +71,33 @@ class Cart(controller.Controller): cart = website_user_cart.search(query, limit=1) data_to_update = { + 'user_id': user_id, 'qty': qty, 'is_selected': is_selected, 'program_line_id': program_line_id, - 'product_id': product_id + 'product_id': product_id, + 'source': source or False } - if program_line_id: - data_to_update['product_id'] = False - - if source: - data_to_update['source'] = source - - result = {} if cart: - # Update existing cart entry cart.write(data_to_update) - result['id'] = cart.id else: - # Create a new cart entry if it doesn't exist - create = website_user_cart.create({ - 'user_id': user_id, - **data_to_update - }) - result['id'] = create.id + cart = website_user_cart.create(data_to_update) - return self.response(result) + return self.response({ + 'id': cart.id, + 'product': { + 'id': cart.product_id.id, + 'name': cart.product_id.name + } if cart.product_id else None, + 'program_line': { + 'id': cart.program_line_id.id, + 'name': cart.program_line_id.name + } if cart.program_line_id else None, + 'qty': cart.qty, + 'is_selected': cart.is_selected, + 'source': cart.source + }) @http.route(PREFIX_USER + 'cart', auth='public', methods=['DELETE', 'OPTIONS'], csrf=False) @controller.Controller.must_authorized() -- cgit v1.2.3 From dd6544f7fa40d8e688349f2f143d258f6dd3eec7 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Mon, 19 Feb 2024 10:44:02 +0700 Subject: Fix get voucher api, ignore voucher for promotion program --- indoteknik_api/controllers/api_v1/voucher.py | 1 + 1 file changed, 1 insertion(+) (limited to 'indoteknik_api') diff --git a/indoteknik_api/controllers/api_v1/voucher.py b/indoteknik_api/controllers/api_v1/voucher.py index 1888fe29..53f118ec 100644 --- a/indoteknik_api/controllers/api_v1/voucher.py +++ b/indoteknik_api/controllers/api_v1/voucher.py @@ -43,6 +43,7 @@ class Voucher(controller.Controller): order_line = [] for product in products: + if product['cart_type'] == 'promotion': continue order_line.append({ 'product_id': request.env['product.product'].browse(product['id']), 'price': product['price']['price'], -- cgit v1.2.3 From 1b321129a53dcd218cab565f7c47210f70c84fdc Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Wed, 21 Feb 2024 14:27:01 +0700 Subject: Update order get active flash sale --- indoteknik_api/models/product_pricelist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_api') diff --git a/indoteknik_api/models/product_pricelist.py b/indoteknik_api/models/product_pricelist.py index f05fa82d..0d4247c8 100644 --- a/indoteknik_api/models/product_pricelist.py +++ b/indoteknik_api/models/product_pricelist.py @@ -92,7 +92,7 @@ class ProductPricelist(models.Model): ('is_flash_sale', '=', True), ('start_date', '<=', current_time), ('end_date', '>=', current_time) - ], limit=1) + ], limit=1, order='start_date asc') return pricelist def is_flash_sale_product(self, product_id: int): -- cgit v1.2.3 From fc460ec7349d557654316c0628d76d49c12fd575 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 23 Feb 2024 09:00:58 +0700 Subject: Update image api watermark --- indoteknik_api/controllers/controller.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'indoteknik_api') diff --git a/indoteknik_api/controllers/controller.py b/indoteknik_api/controllers/controller.py index fe0f1203..c4f323fe 100644 --- a/indoteknik_api/controllers/controller.py +++ b/indoteknik_api/controllers/controller.py @@ -193,8 +193,11 @@ class Controller(http.Controller): if model_name in ['product.template']: version = '1' if field in ['image_256', 'image_512', 'image_1024', 'image_1920'] else '2' ratio = kw.get('ratio', '') + variant = kw.get('variant', False) + image = model['image_256'] or '' - image = self.add_watermark_to_image(image, ratio, version) + if not variant: + image = self.add_watermark_to_image(image, ratio, version) response_headers = [ ('Content-Type', 'image/jpg'), -- cgit v1.2.3 From db98ba79a92ca11df958cce513bc320110764434 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Mon, 26 Feb 2024 15:10:47 +0700 Subject: Add qty append on upsert cart api --- indoteknik_api/controllers/api_v1/cart.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'indoteknik_api') diff --git a/indoteknik_api/controllers/api_v1/cart.py b/indoteknik_api/controllers/api_v1/cart.py index 5948a277..f472a9b0 100644 --- a/indoteknik_api/controllers/api_v1/cart.py +++ b/indoteknik_api/controllers/api_v1/cart.py @@ -44,6 +44,7 @@ class Cart(controller.Controller): qty = int(kw.get('qty', 0)) source = kw.get('source') + qty_append = kw.get('qty_append', False) is_selected = kw.get('selected', False) is_selected = is_selected in ('true', True) @@ -78,6 +79,9 @@ class Cart(controller.Controller): 'product_id': product_id, 'source': source or False } + + if isinstance(qty_append, str) and qty_append.lower() == "true" and cart: + data_to_update['qty'] += cart.qty if cart: cart.write(data_to_update) -- cgit v1.2.3