summaryrefslogtreecommitdiff
path: root/indoteknik_api/models
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2023-09-22 09:15:05 +0000
committerIT Fixcomart <it@fixcomart.co.id>2023-09-22 09:15:05 +0000
commit379ceac5814a8005e8c4cde76494c640ddcbf3bb (patch)
tree7f317713dba6a755ccbd80a3d087b7bb7612b98c /indoteknik_api/models
parent553344781260c61062ceb5522b764b9811b30582 (diff)
parentdd98194d70b878040169e87d3959e526f20213df (diff)
Merged in new-pricelist (pull request #125)
add code for new pricelist and refactor code solr and pricelist
Diffstat (limited to 'indoteknik_api/models')
-rw-r--r--indoteknik_api/models/product_product.py144
1 files changed, 71 insertions, 73 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