summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-09-25 14:39:16 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-09-25 14:39:16 +0700
commit6c7c80b9cf3f4146af1fcfc4c9b24881a7b29b3c (patch)
tree5fd5b639f1dff754214dda0a609f2cbb41f8487a
parent30efa28bf211ffefc181551df026047143939b4f (diff)
add price_tier to program line
-rw-r--r--indoteknik_custom/models/promotion/promotion_program_line.py22
-rwxr-xr-xindoteknik_custom/models/purchase_pricelist.py8
-rw-r--r--indoteknik_custom/models/solr/product_template.py4
-rw-r--r--indoteknik_custom/models/solr/promotion_program_line.py5
-rw-r--r--indoteknik_custom/views/promotion/promotion_program_line.xml5
5 files changed, 42 insertions, 2 deletions
diff --git a/indoteknik_custom/models/promotion/promotion_program_line.py b/indoteknik_custom/models/promotion/promotion_program_line.py
index a57f1f2c..903e95cf 100644
--- a/indoteknik_custom/models/promotion/promotion_program_line.py
+++ b/indoteknik_custom/models/promotion/promotion_program_line.py
@@ -34,6 +34,28 @@ class PromotionProgramLine(models.Model):
active = fields.Boolean(string="Active", default=True)
solr_flag = fields.Integer(string="Solr Flag", default=1)
description = fields.Char('Description')
+ price_tier_1 = fields.Float('Price Tier 1')
+ price_tier_2 = fields.Float('Price Tier 2')
+ price_tier_3 = fields.Float('Price Tier 3')
+ price_tier_4 = fields.Float('Price Tier 4')
+ price_tier_5 = fields.Float('Price Tier 5')
+
+ def get_price_tier(self, product_id, qty):
+ product = self.env['product.product'].browse(product_id.id) # Get the product record
+
+ tiers = ['1_v2', '2_v2', '3_v2', '4_v2', '5_v2']
+
+ for index, tier in enumerate(tiers, start=1): # Automatically count from 1 to 5
+ # Call the function _get_pricelist_tier from product.product model
+ price_tier_data = product._get_pricelist_tier(tier)
+
+ # Use the index as the tier number (1, 2, 3, etc.)
+ price_field = f'price_tier_{index}' # 'price_tier_1', 'price_tier_2', etc.
+
+ # Update the corresponding price_tier_X field
+ if price_field in self._fields: # Ensure the field exists in the model
+ price = price_tier_data.get(f'price_tier{tier}', 0) * qty # Multiply by qty
+ self[price_field] = price
def get_active_promotions(self, product_id):
current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
diff --git a/indoteknik_custom/models/purchase_pricelist.py b/indoteknik_custom/models/purchase_pricelist.py
index 68fb796e..b5f719cb 100755
--- a/indoteknik_custom/models/purchase_pricelist.py
+++ b/indoteknik_custom/models/purchase_pricelist.py
@@ -23,6 +23,14 @@ class PurchasePricelist(models.Model):
brand_id = fields.Many2one('x_manufactures', string='Brand')
count_brand_vendor = fields.Integer(string='Count Brand Vendor')
is_winner = fields.Boolean(string='Winner', default=False, help='Pemenang yang direkomendasikan oleh Merchandise')
+
+ @api.constrains('include_price')
+ def sync_pricelist_tier(self):
+ for rec in self:
+ promotion_product = self.env['promotion.product'].search([('product_id', '=', rec.product_id.id)])
+
+ for promotion in promotion_product:
+ promotion.program_line_id.get_price_tier(promotion.product_id, promotion.qty)
@api.depends('product_id', 'vendor_id')
def _compute_name(self):
diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py
index d8dec47c..1eb6f31b 100644
--- a/indoteknik_custom/models/solr/product_template.py
+++ b/indoteknik_custom/models/solr/product_template.py
@@ -112,8 +112,8 @@ class ProductTemplate(models.Model):
"description_clean_t": cleaned_desc or '',
'has_product_info_b': True,
'publish_b': not template.unpublished,
- 'sni_b': template.unpublished,
- 'tkdn_b': template.unpublished,
+ 'sni_b': template.sni,
+ 'tkdn_b': template.tkdn,
"qty_sold_f": template.qty_sold,
"is_in_bu_b": is_in_bu,
"voucher_min_purchase_f" : voucher.min_purchase_amount or 0,
diff --git a/indoteknik_custom/models/solr/promotion_program_line.py b/indoteknik_custom/models/solr/promotion_program_line.py
index 3e3a2a28..64ad4209 100644
--- a/indoteknik_custom/models/solr/promotion_program_line.py
+++ b/indoteknik_custom/models/solr/promotion_program_line.py
@@ -53,6 +53,11 @@ class PromotionProgramLine(models.Model):
'package_limit_user_i': rec.package_limit_user,
'package_limit_trx_i': rec.package_limit_trx,
'price_f': rec.price,
+ 'price_tier_1_f': rec.price_tier_1,
+ 'price_tier_2_f': rec.price_tier_2,
+ 'price_tier_3_f': rec.price_tier_3,
+ 'price_tier_4_f': rec.price_tier_4,
+ 'price_tier_5_f': rec.price_tier_5,
'sequence_i': sequence_value,
'product_ids': [x.product_id.id for x in rec.product_ids],
'products_s': json.dumps(products),
diff --git a/indoteknik_custom/views/promotion/promotion_program_line.xml b/indoteknik_custom/views/promotion/promotion_program_line.xml
index f3c2eea1..b4dd2254 100644
--- a/indoteknik_custom/views/promotion/promotion_program_line.xml
+++ b/indoteknik_custom/views/promotion/promotion_program_line.xml
@@ -32,6 +32,11 @@
<field name="package_limit_user" />
<field name="package_limit_trx" />
<field name="price" attrs="{'invisible': [('promotion_type', '=', 'special_price')]}" />
+ <field name="price_tier_1" invisible="1"/>
+ <field name="price_tier_2" invisible="1"/>
+ <field name="price_tier_3" invisible="1"/>
+ <field name="price_tier_4" invisible="1"/>
+ <field name="price_tier_5" invisible="1"/>
<field name="sequence"/>
<field name="discount_type" attrs="{'invisible': [('promotion_type', '!=', 'special_price')]}" />
<field name="discount_amount" attrs="{'invisible': [('promotion_type', '!=', 'special_price')]}" />