summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-07-26 15:43:11 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-07-26 15:43:11 +0700
commit5e6c42803281ffc3098061113ca153a59a6eeb58 (patch)
tree4bfd4a6b14e0559efcb128ea05a45c8ff30cac85 /indoteknik_custom/models
parent5bebaee33872d528f1b007a1cb0cc28cfb39cab0 (diff)
refactor email reminder user checkout
Diffstat (limited to 'indoteknik_custom/models')
-rw-r--r--indoteknik_custom/models/website_user_cart.py49
1 files changed, 33 insertions, 16 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