summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-09-03 08:57:48 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-09-03 08:57:48 +0700
commit8dab99ed68d5fdc3a47bcd2cd349cad1d93fd53d (patch)
tree9d5298acf4918f80ea6c8836c19c4b26c60e1374
parent643b93d9b57df8916714d898ba6457282d6756c2 (diff)
reverse code
-rw-r--r--indoteknik_api/controllers/api_v1/cart.py3
-rw-r--r--indoteknik_custom/models/website_user_cart.py109
2 files changed, 29 insertions, 83 deletions
diff --git a/indoteknik_api/controllers/api_v1/cart.py b/indoteknik_api/controllers/api_v1/cart.py
index aa47b247..f472a9b0 100644
--- a/indoteknik_api/controllers/api_v1/cart.py
+++ b/indoteknik_api/controllers/api_v1/cart.py
@@ -19,8 +19,7 @@ class Cart(controller.Controller):
carts.write({'source': 'add_to_cart'})
data = {
'product_total': user_cart.search_count(query),
- 'products': carts.with_context(price_for="web").get_products(),
- 'product_inactive': carts.with_context(price_for="web").get_products_inactive()
+ 'products': carts.with_context(price_for="web").get_products()
}
return self.response(data)
diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py
index 0fd8df98..0af22d47 100644
--- a/indoteknik_custom/models/website_user_cart.py
+++ b/indoteknik_custom/models/website_user_cart.py
@@ -23,46 +23,35 @@ class WebsiteUserCart(models.Model):
record.user_other_carts = others
def get_product(self):
+ res = {
+ 'cart_id': self.id,
+ 'quantity': self.qty,
+ 'selected': self.is_selected,
+ 'can_buy': True
+ }
+
if self.product_id:
- base_price = self.product_id._v2_get_website_price_include_tax()
- active = self.product_id.active
- if base_price > 0 and active:
- res = {
- 'cart_id': self.id,
- 'quantity': self.qty,
- 'selected': self.is_selected,
- 'can_buy': True
- }
- res['cart_type'] = 'product'
- res['active'] = True if self.product_id.active else False
- product = self.product_id.v2_api_single_response(self.product_id)
- res.update(product)
-
- # Check if the product's inventory location is in ID 57 or 83
- target_locations = [57, 83]
- stock_quant = self.env['stock.quant'].search([
- ('product_id', '=', self.product_id.id),
- ('location_id', 'in', target_locations)
- ])
-
- if stock_quant:
- res['is_in_bu'] = True
- res['on_hand_qty'] = sum(stock_quant.mapped('quantity'))
- else:
- res['is_in_bu'] = False
- res['on_hand_qty'] = 0
+ res['cart_type'] = 'product'
+ product = self.product_id.v2_api_single_response(self.product_id)
+ res.update(product)
+
+ # Check if the product's inventory location is in ID 57 or 83
+ target_locations = [57, 83]
+ stock_quant = self.env['stock.quant'].search([
+ ('product_id', '=', self.product_id.id),
+ ('location_id', 'in', target_locations)
+ ])
- flashsales = self.product_id._get_active_flash_sale()
- res['has_flashsale'] = True if len(flashsales) > 0 else False
- res['subtotal'] = self.qty * res['price']['price_discount']
- return res
+ if stock_quant:
+ res['is_in_bu'] = True
+ res['on_hand_qty'] = sum(stock_quant.mapped('quantity'))
+ else:
+ res['is_in_bu'] = False
+ res['on_hand_qty'] = 0
+
+ flashsales = self.product_id._get_active_flash_sale()
+ res['has_flashsale'] = True if len(flashsales) > 0 else False
elif self.program_line_id:
- res = {
- 'cart_id': self.id,
- 'quantity': self.qty,
- 'selected': self.is_selected,
- 'can_buy': True
- }
res['cart_type'] = 'promotion'
userdata = {
'partner_id': self.user_id.partner_id.id,
@@ -73,56 +62,14 @@ class WebsiteUserCart(models.Model):
if program['remaining_qty']['transaction'] < self.qty:
res['can_buy'] = False
- res['subtotal'] = self.qty * res['price']['price_discount']
+ res['subtotal'] = self.qty * res['price']['price_discount']
- return res
+ return res
def get_products(self):
products = [x.get_product() for x in self]
return products
-
- def get_product_inactive(self):
- if self.product_id:
- base_price = self.product_id._v2_get_website_price_include_tax()
- active = self.product_id.active
- if base_price == 0 or not active:
- res = {
- 'cart_id': self.id,
- 'quantity': self.qty,
- 'selected': self.is_selected,
- 'can_buy': True
- }
- res['cart_type'] = 'product'
- res['active'] = True if self.product_id.active else False
- product = self.product_id.v2_api_single_response(self.product_id)
- res.update(product)
-
- # Check if the product's inventory location is in ID 57 or 83
- target_locations = [57, 83]
- stock_quant = self.env['stock.quant'].search([
- ('product_id', '=', self.product_id.id),
- ('location_id', 'in', target_locations)
- ])
-
- if stock_quant:
- res['is_in_bu'] = True
- res['on_hand_qty'] = sum(stock_quant.mapped('quantity'))
- else:
- res['is_in_bu'] = False
- res['on_hand_qty'] = 0
-
- flashsales = self.product_id._get_active_flash_sale()
- res['has_flashsale'] = True if len(flashsales) > 0 else False
-
- res['subtotal'] = self.qty * res['price']['price_discount']
-
- return res
-
- def get_products_inactive(self):
- products = [x.get_product_inactive() for x in self]
-
- return products
def get_product_by_user(self, user_id, selected=False, source=False):
user_id = int(user_id)