diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2023-08-04 03:59:33 +0000 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2023-08-04 03:59:33 +0000 |
| commit | 6d17228cd6c789fe4460e28807d5b39fb1bbe9b7 (patch) | |
| tree | a4c961062c026e1005ebdc82547903c3f30c0a06 /indoteknik_custom/models | |
| parent | cc182dd9963fb8985661ca1b64a53e7f11f095c5 (diff) | |
| parent | bcc35009da39e9ee8b5e181006d3690316b83c59 (diff) | |
Merged in development (pull request #82)
Development
Diffstat (limited to 'indoteknik_custom/models')
| -rw-r--r-- | indoteknik_custom/models/product_pricelist.py | 11 | ||||
| -rwxr-xr-x | indoteknik_custom/models/product_template.py | 23 | ||||
| -rw-r--r-- | indoteknik_custom/models/website_user_cart.py | 2 |
3 files changed, 32 insertions, 4 deletions
diff --git a/indoteknik_custom/models/product_pricelist.py b/indoteknik_custom/models/product_pricelist.py index 2edaeb80..95e63cf0 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): @@ -13,8 +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 + 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 e48136fa..bc54b703 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,14 @@ class ProductTemplate(models.Model): else: template.have_promotion_program = False + 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) + ], limit=1) + return pricelist + @api.model def _calculate_rating_product(self, limit=1000, expiry_days=30, ids=False): current_time = datetime.now() @@ -312,4 +319,14 @@ 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): + 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), + ('start_date', '<=', current_time), + ('end_date', '>=', current_time) + ], 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) |
