summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-07-25 15:44:26 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-07-25 15:44:26 +0700
commit34e3cc9c3307be1eacdc8744d377f03689aea0a7 (patch)
tree44f3b44da4fa04e7da940f2ac09f681f70ee8b88 /indoteknik_custom/models
parentc0a913efe390bad9dde397dd1627b3baf682a8f9 (diff)
email reminder cekout
Diffstat (limited to 'indoteknik_custom/models')
-rw-r--r--indoteknik_custom/models/website_user_cart.py82
1 files changed, 78 insertions, 4 deletions
diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py
index bbff6035..793dda0b 100644
--- a/indoteknik_custom/models/website_user_cart.py
+++ b/indoteknik_custom/models/website_user_cart.py
@@ -1,5 +1,5 @@
from odoo import fields, models
-
+from datetime import datetime, timedelta
class WebsiteUserCart(models.Model):
_name = 'website.user.cart'
@@ -15,6 +15,7 @@ class WebsiteUserCart(models.Model):
('buy', 'Buy')
], 'Source', default='add_to_cart')
user_other_carts = fields.One2many('website.user.cart', 'id', 'Other Products', compute='_compute_user_other_carts')
+ is_reminder = fields.Boolean(string='Reminder?')
def _compute_user_other_carts(self):
for record in self:
@@ -129,10 +130,83 @@ class WebsiteUserCart(models.Model):
}
return result
- def action_mail_reminder_to_checkout(self, id):
- template = self.env.ref('indoteknik_custom.mail_template_user_cart_reminder_to_checkout')
- template.send_mail(int(id), force_send=True)
+ def action_mail_reminder_to_checkout(self):
+ # user_ids = self.search([]).mapped('user_id')
+
+ user_ids = [101]
+ for user in user_ids:
+ latest_cart = self.search([('user_id', '=', user), ('is_reminder', '=', False)], order='create_date desc', limit=1)
+
+ carts_to_remind = self.search([('user_id', '=', user)])
+ if latest_cart and not latest_cart.is_reminder:
+ for cart in carts_to_remind:
+ if not cart.program_line_id:
+ cart.is_selected = True
+ cart.is_reminder = True
+ template = self.env.ref('indoteknik_custom.mail_template_user_cart_reminder_to_checkout')
+ template.send_mail(latest_cart.id, force_send=True)
+
+ def calculate_discount(self, user_id):
+ carts = self.search([('user_id', '=', user_id)])
+ voucher = self.env['voucher'].browse(146)
+ total_discount = 0.01
+ total_voucher = 0.0
+ subtotal_website = 0.0
+
+ for cart in carts:
+ product_manufacture = cart.product_id.x_manufacture.id
+ 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
+ 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
+
+ if total_discount > 0:
+ ppn = total_discount * 0.11
+ return {
+ 'total_discount': self.format_currency(total_discount),
+ 'total_voucher': self.format_currency(total_voucher),
+ 'subtotal_website': self.format_currency(subtotal_website),
+ 'ppn': self.format_currency(ppn),
+ 'grand_total': self.format_currency(total_discount + ppn)
+ }
+ 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
+
+ def get_price_website(self, product_id):
+ price_website = self.env['product.pricelist.item'].search([('product_id', '=', product_id), ('pricelist_id', '=', 17022)], limit=1)
+
+ price_tier = self.env['product.pricelist.item'].search([('product_id', '=', product_id), ('pricelist_id', '=', 17023)], limit=1)
+
+ fixed_price = price_website.fixed_price if price_website else 0.0
+ discount = price_tier.price_discount if price_tier else 0.0
+
+ discounted_price = fixed_price - (fixed_price * discount / 100)
+
+ final_price = discounted_price / 1.11
+
+ return {
+ 'price': final_price,
+ 'web_price': discounted_price
+ }
+
+
+
def format_currency(self, number):
number = int(number)
return "{:,}".format(number).replace(',', '.') \ No newline at end of file