diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2023-09-22 09:15:05 +0000 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2023-09-22 09:15:05 +0000 |
| commit | 379ceac5814a8005e8c4cde76494c640ddcbf3bb (patch) | |
| tree | 7f317713dba6a755ccbd80a3d087b7bb7612b98c | |
| parent | 553344781260c61062ceb5522b764b9811b30582 (diff) | |
| parent | dd98194d70b878040169e87d3959e526f20213df (diff) | |
Merged in new-pricelist (pull request #125)
add code for new pricelist and refactor code solr and pricelist
| -rw-r--r-- | indoteknik_api/models/product_product.py | 144 | ||||
| -rw-r--r-- | indoteknik_custom/models/solr/product_product.py | 35 | ||||
| -rw-r--r-- | indoteknik_custom/models/solr/product_template.py | 29 |
3 files changed, 111 insertions, 97 deletions
diff --git a/indoteknik_api/models/product_product.py b/indoteknik_api/models/product_product.py index 057b449c..8517e28a 100644 --- a/indoteknik_api/models/product_product.py +++ b/indoteknik_api/models/product_product.py @@ -122,33 +122,31 @@ class ProductProduct(models.Model): retValue = math.floor(retValue) return retValue - def _get_website_price_exclude_tax(self): - default_divide_tax = float(1.11) - price_incl = self._get_website_price_include_tax() - res = price_incl / default_divide_tax - return math.floor(res) - - def _get_website_disc(self, partner_id): - default_discount_id = int(4) + def _v2_get_website_price_include_tax(self): + default_pricelist_id = int(17022) - # compile partner - partner = self.env['res.partner'].search([('id', '=', partner_id)], limit=1) - - if partner: - if not partner.parent_id: # it means this is a parent - default_discount_id = partner.custom_pricelist_id - else: # it means this is NOT parent - default_discount_id = partner.parent_id.custom_pricelist_id query = [ - ('pricelist_id.id', '=', default_discount_id), + ('pricelist_id.id', '=', default_pricelist_id), ('product_id.id', '=', self.id) ] - - pl_item2 = self.env['product.pricelist.item'].search(query, limit=1) + pl_item1 = self.env['product.pricelist.item'].search(query, limit=1) - retValue = pl_item2.price_discount + retValue = pl_item1.fixed_price + retValue = math.floor(retValue) return retValue + def _get_website_price_exclude_tax(self): + default_divide_tax = float(1.11) + price_incl = self._get_website_price_include_tax() + res = price_incl / default_divide_tax + return math.floor(res) + + def _v2_get_website_price_exclude_tax(self): + default_divide_tax = float(1.11) + price_incl = self._v2_get_website_price_include_tax() + res = price_incl / default_divide_tax + return math.floor(res) + def _get_website_price_after_disc_and_tax(self): default_divide_tax = float(1.11) price_after_disc = self._get_website_price_after_disc() @@ -156,6 +154,25 @@ class ProductProduct(models.Model): res = math.ceil(res) return res + def _v2_get_website_price_after_disc_and_tax(self): + default_divide_tax = float(1.11) + price_after_disc = self._v2_get_website_price_after_disc() + res = price_after_disc / default_divide_tax + res = math.ceil(res) + return res + + def _get_website_tax(self): + default_percent_tax = float(11) + price_after_disc = self._get_website_price_after_disc_and_tax() + res = price_after_disc * default_percent_tax / 100 + return math.floor(res) + + def _v2_get_website_tax(self): + default_percent_tax = float(11) + price_after_disc = self._v2_get_website_price_after_disc_and_tax() + res = price_after_disc * default_percent_tax / 100 + return math.floor(res) + def _get_website_price_after_disc(self): discount = self._get_website_disc(0) price_incl = self._get_website_price_include_tax() @@ -166,62 +183,44 @@ class ProductProduct(models.Model): res = price_incl return math.floor(res) - def _get_website_tax(self): - default_percent_tax = float(11) - price_after_disc = self._get_website_price_after_disc_and_tax() - res = price_after_disc * default_percent_tax / 100 + def _v2_get_website_price_after_disc(self): + discount = self._get_website_disc(0) + price_incl = self._v2_get_website_price_include_tax() + res = 0 + if discount > 0: + res = price_incl - (price_incl * discount / 100) + else: + res = price_incl return math.floor(res) - def _get_pricelist_tier1(self): - product_pricelist_tier1 = int(self.env['ir.config_parameter'].get_param('product.pricelist.tier1')) - default_divide_tax = float(1.11) - base_price = discount = price = 0 - pricelist_item = self.env['product.pricelist.item'].search([ - ('pricelist_id', '=', product_pricelist_tier1), - ('product_id', '=', self.id) - ], limit=1) - if pricelist_item: - # base_price = self._get_website_price_exclude_tax() - base_price_incl = self._get_website_price_include_tax() - discount = pricelist_item.price_discount - price = base_price_incl - (base_price_incl * discount / 100) - price = price / default_divide_tax - price = math.floor(price) - data = { - # 'base_price_tier1': base_price or 0, - 'discount_tier1': discount or 0, - 'price_tier1': price or 0 - } - return data - - def _get_pricelist_tier2(self): - product_pricelist_tier2 = int(self.env['ir.config_parameter'].get_param('product.pricelist.tier2')) - default_divide_tax = float(1.11) - base_price = discount = price = 0 - pricelist_item = self.env['product.pricelist.item'].search([ - ('pricelist_id', '=', product_pricelist_tier2), - ('product_id', '=', self.id) - ], limit=1) - if pricelist_item: - # base_price = self._get_website_price_exclude_tax() - base_price_incl = self._get_website_price_include_tax() - discount = pricelist_item.price_discount - price = base_price_incl - (base_price_incl * discount / 100) - price = price / default_divide_tax - price = math.floor(price) - data = { - # 'base_price_tier2': base_price or 0, - 'discount_tier2': discount or 0, - 'price_tier2': price or 0 - } - return data + def _get_website_disc(self, partner_id): + default_discount_id = int(4) + + # compile partner + partner = self.env['res.partner'].search([('id', '=', partner_id)], limit=1) + + if partner: + if not partner.parent_id: # it means this is a parent + default_discount_id = partner.custom_pricelist_id + else: # it means this is NOT parent + default_discount_id = partner.parent_id.custom_pricelist_id + query = [ + ('pricelist_id.id', '=', default_discount_id), + ('product_id.id', '=', self.id) + ] + + pl_item2 = self.env['product.pricelist.item'].search(query, limit=1) + + retValue = pl_item2.price_discount + return retValue - def _get_pricelist_tier3(self): - product_pricelist_tier3 = int(self.env['ir.config_parameter'].get_param('product.pricelist.tier3')) + def _get_pricelist_tier(self, tier_number): + config_param_name = f'product.pricelist.tier{tier_number}' + product_pricelist_tier = int(self.env['ir.config_parameter'].get_param(config_param_name)) default_divide_tax = float(1.11) base_price = discount = price = 0 pricelist_item = self.env['product.pricelist.item'].search([ - ('pricelist_id', '=', product_pricelist_tier3), + ('pricelist_id', '=', product_pricelist_tier), ('product_id', '=', self.id) ], limit=1) if pricelist_item: @@ -232,9 +231,8 @@ class ProductProduct(models.Model): price = price / default_divide_tax price = math.floor(price) data = { - # 'base_price_tier3': base_price or 0, - 'discount_tier3': discount or 0, - 'price_tier3': price or 0 + f'discount_tier{tier_number}': discount or 0, + f'price_tier{tier_number}': price or 0 } return data diff --git a/indoteknik_custom/models/solr/product_product.py b/indoteknik_custom/models/solr/product_product.py index d6418ede..41af2d0e 100644 --- a/indoteknik_custom/models/solr/product_product.py +++ b/indoteknik_custom/models/solr/product_product.py @@ -77,18 +77,18 @@ class ProductProduct(models.Model): for variant in self: price_excl_after_disc = price_excl = discount = tax = 0 - flashsale_data = tier1 = tier2 = tier3 = {} + flashsale_data = {} if price_excl_after_disc == 0 or variant._get_website_price_after_disc_and_tax() < price_excl_after_disc: price_excl = variant._get_website_price_exclude_tax() price_excl_after_disc = variant._get_website_price_after_disc_and_tax() - discount = variant._get_website_disc(0) tax = variant._get_website_tax() + discount = variant._get_website_disc(0) flashsale_data = variant._get_flashsale_price() - # add price tiering for base price, discount, and price after discount (tier 1 - 3) - tier1 = variant._get_pricelist_tier1() - tier2 = variant._get_pricelist_tier2() - tier3 = variant._get_pricelist_tier3() + + price_excl_v2 = variant._v2_get_website_price_exclude_tax() + price_excl_after_disc_v2 = variant._v2_get_website_price_after_disc_and_tax() + tax_v2 = variant._v2_get_website_tax() document = solr_model.get_doc('variants', variant.id) document.update({ @@ -105,14 +105,23 @@ class ProductProduct(models.Model): "discount_f": discount, "price_discount_f": price_excl_after_disc, "tax_f": tax, - "discount_tier1_f": tier1.get('discount_tier1', 0), - "price_tier1_f": tier1.get('price_tier1', 0), - "discount_tier2_f": tier2.get('discount_tier2', 0), - "price_tier2_f": tier2.get('price_tier2', 0), - "discount_tier3_f": tier3.get('discount_tier3', 0), - "price_tier3_f": tier3.get('price_tier3', 0), - "has_price_info_b": True + "price_v2_f": price_excl_v2, + "price_discount_v2_f": price_excl_after_disc_v2, + "tax_v2_f": tax_v2, }) + + for tier_number in [1, 2, 3, '1_v2', '2_v2', '3_v2', '4_v2', '5_v2']: + tier = variant._get_pricelist_tier(tier_number) + document.update({ + f"discount_tier{tier_number}_f": tier.get(f'discount_tier{tier_number}', 0), + f"price_tier{tier_number}_f": tier.get(f'price_tier{tier_number}', 0), + }) + + # for tier_number in [1, 2, 3, '1_v2', '2_v2', '3_v2', '4_v2', '5_v2']: + # tier = tier_data[tier_number] + + document.update({"has_price_info_b": True}) + self.solr().add(docs=[document], softCommit=True) variant.change_solr_data('Ada perubahan pada harga product') diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py index 7d899873..b4782d1c 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -112,6 +112,8 @@ class ProductTemplate(models.Model): for template in self: flashsale_data = {} + price_excl = price_excl_after_disc = discount = tax = 0 + tier_data = {} for variant in template.product_variant_ids: variant_flashsale = variant._get_flashsale_price() @@ -125,9 +127,10 @@ class ProductTemplate(models.Model): price_excl_after_disc = variant._get_website_price_after_disc_and_tax() discount = variant._get_website_disc(0) tax = variant._get_website_tax() - tier1 = variant._get_pricelist_tier1() - tier2 = variant._get_pricelist_tier2() - tier3 = variant._get_pricelist_tier3() + + price_excl_v2 = variant._v2_get_website_price_exclude_tax() + price_excl_after_disc_v2 = variant._v2_get_website_price_after_disc_and_tax() + tax_v2 = variant._v2_get_website_tax() document = solr_model.get_doc('product', template.id) document.update({ @@ -144,22 +147,26 @@ class ProductTemplate(models.Model): "discount_f": discount, "price_discount_f": price_excl_after_disc, "tax_f": tax, - "discount_tier1_f": tier1.get('discount_tier1', 0), - "price_tier1_f": tier1.get('price_tier1', 0), - "discount_tier2_f": tier2.get('discount_tier2', 0), - "price_tier2_f": tier2.get('price_tier2', 0), - "discount_tier3_f": tier3.get('discount_tier3', 0), - "price_tier3_f": tier3.get('price_tier3', 0), - "has_price_info_b": True + "price_v2_f": price_excl_v2, + "price_discount_v2_f": price_excl_after_disc_v2, + "tax_v2_f": tax_v2, }) + for tier_number in [1, 2, 3, '1_v2', '2_v2', '3_v2', '4_v2', '5_v2']: + tier = variant._get_pricelist_tier(tier_number) + document.update({ + f"discount_tier{tier_number}_f": tier.get(f'discount_tier{tier_number}', 0), + f"price_tier{tier_number}_f": tier.get(f'price_tier{tier_number}', 0), + }) + + document.update({"has_price_info_b": True}) + self.solr().add(docs=[document], softCommit=True) template.product_variant_ids._sync_price_to_solr() template.change_solr_data('Ada perubahan pada harga product') if not document.get('has_product_info_b'): template._sync_product_template_to_solr() - def solr_results(self, detail=False): solr_model = self.env['apache.solr'] |
