From 5e6c42803281ffc3098061113ca153a59a6eeb58 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 26 Jul 2024 15:43:11 +0700 Subject: refactor email reminder user checkout --- indoteknik_custom/models/website_user_cart.py | 49 +++++++--- indoteknik_custom/views/website_user_cart.xml | 135 +++++++++++++++++--------- 2 files changed, 123 insertions(+), 61 deletions(-) diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py index 793dda0b..b4eba476 100644 --- a/indoteknik_custom/models/website_user_cart.py +++ b/indoteknik_custom/models/website_user_cart.py @@ -158,21 +158,26 @@ class WebsiteUserCart(models.Model): product_price = cart.get_price_website(cart.product_id.id) subtotal = product_price['price'] * cart.qty subtotal_website += product_price['price'] - discount_amount = 0.0 + subtotal_promo = 0.0 + + if cart.program_line_id: + subtotal_website += cart.program_line_id.price + subtotal_promo = cart.program_line_id.price * cart.qty - for line in voucher.voucher_line: - if line.manufacture_id.id == product_manufacture: - discount_amount = line.discount_amount - break + discount_amount = 0.0 + if product_manufacture: + for line in voucher.voucher_line: + if line.manufacture_id.id == product_manufacture: + discount_amount = line.discount_amount + break - if discount_amount > 0 and subtotal > 0: - product_discount = subtotal - (subtotal * (discount_amount / 100.0)) - voucher_product = subtotal * (discount_amount / 100.0) - total_discount += product_discount - total_voucher += voucher_product + product_discount = subtotal_promo if cart.program_line_id else subtotal + voucher_product = subtotal * (discount_amount / 100.0) + total_discount += product_discount + total_voucher += voucher_product if total_discount > 0: - ppn = total_discount * 0.11 + ppn = subtotal_website * 0.11 return { 'total_discount': self.format_currency(total_discount), 'total_voucher': self.format_currency(total_voucher), @@ -183,10 +188,20 @@ class WebsiteUserCart(models.Model): return self.format_currency(0.0) def get_data_promo(self, program_line_id): - program_line_product = self.env['promotion.product'].search([ - ('program_line_id', '=', program_line_id) - ]) - return program_line_product + criteria = [('program_line_id', '=', program_line_id)] + return ( + self.env['promotion.product'].search(criteria), + self.env['promotion.free_product'].search(criteria) + ) + + def get_weight_product(self, program_line_id): + products = self.env['promotion.product'].search([('program_line_id', '=', program_line_id)]) + free_products = self.env['promotion.free_product'].search([('program_line_id', '=', program_line_id)]) + + all_products = products + free_products + real_weight = sum(product.product_id.weight for product in all_products) + + return real_weight def get_price_website(self, product_id): price_website = self.env['product.pricelist.item'].search([('product_id', '=', product_id), ('pricelist_id', '=', 17022)], limit=1) @@ -205,8 +220,10 @@ class WebsiteUserCart(models.Model): 'web_price': discounted_price } + def format_integer(self, number): + number = int(number) + return number - def format_currency(self, number): number = int(number) return "{:,}".format(number).replace(',', '.') \ No newline at end of file diff --git a/indoteknik_custom/views/website_user_cart.xml b/indoteknik_custom/views/website_user_cart.xml index a1407355..64a7eff7 100755 --- a/indoteknik_custom/views/website_user_cart.xml +++ b/indoteknik_custom/views/website_user_cart.xml @@ -131,14 +131,6 @@ % set base_url = object.env['ir.config_parameter'].get_param('web.base.url') - - - - - - - - % for cart in object.user_other_carts: % set product_price = cart.get_price_website(cart.product_id.id) @@ -146,30 +138,73 @@ % set subtotal = product_price['price'] * cart.qty % if cart.program_line_id: - % set promo = cart.get_data_promo(cart.program_line_id.id) + % set promo, free_product = cart.get_data_promo(cart.program_line_id.id) % if promo: + % set weight = cart.get_weight_product(cart.program_line_id.id) % set subtotal = promo[0].program_line_id.price * cart.qty - - - % else: - - - +
+
+
+ ${cart.product_id.name} +
+
+
${cart.product_id.name}
+
+
+ Rp${cart.format_currency(product_price['price'])} +
+
+ Rp${cart.format_currency(product_price['price'])} +
+
+
+ ${cart.product_id.default_code} | Berat barang: ${cart.product_id.weight} Kg +
+
+
+ +
+
+
+ % endif % endfor -
Nama ProdukHarga DiskonJumlahSubtotal
-
- ${promo[0].program_line_id.program_id.name} +
+
+
+ ${promo[0].program_line_id.program_id.name} +
+
+
${promo[0].program_line_id.name}
+
+
+ Rp ${cart.format_currency(promo[0].program_line_id.price)} +
+
+ Rp ${cart.format_currency(promo[0].program_line_id.price)} +
+
+
+ Berat barang: ${weight} Kg +
+
+
+ +
+
-
+
% for data in promo: -
- ${data.product_id.name} -
${data.product_id.name}
+
+
+
+ ${data.product_id.name} +
+
+
${data.product_id.name}
+
+ ${data.product_id.default_code} | Berat barang: ${data.product_id.weight} Kg +
+
+
+ +
+
+
+ % endfor + % for free in free_product: +
+
+
+ ${free.product_id.name} +
+
+
${free.product_id.name}
+
+ ${free.product_id.default_code} | Berat barang: ${free.product_id.weight} Kg +
+
+
+ +
+
% endfor
-
-
Rp${cart.format_currency(promo[0].program_line_id.price)}
-
-
${'%d pcs' % cart.qty}
-
-
Rp${cart.format_currency(subtotal)}
@@ -178,36 +213,42 @@ % endif % else: - ${cart.product_id.name} -
${cart.product_id.name}
-
-
Rp${cart.format_currency(product_price['price'])}
-
-
${'%d pcs' % cart.qty}
-
-
Rp${cart.format_currency(subtotal)}
-
% set totalan = object.calculate_discount(object.user_id.id) - - - - - - - - @@ -220,6 +261,10 @@ + + + +
Subtotal:Rp${totalan['subtotal_website']}
Pakai Voucher:(Potensi Potongan) Rp${totalan['total_voucher']}
Total: Rp${totalan['total_discount']}Grand Total: Rp${totalan['grand_total']}
Pakai Voucher:(Potensi Potongan) Rp${totalan['total_voucher']}
-- cgit v1.2.3