From 0e9e58da406e62a72ce2ba18c6317e3de57963a1 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 29 Aug 2024 13:09:54 +0700 Subject: cr api voucher --- indoteknik_custom/models/website_user_cart.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'indoteknik_custom/models/website_user_cart.py') diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py index d9352abb..c233dfd7 100644 --- a/indoteknik_custom/models/website_user_cart.py +++ b/indoteknik_custom/models/website_user_cart.py @@ -91,7 +91,7 @@ class WebsiteUserCart(models.Model): products = carts.get_products() return products - def get_user_checkout(self, user_id, voucher=False, source=False): + def get_user_checkout(self, user_id, voucher=False, voucher_shipping=False, source=False): products = self.get_product_by_user(user_id=user_id, selected=True, source=source) total_purchase = 0 @@ -109,12 +109,12 @@ class WebsiteUserCart(models.Model): subtotal = total_purchase - total_discount discount_voucher = 0 - if voucher: - order_line = [] + discount_voucher_shipping = 0 + order_line = [] + + if voucher or voucher_shipping: for product in products: - if product['cart_type'] == 'promotion': - continue - + if product['cart_type'] == 'promotion': continue order_line.append({ 'product_id': self.env['product.product'].browse(product['id']), 'price': product['price']['price'], @@ -122,9 +122,16 @@ class WebsiteUserCart(models.Model): 'qty': product['quantity'], 'subtotal': product['subtotal'] }) + + if voucher: voucher_info = voucher.apply(order_line) discount_voucher = voucher_info['discount']['all'] subtotal -= discount_voucher + + if voucher_shipping: + voucher_shipping_info = voucher_shipping.apply(order_line) + discount_voucher_shipping = voucher_shipping_info['discount']['all'] + tax = round(subtotal * 0.11) grand_total = subtotal + tax total_weight = sum(x['weight'] * x['quantity'] for x in products) @@ -133,6 +140,7 @@ class WebsiteUserCart(models.Model): 'total_purchase': total_purchase, 'total_discount': total_discount, 'discount_voucher': discount_voucher, + 'discount_voucher_shipping': discount_voucher_shipping, 'subtotal': subtotal, 'tax': tax, 'grand_total': round(grand_total), -- cgit v1.2.3 From 00b552bcdd7a689cf347aa2b882ec6796f42bc20 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 29 Aug 2024 14:38:17 +0700 Subject: fix voucher --- indoteknik_custom/models/website_user_cart.py | 1 + 1 file changed, 1 insertion(+) (limited to 'indoteknik_custom/models/website_user_cart.py') diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py index c233dfd7..0af22d47 100644 --- a/indoteknik_custom/models/website_user_cart.py +++ b/indoteknik_custom/models/website_user_cart.py @@ -131,6 +131,7 @@ class WebsiteUserCart(models.Model): if voucher_shipping: voucher_shipping_info = voucher_shipping.apply(order_line) discount_voucher_shipping = voucher_shipping_info['discount']['all'] + subtotal -= discount_voucher_shipping tax = round(subtotal * 0.11) grand_total = subtotal + tax -- cgit v1.2.3 From 1e44c76fa1b4f9aa63599a4efb0adb84b3adba75 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 2 Sep 2024 09:30:18 +0700 Subject: cr api get cart --- indoteknik_custom/models/website_user_cart.py | 1 + 1 file changed, 1 insertion(+) (limited to 'indoteknik_custom/models/website_user_cart.py') diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py index 0af22d47..581ed4cd 100644 --- a/indoteknik_custom/models/website_user_cart.py +++ b/indoteknik_custom/models/website_user_cart.py @@ -32,6 +32,7 @@ class WebsiteUserCart(models.Model): if self.product_id: res['cart_type'] = 'product' + res['active'] = True if self.product_id.active else False product = self.product_id.v2_api_single_response(self.product_id) res.update(product) -- cgit v1.2.3 From 9808cae54a32a65a41d0a13a141e62d88abedfef Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 2 Sep 2024 16:14:26 +0700 Subject: cr api get user cart --- indoteknik_custom/models/website_user_cart.py | 110 +++++++++++++++++++------- 1 file changed, 81 insertions(+), 29 deletions(-) (limited to 'indoteknik_custom/models/website_user_cart.py') diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py index 581ed4cd..0fd8df98 100644 --- a/indoteknik_custom/models/website_user_cart.py +++ b/indoteknik_custom/models/website_user_cart.py @@ -23,36 +23,46 @@ class WebsiteUserCart(models.Model): record.user_other_carts = others def get_product(self): - res = { - 'cart_id': self.id, - 'quantity': self.qty, - 'selected': self.is_selected, - 'can_buy': True - } - if self.product_id: - res['cart_type'] = 'product' - res['active'] = True if self.product_id.active else False - product = self.product_id.v2_api_single_response(self.product_id) - res.update(product) - - # Check if the product's inventory location is in ID 57 or 83 - target_locations = [57, 83] - stock_quant = self.env['stock.quant'].search([ - ('product_id', '=', self.product_id.id), - ('location_id', 'in', target_locations) - ]) - - if stock_quant: - res['is_in_bu'] = True - res['on_hand_qty'] = sum(stock_quant.mapped('quantity')) - else: - res['is_in_bu'] = False - res['on_hand_qty'] = 0 + base_price = self.product_id._v2_get_website_price_include_tax() + active = self.product_id.active + if base_price > 0 and active: + res = { + 'cart_id': self.id, + 'quantity': self.qty, + 'selected': self.is_selected, + 'can_buy': True + } + res['cart_type'] = 'product' + res['active'] = True if self.product_id.active else False + product = self.product_id.v2_api_single_response(self.product_id) + res.update(product) + + # Check if the product's inventory location is in ID 57 or 83 + target_locations = [57, 83] + stock_quant = self.env['stock.quant'].search([ + ('product_id', '=', self.product_id.id), + ('location_id', 'in', target_locations) + ]) + + if stock_quant: + res['is_in_bu'] = True + res['on_hand_qty'] = sum(stock_quant.mapped('quantity')) + else: + res['is_in_bu'] = False + res['on_hand_qty'] = 0 - flashsales = self.product_id._get_active_flash_sale() - res['has_flashsale'] = True if len(flashsales) > 0 else False + flashsales = self.product_id._get_active_flash_sale() + res['has_flashsale'] = True if len(flashsales) > 0 else False + res['subtotal'] = self.qty * res['price']['price_discount'] + return res elif self.program_line_id: + res = { + 'cart_id': self.id, + 'quantity': self.qty, + 'selected': self.is_selected, + 'can_buy': True + } res['cart_type'] = 'promotion' userdata = { 'partner_id': self.user_id.partner_id.id, @@ -63,14 +73,56 @@ class WebsiteUserCart(models.Model): if program['remaining_qty']['transaction'] < self.qty: res['can_buy'] = False - res['subtotal'] = self.qty * res['price']['price_discount'] + res['subtotal'] = self.qty * res['price']['price_discount'] - return res + return res def get_products(self): products = [x.get_product() for x in self] return products + + def get_product_inactive(self): + if self.product_id: + base_price = self.product_id._v2_get_website_price_include_tax() + active = self.product_id.active + if base_price == 0 or not active: + res = { + 'cart_id': self.id, + 'quantity': self.qty, + 'selected': self.is_selected, + 'can_buy': True + } + res['cart_type'] = 'product' + res['active'] = True if self.product_id.active else False + product = self.product_id.v2_api_single_response(self.product_id) + res.update(product) + + # Check if the product's inventory location is in ID 57 or 83 + target_locations = [57, 83] + stock_quant = self.env['stock.quant'].search([ + ('product_id', '=', self.product_id.id), + ('location_id', 'in', target_locations) + ]) + + if stock_quant: + res['is_in_bu'] = True + res['on_hand_qty'] = sum(stock_quant.mapped('quantity')) + else: + res['is_in_bu'] = False + res['on_hand_qty'] = 0 + + flashsales = self.product_id._get_active_flash_sale() + res['has_flashsale'] = True if len(flashsales) > 0 else False + + res['subtotal'] = self.qty * res['price']['price_discount'] + + return res + + def get_products_inactive(self): + products = [x.get_product_inactive() for x in self] + + return products def get_product_by_user(self, user_id, selected=False, source=False): user_id = int(user_id) -- cgit v1.2.3 From 8dab99ed68d5fdc3a47bcd2cd349cad1d93fd53d Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 3 Sep 2024 08:57:48 +0700 Subject: reverse code --- indoteknik_custom/models/website_user_cart.py | 109 +++++++------------------- 1 file changed, 28 insertions(+), 81 deletions(-) (limited to 'indoteknik_custom/models/website_user_cart.py') diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py index 0fd8df98..0af22d47 100644 --- a/indoteknik_custom/models/website_user_cart.py +++ b/indoteknik_custom/models/website_user_cart.py @@ -23,46 +23,35 @@ class WebsiteUserCart(models.Model): record.user_other_carts = others def get_product(self): + res = { + 'cart_id': self.id, + 'quantity': self.qty, + 'selected': self.is_selected, + 'can_buy': True + } + if self.product_id: - base_price = self.product_id._v2_get_website_price_include_tax() - active = self.product_id.active - if base_price > 0 and active: - res = { - 'cart_id': self.id, - 'quantity': self.qty, - 'selected': self.is_selected, - 'can_buy': True - } - res['cart_type'] = 'product' - res['active'] = True if self.product_id.active else False - product = self.product_id.v2_api_single_response(self.product_id) - res.update(product) - - # Check if the product's inventory location is in ID 57 or 83 - target_locations = [57, 83] - stock_quant = self.env['stock.quant'].search([ - ('product_id', '=', self.product_id.id), - ('location_id', 'in', target_locations) - ]) - - if stock_quant: - res['is_in_bu'] = True - res['on_hand_qty'] = sum(stock_quant.mapped('quantity')) - else: - res['is_in_bu'] = False - res['on_hand_qty'] = 0 + res['cart_type'] = 'product' + product = self.product_id.v2_api_single_response(self.product_id) + res.update(product) + + # Check if the product's inventory location is in ID 57 or 83 + target_locations = [57, 83] + stock_quant = self.env['stock.quant'].search([ + ('product_id', '=', self.product_id.id), + ('location_id', 'in', target_locations) + ]) - flashsales = self.product_id._get_active_flash_sale() - res['has_flashsale'] = True if len(flashsales) > 0 else False - res['subtotal'] = self.qty * res['price']['price_discount'] - return res + if stock_quant: + res['is_in_bu'] = True + res['on_hand_qty'] = sum(stock_quant.mapped('quantity')) + else: + res['is_in_bu'] = False + res['on_hand_qty'] = 0 + + flashsales = self.product_id._get_active_flash_sale() + res['has_flashsale'] = True if len(flashsales) > 0 else False elif self.program_line_id: - res = { - 'cart_id': self.id, - 'quantity': self.qty, - 'selected': self.is_selected, - 'can_buy': True - } res['cart_type'] = 'promotion' userdata = { 'partner_id': self.user_id.partner_id.id, @@ -73,56 +62,14 @@ class WebsiteUserCart(models.Model): if program['remaining_qty']['transaction'] < self.qty: res['can_buy'] = False - res['subtotal'] = self.qty * res['price']['price_discount'] + res['subtotal'] = self.qty * res['price']['price_discount'] - return res + return res def get_products(self): products = [x.get_product() for x in self] return products - - def get_product_inactive(self): - if self.product_id: - base_price = self.product_id._v2_get_website_price_include_tax() - active = self.product_id.active - if base_price == 0 or not active: - res = { - 'cart_id': self.id, - 'quantity': self.qty, - 'selected': self.is_selected, - 'can_buy': True - } - res['cart_type'] = 'product' - res['active'] = True if self.product_id.active else False - product = self.product_id.v2_api_single_response(self.product_id) - res.update(product) - - # Check if the product's inventory location is in ID 57 or 83 - target_locations = [57, 83] - stock_quant = self.env['stock.quant'].search([ - ('product_id', '=', self.product_id.id), - ('location_id', 'in', target_locations) - ]) - - if stock_quant: - res['is_in_bu'] = True - res['on_hand_qty'] = sum(stock_quant.mapped('quantity')) - else: - res['is_in_bu'] = False - res['on_hand_qty'] = 0 - - flashsales = self.product_id._get_active_flash_sale() - res['has_flashsale'] = True if len(flashsales) > 0 else False - - res['subtotal'] = self.qty * res['price']['price_discount'] - - return res - - def get_products_inactive(self): - products = [x.get_product_inactive() for x in self] - - return products def get_product_by_user(self, user_id, selected=False, source=False): user_id = int(user_id) -- 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_custom/models/website_user_cart.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'indoteknik_custom/models/website_user_cart.py') diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py index 0af22d47..b0cf47f7 100644 --- a/indoteknik_custom/models/website_user_cart.py +++ b/indoteknik_custom/models/website_user_cart.py @@ -130,8 +130,7 @@ class WebsiteUserCart(models.Model): if voucher_shipping: voucher_shipping_info = voucher_shipping.apply(order_line) - discount_voucher_shipping = voucher_shipping_info['discount']['all'] - subtotal -= discount_voucher_shipping + discount_voucher_shipping = voucher_shipping_info['discount']['all'] tax = round(subtotal * 0.11) grand_total = subtotal + tax -- cgit v1.2.3