diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2023-07-31 09:33:19 +0000 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2023-07-31 09:33:19 +0000 |
| commit | 61bbb1b7164378a31522312ca3a076d6d35141d3 (patch) | |
| tree | 792601c9fdae3daa45d290dd0de150a4e3c79fe3 | |
| parent | bf45239720a7eaa49557087fdfd523611b048a7c (diff) | |
| parent | f785e7605f4d0151a0f48e3d871b996c40e51351 (diff) | |
Merged in feature/voucher-cart (pull request #78)
Add flash sale tag on model, view, api response
| -rw-r--r-- | indoteknik_api/models/product_template.py | 7 | ||||
| -rw-r--r-- | indoteknik_custom/models/product_pricelist.py | 7 | ||||
| -rwxr-xr-x | indoteknik_custom/models/product_template.py | 8 | ||||
| -rw-r--r-- | indoteknik_custom/views/product_pricelist.xml | 37 |
4 files changed, 28 insertions, 31 deletions
diff --git a/indoteknik_api/models/product_template.py b/indoteknik_api/models/product_template.py index b01e957b..fb77769f 100644 --- a/indoteknik_api/models/product_template.py +++ b/indoteknik_api/models/product_template.py @@ -70,9 +70,12 @@ class ProductTemplate(models.Model): for variant in variants: if variant["price"]["price_discount"] < lowest_price["price_discount"]: lowest_price = variant['price'] - + template_pricelist = product_template._get_active_flash_sale() data_with_detail = { - 'flash_sale_remaining_time': product_template._get_flash_sale_remaining_time(), + 'flash_sale': { + 'remaining_time': template_pricelist._remaining_time_in_second() if template_pricelist else 0, + 'tag': template_pricelist.flashsale_tag if template_pricelist else None + }, 'lowest_price': lowest_price, 'image': self.env['ir.attachment'].api_image('product.template', 'image_512', product_template.id), 'display_name': product_template.display_name, 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 acd592ab..82cb0432 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, limit=1000, expiry_days=30, ids=False): 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 @@ <field name="arch" type="xml"> <field name="company_id" position="after"> <field name="is_flash_sale"/> - <field name="flashsale_option" attrs="{'invisible':[('is_flash_sale', '=', False)]}"/> </field> - <group name="pricelist_settings" position="after"> - <group name="flash_sale_setting"> - <field name="banner" widget="image" attrs="{ - 'invisible': [('is_flash_sale', '=', False)] - }" /> - <field name="banner_mobile" widget="image" attrs="{ - 'invisible': [('is_flash_sale', '=', False)] - }" /> - <field name="banner_top" widget="image" attrs="{ - 'invisible': [('is_flash_sale', '=', False)] - }" /> - <field name="start_date" attrs="{ - 'invisible': [('is_flash_sale', '=', False)], - 'required': [('is_flash_sale', '=', True)] - }" /> - <field name="end_date" attrs="{ - 'invisible': [('is_flash_sale', '=', False)], - 'required': [('is_flash_sale', '=', True)] - }" /> - </group> - </group> + <page name="pricelist_rules" position="before"> + <page name="flash_sale_setting" string="Flash Sale" attrs="{'invisible': [('is_flash_sale', '=', False)]}"> + <group> + <group> + <field name="flashsale_option" /> + <field name="flashsale_tag" /> + <field name="banner" widget="image" /> + <field name="banner_mobile" widget="image" /> + <field name="banner_top" widget="image" /> + <field name="start_date" attrs="{'required': [('is_flash_sale', '=', True)]}" /> + <field name="end_date" attrs="{'required': [('is_flash_sale', '=', True)]}" /> + </group> + </group> + </page> + </page> </field> </record> </odoo>
\ No newline at end of file |
