From eced81efba75d710d164f1baa2d2e50b4d2d3c18 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 3 Sep 2024 14:14:40 +0700 Subject: fix bug --- indoteknik_api/controllers/api_v1/sale_order.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'indoteknik_api/controllers') diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py index 1b7c1af4..c871b69e 100644 --- a/indoteknik_api/controllers/api_v1/sale_order.py +++ b/indoteknik_api/controllers/api_v1/sale_order.py @@ -460,11 +460,16 @@ class SaleOrder(controller.Controller): sale_order.apply_promotion_program() voucher_code = params['value']['voucher'] - voucher = request.env['voucher'].search([('code', '=', voucher_code)]) + voucher = request.env['voucher'].search([('code', '=', voucher_code),('apply_type', 'in', ['all', 'brand'])], limit=1) + voucher_shipping = request.env['voucher'].search([('code', '=', voucher_code),('apply_type', 'in', ['shipping'])], limit=1) if voucher and len(promotions) == 0: sale_order.voucher_id = voucher.id sale_order.apply_voucher() + if voucher_shipping and len(promotions) == 0: + sale_order.voucher_shipping_id = voucher_shipping.id + sale_order.apply_voucher() + cart_ids = [x['cart_id'] for x in carts] if sale_order._requires_approval_margin_leader(): #jika ada error tambahkan kondisi if params['value']['type'] == 'sale_order': sale_order.approval_status = 'pengajuan2' -- cgit v1.2.3 From 0222d907c08ef27dd8d3b303b55d70542cbeb788 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 4 Sep 2024 10:14:54 +0700 Subject: cr api cart v1 --- indoteknik_api/controllers/api_v1/cart.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'indoteknik_api/controllers') diff --git a/indoteknik_api/controllers/api_v1/cart.py b/indoteknik_api/controllers/api_v1/cart.py index f472a9b0..6bbb812c 100644 --- a/indoteknik_api/controllers/api_v1/cart.py +++ b/indoteknik_api/controllers/api_v1/cart.py @@ -17,9 +17,27 @@ class Cart(controller.Controller): query = [('user_id', '=', user_id)] carts = user_cart.search(query, limit=limit, offset=offset, order='create_date desc') carts.write({'source': 'add_to_cart'}) + products = [] + products_inactive = [] + for cart in carts: + if cart.product_id: + price = cart.product_id._v2_get_website_price_include_tax() + if cart.product_id.active and price > 0: + product = cart.with_context(price_for="web").get_products() + for product_active in product: + products.append(product_active) + else: + product_inactives = cart.with_context(price_for="web").get_products() + for inactives in product_inactives: + products_inactive.append(inactives) + else: + program = cart.with_context(price_for="web").get_products() + for programs in program: + products.append(programs) data = { 'product_total': user_cart.search_count(query), - 'products': carts.with_context(price_for="web").get_products() + 'products': products, + 'products_inactive': products_inactive } return self.response(data) -- cgit v1.2.3 From 1bb074bb8f63072fb990c57c18986c50981f1402 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 4 Sep 2024 17:12:38 +0700 Subject: fix voucher shipping --- indoteknik_api/controllers/api_v1/sale_order.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indoteknik_api/controllers') diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py index c871b69e..e8d18366 100644 --- a/indoteknik_api/controllers/api_v1/sale_order.py +++ b/indoteknik_api/controllers/api_v1/sale_order.py @@ -407,7 +407,7 @@ class SaleOrder(controller.Controller): 'real_invoice_id': params['value']['partner_invoice_id'], 'partner_purchase_order_name': params['value']['po_number'], 'partner_purchase_order_file': params['value']['po_file'], - 'delivery_amt': params['value']['delivery_amount'], + 'delivery_amt': params['value']['delivery_amount'] * 1.10, 'estimated_arrival_days': params['value']['estimated_arrival_days'], 'shipping_cost_covered': 'customer', 'shipping_paid_by': 'customer', @@ -468,7 +468,7 @@ class SaleOrder(controller.Controller): if voucher_shipping and len(promotions) == 0: sale_order.voucher_shipping_id = voucher_shipping.id - sale_order.apply_voucher() + sale_order.apply_voucher_shipping() cart_ids = [x['cart_id'] for x in carts] if sale_order._requires_approval_margin_leader(): #jika ada error tambahkan kondisi if params['value']['type'] == 'sale_order': -- cgit v1.2.3 From 1b55d65464b9789164ba45bdef03c56428e026f2 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Thu, 5 Sep 2024 17:49:30 +0700 Subject: update category management --- .../controllers/api_v1/category_management.py | 46 +++++++++++++--------- 1 file changed, 28 insertions(+), 18 deletions(-) (limited to 'indoteknik_api/controllers') diff --git a/indoteknik_api/controllers/api_v1/category_management.py b/indoteknik_api/controllers/api_v1/category_management.py index 836f4493..8015bffc 100644 --- a/indoteknik_api/controllers/api_v1/category_management.py +++ b/indoteknik_api/controllers/api_v1/category_management.py @@ -2,11 +2,12 @@ from odoo import http from odoo.http import request from .. import controller + class CategoryManagement(controller.Controller): prefix = '/api/v1/' @http.route(prefix + 'categories_management', auth='public', methods=['GET', 'OPTIONS'], csrf=False) - @controller.Controller.must_authorized() + # @controller.Controller.must_authorized() def get_categories_management(self, **kw): base_url = request.env['ir.config_parameter'].sudo().get_param('web.base.url') @@ -14,33 +15,42 @@ class CategoryManagement(controller.Controller): categories = request.env['website.categories.management'].search(query, order='sequence') data = [] + for category in categories: category_id2_data = [] - for x in category.category_id2: - child_data = [ - {'id_level_3': child.id, - 'name': child.name, - 'numFound': len(child.product_tmpl_ids.ids), - 'image': request.env['ir.attachment'].api_image('product.public.category', 'image_1920', child.id)} - for child in x.child_frontend_id2 + + # Loop through each line to get Category Level 2 and Level 3 + for line in category.line_ids: + category_id3_data = [ + { + 'id_level_3': child.id, + 'name': child.name, + 'numFound': len(child.product_tmpl_ids.ids), + 'image': request.env['ir.attachment'].api_image('product.public.category', 'image_1920', + child.id) + } + for child in line.category_id3_ids # Loop through Many2many Category Level 3 ] + category_id2_data.append({ - 'id_level_2': x.id, - 'name': x.name, - 'numFound': len(x.product_tmpl_ids.ids), - 'image': request.env['ir.attachment'].api_image('product.public.category', 'image_1920', x.id), - 'child_frontend_id_i': child_data + 'id_level_2': line.category_id2.id, + 'name': line.category_id2.name, + 'numFound': len(line.category_id2.product_tmpl_ids.ids), + 'image': request.env['ir.attachment'].api_image('product.public.category', 'image_1920', + line.category_id2.id), + 'child_frontend_id_i': category_id3_data # Add Category Level 3 data }) + # Add data for Category Level 1 along with its lines (Category Level 2) data.append({ 'id': category.id, 'sequence': category.sequence, 'category_id_i': category.category_id.id, 'name': category.category_id.name, - 'numFound': len(category.category_id.product_tmpl_ids.ids) , - 'image': request.env['ir.attachment'].api_image('product.public.category', 'image_1920', category.category_id.id), - 'categories': category_id2_data, + 'numFound': len(category.category_id.product_tmpl_ids.ids), + 'image': request.env['ir.attachment'].api_image('product.public.category', 'image_1920', + category.category_id.id), + 'categories': category_id2_data, # Category Level 2 with Level 3 nested inside }) - return self.response(data, headers=[('Cache-Control', 'max-age=3600, public')]) - + return self.response(data, headers=[('Cache-Control', 'max-age=3600, public')]) -- cgit v1.2.3 From 94be2756aa2ab4c5a403877e9085eab344468f1a Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 6 Sep 2024 09:31:28 +0700 Subject: update category management --- .../controllers/api_v1/category_management.py | 42 ++++++++-------------- 1 file changed, 15 insertions(+), 27 deletions(-) (limited to 'indoteknik_api/controllers') diff --git a/indoteknik_api/controllers/api_v1/category_management.py b/indoteknik_api/controllers/api_v1/category_management.py index 8015bffc..c7c4651d 100644 --- a/indoteknik_api/controllers/api_v1/category_management.py +++ b/indoteknik_api/controllers/api_v1/category_management.py @@ -7,7 +7,6 @@ class CategoryManagement(controller.Controller): prefix = '/api/v1/' @http.route(prefix + 'categories_management', auth='public', methods=['GET', 'OPTIONS'], csrf=False) - # @controller.Controller.must_authorized() def get_categories_management(self, **kw): base_url = request.env['ir.config_parameter'].sudo().get_param('web.base.url') @@ -15,42 +14,31 @@ class CategoryManagement(controller.Controller): categories = request.env['website.categories.management'].search(query, order='sequence') data = [] - for category in categories: category_id2_data = [] - - # Loop through each line to get Category Level 2 and Level 3 - for line in category.line_ids: - category_id3_data = [ - { - 'id_level_3': child.id, - 'name': child.name, - 'numFound': len(child.product_tmpl_ids.ids), - 'image': request.env['ir.attachment'].api_image('product.public.category', 'image_1920', - child.id) - } - for child in line.category_id3_ids # Loop through Many2many Category Level 3 + for x in category.category_id2: + child_data = [ + {'id_level_3': child.id, + 'name': child.name, + 'numFound': len(child.product_tmpl_ids.ids), + 'image': request.env['ir.attachment'].api_image('product.public.category', 'image_1920', child.id)} + for child in x.child_frontend_id2 ] - category_id2_data.append({ - 'id_level_2': line.category_id2.id, - 'name': line.category_id2.name, - 'numFound': len(line.category_id2.product_tmpl_ids.ids), - 'image': request.env['ir.attachment'].api_image('product.public.category', 'image_1920', - line.category_id2.id), - 'child_frontend_id_i': category_id3_data # Add Category Level 3 data + 'id_level_2': x.id, + 'name': x.name, + 'numFound': len(x.product_tmpl_ids.ids), + 'image': request.env['ir.attachment'].api_image('product.public.category', 'image_1920', x.id), + 'child_frontend_id_i': child_data }) - # Add data for Category Level 1 along with its lines (Category Level 2) data.append({ 'id': category.id, 'sequence': category.sequence, 'category_id_i': category.category_id.id, 'name': category.category_id.name, - 'numFound': len(category.category_id.product_tmpl_ids.ids), - 'image': request.env['ir.attachment'].api_image('product.public.category', 'image_1920', - category.category_id.id), - 'categories': category_id2_data, # Category Level 2 with Level 3 nested inside + 'numFound': len(category.category_id.product_tmpl_ids.ids) , + 'image': request.env['ir.attachment'].api_image('product.public.category', 'image_1920', category.category_id.id), + 'categories': category_id2_data, }) - return self.response(data, headers=[('Cache-Control', 'max-age=3600, public')]) -- cgit v1.2.3 From 8940e5abaa3f4627875e93820aac95c032a03788 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 6 Sep 2024 09:53:17 +0700 Subject: back to code api original --- indoteknik_api/controllers/api_v1/category_management.py | 1 + 1 file changed, 1 insertion(+) (limited to 'indoteknik_api/controllers') diff --git a/indoteknik_api/controllers/api_v1/category_management.py b/indoteknik_api/controllers/api_v1/category_management.py index c7c4651d..c0ecc6b9 100644 --- a/indoteknik_api/controllers/api_v1/category_management.py +++ b/indoteknik_api/controllers/api_v1/category_management.py @@ -7,6 +7,7 @@ class CategoryManagement(controller.Controller): prefix = '/api/v1/' @http.route(prefix + 'categories_management', auth='public', methods=['GET', 'OPTIONS'], csrf=False) + @controller.Controller.must_authorized() def get_categories_management(self, **kw): base_url = request.env['ir.config_parameter'].sudo().get_param('web.base.url') -- cgit v1.2.3