From 1563299905b3e0cf97129739c0ee0a6269ce4bc8 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 28 Jul 2023 16:53:32 +0700 Subject: Add flash sale remaining time API response --- indoteknik_custom/models/product_pricelist.py | 6 ++++++ indoteknik_custom/models/product_template.py | 13 +++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom') diff --git a/indoteknik_custom/models/product_pricelist.py b/indoteknik_custom/models/product_pricelist.py index 2edaeb80..49927d6b 100644 --- a/indoteknik_custom/models/product_pricelist.py +++ b/indoteknik_custom/models/product_pricelist.py @@ -1,5 +1,6 @@ from odoo import models, fields, api from odoo.exceptions import UserError +from datetime import datetime class ProductPricelist(models.Model): @@ -16,6 +17,11 @@ class ProductPricelist(models.Model): ], string='Flashsale Option') banner_top = fields.Binary(string='Banner Top') + def _remaining_time_in_second(self): + if not self.end_date: + return 0 + return round((self.end_date - datetime.now()).total_seconds()) + class ProductPricelistItem(models.Model): _inherit = 'product.pricelist.item' diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 1a83b702..24264366 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -29,8 +29,7 @@ class ProductTemplate(models.Model): digits='Product Price', inverse='_set_product_lst_price', help="Web Price with pricelist_id = 1") qty_stock_vendor = fields.Float('QTY Stock Vendor', compute='_compute_qty_stock_vendor') - have_promotion_program = fields.Boolean('Have Promotion Program', compute='_have_promotion_program', - help="Punya promotion program gak?") + have_promotion_program = fields.Boolean('Have Promotion Program', compute='_have_promotion_program', help="Punya promotion program gak?") product_rating = fields.Float('Product Rating', help="Digunakan untuk sorting product di website", default=0.0) virtual_rating = fields.Float('Virtual Rating', compute='_compute_virtual_rating', help="Column Virtual untuk product rating, digunakan oleh Solr", default=0.0) last_calculate_rating = fields.Datetime("Last Calculate Rating") @@ -155,6 +154,16 @@ class ProductTemplate(models.Model): else: template.have_promotion_program = False + def _get_flash_sale_remaining_time(self): + variant_ids = [x.id for x in self.product_variant_ids] + pricelist = self.env['product.pricelist'].search([ + ('is_flash_sale', '=', True), + ('item_ids.product_id', 'in', variant_ids) + ]) + if not pricelist: + return 0 + return pricelist._remaining_time_in_second() + @api.model def _calculate_rating_product(self): #["&","&",["type","=","product"],["active","=",True],"|",["last_calculate_rating","=",False],["last_calculate_rating","<","2023-01-01 00:00:00"]] -- cgit v1.2.3 From f785e7605f4d0151a0f48e3d871b996c40e51351 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Mon, 31 Jul 2023 16:31:42 +0700 Subject: Add flash sale tag on model, view, api response --- indoteknik_custom/models/product_pricelist.py | 7 +++-- indoteknik_custom/models/product_template.py | 8 +++--- indoteknik_custom/views/product_pricelist.xml | 37 +++++++++++---------------- 3 files changed, 23 insertions(+), 29 deletions(-) (limited to 'indoteknik_custom') diff --git a/indoteknik_custom/models/product_pricelist.py b/indoteknik_custom/models/product_pricelist.py index 49927d6b..95e63cf0 100644 --- a/indoteknik_custom/models/product_pricelist.py +++ b/indoteknik_custom/models/product_pricelist.py @@ -14,13 +14,16 @@ class ProductPricelist(models.Model): flashsale_option = fields.Selection([ ('all', 'For All User'), ('registered_user', 'Only for Registered User') - ], string='Flashsale Option') + ], string='Flash Sale Option') banner_top = fields.Binary(string='Banner Top') + flashsale_tag = fields.Char(string='Flash Sale Tag') def _remaining_time_in_second(self): if not self.end_date: return 0 - return round((self.end_date - datetime.now()).total_seconds()) + remaining_time = (self.end_date - datetime.now()).total_seconds() + remaining_time = round(remaining_time) + return max(remaining_time, 0) class ProductPricelistItem(models.Model): diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 24264366..0b9b1945 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -154,15 +154,13 @@ class ProductTemplate(models.Model): else: template.have_promotion_program = False - def _get_flash_sale_remaining_time(self): + def _get_active_flash_sale(self): variant_ids = [x.id for x in self.product_variant_ids] pricelist = self.env['product.pricelist'].search([ ('is_flash_sale', '=', True), ('item_ids.product_id', 'in', variant_ids) - ]) - if not pricelist: - return 0 - return pricelist._remaining_time_in_second() + ], limit=1) + return pricelist @api.model def _calculate_rating_product(self): diff --git a/indoteknik_custom/views/product_pricelist.xml b/indoteknik_custom/views/product_pricelist.xml index 0ad9e200..55139a24 100644 --- a/indoteknik_custom/views/product_pricelist.xml +++ b/indoteknik_custom/views/product_pricelist.xml @@ -7,29 +7,22 @@ - - - - - - - - - - + + + + + + + + + + + + + + + \ No newline at end of file -- cgit v1.2.3 From f8e0259289c728b11a373601e569f6e64ca803f8 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Tue, 1 Aug 2023 11:32:11 +0700 Subject: Update voucher can't combined with other promotions --- indoteknik_custom/models/product_template.py | 9 ++++++++- indoteknik_custom/models/website_user_cart.py | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom') diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 0b9b1945..e07adf30 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -327,4 +327,11 @@ class ProductProduct(models.Model): def unlink(self): if self._name == 'product.product': - raise UserError('Maaf anda tidak bisa delete product') \ No newline at end of file + raise UserError('Maaf anda tidak bisa delete product') + + def _get_active_flash_sale(self): + pricelist = self.env['product.pricelist'].search([ + ('is_flash_sale', '=', True), + ('item_ids.product_id', '=', self.id) + ], limit=1) + return pricelist \ No newline at end of file diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py index 4d85e64d..9b82aa93 100644 --- a/indoteknik_custom/models/website_user_cart.py +++ b/indoteknik_custom/models/website_user_cart.py @@ -27,6 +27,8 @@ class WebsiteUserCart(models.Model): product['selected'] = self.is_selected product['program'] = None product['can_buy'] = True + product_flashsale = self.product_id._get_active_flash_sale() + product['has_flashsale'] = True if len(product_flashsale) > 0 else False if self.program_line_id: product['program'] = self.program_line_id.res_format_cart(user=user_data, quantity=self.qty) -- cgit v1.2.3 From f0f30aa566c0e49b03fd86f86bbcd80d6c7383ce Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Thu, 3 Aug 2023 09:37:08 +0700 Subject: Fix get active flashsale on variant --- indoteknik_custom/models/product_template.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom') diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 72fb4dea..bc54b703 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -322,8 +322,11 @@ class ProductProduct(models.Model): raise UserError('Maaf anda tidak bisa delete product') def _get_active_flash_sale(self): + current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') pricelist = self.env['product.pricelist'].search([ ('is_flash_sale', '=', True), - ('item_ids.product_id', '=', self.id) + ('item_ids.product_id', '=', self.id), + ('start_date', '<=', current_time), + ('end_date', '>=', current_time) ], limit=1) return pricelist \ No newline at end of file -- cgit v1.2.3