From 1988d339be9c737ec814bf84f59f4ae03ad7c32a Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Wed, 26 Jul 2023 13:59:24 +0700 Subject: Update stock on variant api response --- indoteknik_api/models/product_product.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'indoteknik_api/models') diff --git a/indoteknik_api/models/product_product.py b/indoteknik_api/models/product_product.py index 334b58c5..559f8694 100644 --- a/indoteknik_api/models/product_product.py +++ b/indoteknik_api/models/product_product.py @@ -31,6 +31,8 @@ class ProductProduct(models.Model): def v2_api_single_response(self, product_product): product_template = product_product.product_tmpl_id + stock = product_product.qty_stock_vendor + stock = 1 if stock == 0 else stock data = { 'id': product_product.id, 'parent': { @@ -41,7 +43,7 @@ class ProductProduct(models.Model): 'code': product_product.default_code or '', 'name': product_product.display_name, 'price': product_product.calculate_website_price(), - 'stock': product_product.qty_stock_vendor, + 'stock': stock, 'weight': product_product.weight, 'attributes': [x.name for x in product_product.product_template_attribute_value_ids], 'manufacture' : self.api_manufacture(product_product) -- cgit v1.2.3 From c0d30564d32210b9edb4c523ca8632e86de0f0a2 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Wed, 26 Jul 2023 16:41:49 +0700 Subject: Update calculate_website_price with flashsale price on get variant API --- indoteknik_api/models/product_product.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'indoteknik_api/models') diff --git a/indoteknik_api/models/product_product.py b/indoteknik_api/models/product_product.py index 559f8694..fb485bae 100644 --- a/indoteknik_api/models/product_product.py +++ b/indoteknik_api/models/product_product.py @@ -84,6 +84,13 @@ class ProductProduct(models.Model): if price[discount_key] > 0: discount_percentage = price[discount_key] if price[price_key] > 0: price_discount = price[price_key] + flashsale = self._get_flashsale_price() + flashsale_price = flashsale['flashsale_price'] + flashsale_discount = flashsale['flashsale_discount'] + if flashsale_price > 0 and flashsale_price < price_discount: + price_discount = flashsale_price + discount_percentage = flashsale_discount + return { 'price': self._get_website_price_exclude_tax(), 'discount_percentage': discount_percentage, -- cgit v1.2.3