summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-07-31 16:31:42 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-07-31 16:31:42 +0700
commitf785e7605f4d0151a0f48e3d871b996c40e51351 (patch)
tree937bc48e019bb7963126cfaa52f31c8a343e52bd /indoteknik_custom/models
parent1563299905b3e0cf97129739c0ee0a6269ce4bc8 (diff)
Add flash sale tag on model, view, api response
Diffstat (limited to 'indoteknik_custom/models')
-rw-r--r--indoteknik_custom/models/product_pricelist.py7
-rwxr-xr-xindoteknik_custom/models/product_template.py8
2 files changed, 8 insertions, 7 deletions
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):