summaryrefslogtreecommitdiff
path: root/indoteknik_api/models/product_product.py
diff options
context:
space:
mode:
Diffstat (limited to 'indoteknik_api/models/product_product.py')
-rw-r--r--indoteknik_api/models/product_product.py95
1 files changed, 95 insertions, 0 deletions
diff --git a/indoteknik_api/models/product_product.py b/indoteknik_api/models/product_product.py
index c867eaa0..32bd7c21 100644
--- a/indoteknik_api/models/product_product.py
+++ b/indoteknik_api/models/product_product.py
@@ -62,6 +62,14 @@ class ProductProduct(models.Model):
}
return {}
+ def _is_have_flashsale(self):
+ active_flashsale = self.env['product.pricelist'].get_active_flash_sale()
+ for pricelist in active_flashsale:
+ found_product = self.env['product.pricelist.item'].search([('pricelist_id', '=', pricelist.id), ('product_id', '=', self.id)])
+ if found_product:
+ return True
+ return False
+
def _get_website_price_include_tax(self):
default_pricelist_id = int(1)
@@ -124,3 +132,90 @@ class ProductProduct(models.Model):
price_after_disc = self._get_website_price_after_disc_and_tax()
res = price_after_disc * default_percent_tax / 100
return math.floor(res)
+
+ def _get_pricelist_tier1(self):
+ default_divide_tax = float(1.11)
+ base_price = discount = price = 0
+ pricelist_item = self.env['product.pricelist.item'].search([('pricelist_id', '=', 15037), ('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):
+ default_divide_tax = float(1.11)
+ base_price = discount = price = 0
+ pricelist_item = self.env['product.pricelist.item'].search([('pricelist_id', '=', 15038), ('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_pricelist_tier3(self):
+ default_divide_tax = float(1.11)
+ base_price = discount = price = 0
+ pricelist_item = self.env['product.pricelist.item'].search([('pricelist_id', '=', 15039), ('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_tier3': base_price or 0,
+ 'discount_tier3': discount or 0,
+ 'price_tier3': price or 0
+ }
+ return data
+
+ def _get_flashsale_price(self):
+ # must get active pricelist
+ active_flash_sale = self.env['product.pricelist'].get_active_flash_sale()
+ flashsale_id = 0
+ flashsale_name = ''
+ # loop pricelist items
+ base_price = discount = price_flashsale = 0
+ for pricelist in active_flash_sale:
+ query = [
+ ('pricelist_id', '=', pricelist.id),
+ ('product_id', '=', self.id),
+ ]
+ pricelist_items = self.env['product.pricelist.item'].search(query, limit=1)
+ for item in pricelist_items:
+ flashsale_id = pricelist.id
+ flashsale_name = pricelist.name
+ base_price = self._get_website_price_exclude_tax()
+ if item.price_discount > 0:
+ discount = item.price_discount
+ # base_item = self.env['product.pricelist.item'].search([('pricelist_id', '=', item.base_pricelist_id.id), ('product_id', '=', self.id)], limit=1)
+ price_flashsale = base_price - (base_price * discount // 100)
+ elif item.fixed_price > 0:
+ price_flashsale = item.fixed_price # ask darren for include or exclude
+ discount = (base_price - price_flashsale) // base_price * 100
+ data = {
+ 'flashsale_id': flashsale_id,
+ 'flashsale_name': flashsale_name,
+ 'flashsale_base_price': base_price,
+ 'flashsale_discount': discount,
+ 'flashsale_price': price_flashsale
+ }
+ return data