summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-08-22 11:05:06 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-08-22 11:05:06 +0700
commit1297a3f4af3c847bcaf04ec7c66f052678a88e84 (patch)
treefa0d7e8f1cf6aa54b99bc49d379dc77277d7c8fd
parent64e790b5d9c923c91bed9f7f9a934e9d229bca2c (diff)
email reminder and cr archive product
-rwxr-xr-xindoteknik_custom/models/product_template.py14
-rw-r--r--indoteknik_custom/models/website_user_cart.py12
2 files changed, 21 insertions, 5 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py
index 56460821..d51f903f 100755
--- a/indoteknik_custom/models/product_template.py
+++ b/indoteknik_custom/models/product_template.py
@@ -337,7 +337,7 @@ class ProductTemplate(models.Model):
raise UserError('Tidak dapat mengubah produk sementara')
return super(ProductTemplate, self).write(vals)
-
+
class ProductProduct(models.Model):
_inherit = "product.product"
web_price = fields.Float(
@@ -367,6 +367,18 @@ class ProductProduct(models.Model):
qty_sold = fields.Float(string='Sold Quantity', compute='_get_qty_sold')
short_spesification = fields.Char(string='Short Spesification')
+ @api.constrains('active')
+ def archive_product(self):
+ for product in self:
+ product_template = product.product_tmpl_id
+ variants = product_template.product_variant_ids
+
+ if product_template.active and product.active:
+ if not product.active and len(variants) == 1:
+ product_template.with_context(skip_active_constraint=True).active = False
+ elif not product.active and len(variants) > 1:
+ continue
+
def update_internal_reference_variants(self, limit=100):
variants = self.env['product.product'].search([
('default_code', '=', False),
diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py
index 10821cd3..d9352abb 100644
--- a/indoteknik_custom/models/website_user_cart.py
+++ b/indoteknik_custom/models/website_user_cart.py
@@ -145,14 +145,15 @@ class WebsiteUserCart(models.Model):
}
return result
- def action_mail_reminder_to_checkout(self):
- user_ids = self.search([]).mapped('user_id')
+ def action_mail_reminder_to_checkout(self, limit=10):
+ user_ids = self.search([]).mapped('user_id')[:limit]
- # user_ids = [1102]
- for user in user_ids:
+ for user in user_ids:
latest_cart = self.search([('user_id', '=', user.id), ('is_reminder', '=', False)], order='create_date desc', limit=1)
+ # Proses semua keranjang untuk user tersebut
carts_to_remind = self.search([('user_id', '=', user.id)])
+
if latest_cart and not latest_cart.is_reminder:
for cart in carts_to_remind:
check = cart.check_product_flashsale(cart.product_id.id)
@@ -161,9 +162,12 @@ class WebsiteUserCart(models.Model):
if cart.program_line_id or check['is_flashsale'] or cart.product_id.default_code and 'BOM' in cart.product_id.default_code:
cart.is_selected = False
cart.is_reminder = True
+
+ # Mengirim email pengingat untuk keranjang terbaru
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)