diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2024-07-26 15:43:11 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2024-07-26 15:43:11 +0700 |
| commit | 5e6c42803281ffc3098061113ca153a59a6eeb58 (patch) | |
| tree | 4bfd4a6b14e0559efcb128ea05a45c8ff30cac85 | |
| parent | 5bebaee33872d528f1b007a1cb0cc28cfb39cab0 (diff) | |
refactor email reminder user checkout
| -rw-r--r-- | indoteknik_custom/models/website_user_cart.py | 49 | ||||
| -rwxr-xr-x | 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 @@ <!-- Tabel Produk --> % set base_url = object.env['ir.config_parameter'].get_param('web.base.url') <table style="box-shadow: rgba(0, 0, 0, 0.16) 0px 1px 4px; width: 100%; margin-bottom: 12px; color: black !important; border-collapse: collapse;"> - <thead> - <tr> - <th style="border: 1px solid #dddddd; padding: 8px;">Nama Produk</th> - <th style="border: 1px solid #dddddd; padding: 8px;">Harga Diskon</th> - <th style="border: 1px solid #dddddd; padding: 8px;">Jumlah</th> - <th style="border: 1px solid #dddddd; padding: 8px;">Subtotal</th> - </tr> - </thead> <tbody> % 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 <tr> % 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 <td style="border: 1px solid #dddddd; padding: 8px;"> - <div style="text-align: left; margin-bottom: 16px;"> - <img src="${base_url}api/image/promotion.program/image/${promo[0].program_line_id.program_id.id}" alt="${promo[0].program_line_id.program_id.name}" width="120" height="120" style="object-fit: fill; object-position: center;"/> + <div class="container text-center"> + <div style="display: flex; gap: 20px; align-items: center; margin-top: 8px;"> + <div class="col-3"> + <img src="${base_url}api/image/promotion.program/image/${promo[0].program_line_id.program_id.id}" alt="${promo[0].program_line_id.program_id.name}" width="120" height="120" style="object-fit: fill; object-position: center;"/> + </div> + <div class="col-6" style="margin-top: 1rem; margin-left: 1.5rem;"> + <div style="font-weight: 600; margin-bottom: 8px;">${promo[0].program_line_id.name}</div> + <div style="display: flex; gap: 20px; align-items: center; margin-bottom: 8px;"> + <div style="color: grey; text-decoration: line-through; margin-right: 20px;"> + Rp ${cart.format_currency(promo[0].program_line_id.price)} + </div> + <div style="color: red; font-weight: bold;"> + Rp ${cart.format_currency(promo[0].program_line_id.price)} + </div> + </div> + <div style="color: grey;"> + Berat barang: ${weight} Kg + </div> + </div> + <div class="col-3"> + <button type="button" class="btn btn-outline-secondary" style="margin-left: 11rem; margin-top: 2.5rem;">${cart.format_integer(cart.qty)}</button> + </div> + </div> </div> - <div style="display: block; gap: 16px; justify-content: center;"> + <div style="display: block; gap: 16px; justify-content: center; margin-left: 2rem;"> % for data in promo: - <div style="text-align: center;"> - <img src="${base_url}api/image/product.template/image_512/${data.product_id.product_tmpl_id.id}" alt="${data.product_id.name}" width="100" height="100" style="object-fit: fill; object-position: center;"/> - <div style="font-weight: 600; margin-top: 4px;">${data.product_id.name}</div> + <div class="container text-center"> + <div style="display: flex; gap: 20px; align-items: center; margin-top: 8px;"> + <div class="col-3"> + <img src="${base_url}api/image/product.template/image_512/${data.product_id.product_tmpl_id.id}" alt="${data.product_id.name}" width="120" height="120" style="object-fit: fill; object-position: center;"/> + </div> + <div class="col-6" style="margin-top: 1rem; margin-left: 1.5rem;"> + <div style="font-weight: 400; margin-bottom: 8px;">${data.product_id.name}</div> + <div style="color: grey;"> + ${data.product_id.default_code} | Berat barang: ${data.product_id.weight} Kg + </div> + </div> + <div class="col-3"> + <button type="button" class="btn btn-outline-secondary" style="margin-left: 9rem; margin-top: 2.5rem;">${data.qty}</button> + </div> + </div> + </div> + % endfor + % for free in free_product: + <div class="container text-center"> + <div style="display: flex; gap: 20px; align-items: center; margin-top: 8px;"> + <div class="col-3"> + <img src="${base_url}api/image/product.template/image_512/${free.product_id.product_tmpl_id.id}" alt="${free.product_id.name}" width="120" height="120" style="object-fit: fill; object-position: center;"/> + </div> + <div class="col-6" style="margin-top: 1rem; margin-left: 1.5rem;"> + <div style="font-weight: 400; margin-bottom: 8px;">${free.product_id.name}</div> + <div style="color: grey;"> + ${free.product_id.default_code} | Berat barang: ${free.product_id.weight} Kg + </div> + </div> + <div class="col-3"> + <button type="button" class="btn btn-outline-secondary" style="margin-left: 9rem; margin-top: 2.5rem;">${free.qty}</button> + </div> + </div> </div> % endfor </div> - </td> - <td style="border: 1px solid #dddddd; padding: 8px;"> - <div>Rp${cart.format_currency(promo[0].program_line_id.price)}</div> - </td> - <td style="border: 1px solid #dddddd; padding: 8px;"> - <div>${'%d pcs' % cart.qty}</div> - </td> - <td style="border: 1px solid #dddddd; padding: 8px;"> - <div style="font-weight: 600;">Rp${cart.format_currency(subtotal)}</div> </td> % else: <td colspan="4" style="border: 1px solid #dddddd; padding: 8px; text-align: center;"> @@ -178,22 +213,36 @@ % endif % else: <td style="border: 1px solid #dddddd; padding: 8px;"> - <img src="${base_url}api/image/product.template/image_512/${product_template_id}" alt="${cart.product_id.name}" width="120" height="120" style="object-fit: fill; object-position: center;"/> - <div style="font-weight: 600;">${cart.product_id.name}</div> - </td> - <td style="border: 1px solid #dddddd; padding: 8px;"> - <div>Rp${cart.format_currency(product_price['price'])}</div> - </td> - <td style="border: 1px solid #dddddd; padding: 8px;"> - <div>${'%d pcs' % cart.qty}</div> - </td> - <td style="border: 1px solid #dddddd; padding: 8px;"> - <div style="font-weight: 600;">Rp${cart.format_currency(subtotal)}</div> - </td> + <div class="container text-center"> + <div style="display: flex; gap: 20px; align-items: center; margin-top: 8px;"> + <div class="col-3"> + <img src="${base_url}api/image/product.template/image_512/${product_template_id}" + alt="${cart.product_id.name}" width="120" height="120" + style="object-fit: fill; object-position: center;"/> + </div> + <div class="col-6"> + <div style="font-weight: 600; margin-bottom: 8px;">${cart.product_id.name}</div> + <div style="display: flex; gap: 20px; align-items: center; margin-bottom: 8px;"> + <div style="color: grey; text-decoration: line-through; margin-right: 20px;"> + Rp${cart.format_currency(product_price['price'])} + </div> + <div style="color: red; font-weight: bold;"> + Rp${cart.format_currency(product_price['price'])} + </div> + </div> + <div style="color: grey;"> + ${cart.product_id.default_code} | Berat barang: ${cart.product_id.weight} Kg + </div> + </div> + <div class="col-3"> + <button type="button" class="btn btn-outline-secondary" style="margin-left: 11rem; margin-top: 2.5rem;">${cart.format_integer(cart.qty)}</button> + </div> + </div> + </div> + </td> % endif </tr> % endfor - </tbody> </table> % set totalan = object.calculate_discount(object.user_id.id) @@ -201,14 +250,6 @@ <table style="width: 100%; margin-top: 12px; color: black !important; border-collapse: collapse;"> <tbody> <tr> - <td style="text-align: right; padding: 8px;"><b>Subtotal:</b></td> - <td style="text-align: right; padding: 8px;">Rp${totalan['subtotal_website']}</td> - </tr> - <tr> - <td style="text-align: right; padding: 8px;"><b>Pakai Voucher:</b></td> - <td style="text-align: right; padding: 8px; color: green;"><b>(Potensi Potongan)</b> <b>Rp${totalan['total_voucher']}</b></td> - </tr> - <tr> <td style="text-align: right; padding: 8px;"><b>Total:</b></td> <td style="text-align: right; padding: 8px;">Rp${totalan['total_discount']}</td> </tr> @@ -220,6 +261,10 @@ <td style="text-align: right; padding: 8px;"><b>Grand Total:</b></td> <td style="text-align: right; padding: 8px;"><b>Rp${totalan['grand_total']}</b></td> </tr> + <tr> + <td style="text-align: right; padding: 8px;"><b>Pakai Voucher:</b></td> + <td style="text-align: right; padding: 8px; color: green;"><b>(Potensi Potongan)</b> <b>Rp${totalan['total_voucher']}</b></td> + </tr> </tbody> </table> </td> |
