From 89f27a69415d8ffbadbfbab0e23af9cada86d163 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 13 Aug 2024 17:05:22 +0700 Subject: add api pickup-service --- indoteknik_custom/models/website_user_cart.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py index dd3f87e6..10821cd3 100644 --- a/indoteknik_custom/models/website_user_cart.py +++ b/indoteknik_custom/models/website_user_cart.py @@ -24,16 +24,31 @@ class WebsiteUserCart(models.Model): def get_product(self): res = { - 'cart_id': self.id, - 'quantity': self.qty, + 'cart_id': self.id, + 'quantity': self.qty, 'selected': self.is_selected, 'can_buy': True } - + if self.product_id: 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) + ]) + + 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: @@ -48,9 +63,9 @@ class WebsiteUserCart(models.Model): res['can_buy'] = False res['subtotal'] = self.qty * res['price']['price_discount'] - + return res - + def get_products(self): products = [x.get_product() for x in self] -- cgit v1.2.3