summaryrefslogtreecommitdiff
path: root/indoteknik_api
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2023-09-29 02:32:56 +0000
committerIT Fixcomart <it@fixcomart.co.id>2023-09-29 02:32:56 +0000
commit78f205302c35cab2512971d64c8152aab2dcfa95 (patch)
tree72be75ad949fe9efaf7b55c8f7f5722225538b28 /indoteknik_api
parent50b5bd7bd984ef108e8bd324440050a222d8262f (diff)
parent0bb47005022b33c79ecfb5924d41f35ce794c5fb (diff)
Merged in production (pull request #126)
Production
Diffstat (limited to 'indoteknik_api')
-rw-r--r--indoteknik_api/controllers/api_v1/cart.py13
-rw-r--r--indoteknik_api/models/product_product.py153
2 files changed, 90 insertions, 76 deletions
diff --git a/indoteknik_api/controllers/api_v1/cart.py b/indoteknik_api/controllers/api_v1/cart.py
index 2243ec0f..cb0f5a99 100644
--- a/indoteknik_api/controllers/api_v1/cart.py
+++ b/indoteknik_api/controllers/api_v1/cart.py
@@ -101,4 +101,17 @@ class Cart(controller.Controller):
query += [('product_id', 'in', [int(x) for x in product_ids.split(',')])]
cart = request.env['website.user.cart'].search(query).unlink()
return self.response(cart)
+
+ @http.route(PREFIX_USER + 'cart/select-all', auth='public', methods=['POST', 'OPTIONS'], csrf=False)
+ @controller.Controller.must_authorized(private=True, private_key='user_id')
+ def select_all_cart_by_user_id(self, user_id):
+ user_id = int(user_id)
+
+ website_user_cart = request.env['website.user.cart']
+ query = [('user_id', '=', user_id)]
+ website_user_cart.search(query).write({
+ 'is_selected': True
+ })
+
+ return self.response(True)
\ No newline at end of file
diff --git a/indoteknik_api/models/product_product.py b/indoteknik_api/models/product_product.py
index 057b449c..78e32762 100644
--- a/indoteknik_api/models/product_product.py
+++ b/indoteknik_api/models/product_product.py
@@ -64,9 +64,9 @@ class ProductProduct(models.Model):
price_discount = self._get_website_price_after_disc_and_tax()
pricelists = {
- 'tier1': self._get_pricelist_tier1,
- 'tier2': self._get_pricelist_tier2,
- 'tier3': self._get_pricelist_tier3,
+ 'tier1': self._get_pricelist_tier(1),
+ 'tier2': self._get_pricelist_tier(2),
+ 'tier3': self._get_pricelist_tier(3),
}
price_tier = pricelist.get_tier_name()
@@ -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,75 +183,59 @@ 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', '=', int(product_pricelist_tier)),
('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()
+ if tier_number in ['1_v2', '2_v2', '3_v2', '4_v2', '5_v2']:
+ base_price_incl = self._v2_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
+ f'discount_tier{tier_number}': discount or 0,
+ f'price_tier{tier_number}': price or 0
}
return data