From a5ae0bbfb7bbf07ec444b3eebf62d69df30a0e63 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 20 Sep 2023 14:17:00 +0700 Subject: add new code cart --- indoteknik_api/controllers/api_v1/cart.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'indoteknik_api') diff --git a/indoteknik_api/controllers/api_v1/cart.py b/indoteknik_api/controllers/api_v1/cart.py index 6faac27f..3b15e778 100644 --- a/indoteknik_api/controllers/api_v1/cart.py +++ b/indoteknik_api/controllers/api_v1/cart.py @@ -92,4 +92,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 -- cgit v1.2.3 From dd98194d70b878040169e87d3959e526f20213df Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 22 Sep 2023 14:27:49 +0700 Subject: add code for new pricelist and refactor code solr and pricelist --- indoteknik_api/models/product_product.py | 144 +++++++++++++++---------------- 1 file changed, 71 insertions(+), 73 deletions(-) (limited to 'indoteknik_api') diff --git a/indoteknik_api/models/product_product.py b/indoteknik_api/models/product_product.py index 057b449c..8517e28a 100644 --- a/indoteknik_api/models/product_product.py +++ b/indoteknik_api/models/product_product.py @@ -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,62 +183,44 @@ 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', '=', product_pricelist_tier), ('product_id', '=', self.id) ], limit=1) if pricelist_item: @@ -232,9 +231,8 @@ class ProductProduct(models.Model): 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 -- cgit v1.2.3 From e5f37e075273f6c463e70eb0d3743b95e05096cc Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 22 Sep 2023 16:42:49 +0700 Subject: fix error product product --- indoteknik_api/models/product_product.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'indoteknik_api') diff --git a/indoteknik_api/models/product_product.py b/indoteknik_api/models/product_product.py index 8517e28a..71022af5 100644 --- a/indoteknik_api/models/product_product.py +++ b/indoteknik_api/models/product_product.py @@ -235,6 +235,15 @@ class ProductProduct(models.Model): f'price_tier{tier_number}': price or 0 } return data + + def _get_pricelist_tier1(self): + return self._get_pricelist_tier(1) + + def _get_pricelist_tier2(self): + return self._get_pricelist_tier(2) + + def _get_pricelist_tier3(self): + return self._get_pricelist_tier(3) def _get_flashsale_price(self): result = {} -- cgit v1.2.3 From a74adc5dc9bfbbd87c308aa040b605e4160e0d17 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Sat, 23 Sep 2023 12:35:22 +0700 Subject: fix bug pricelist --- indoteknik_api/models/product_product.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'indoteknik_api') diff --git a/indoteknik_api/models/product_product.py b/indoteknik_api/models/product_product.py index 71022af5..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() @@ -220,12 +220,15 @@ class ProductProduct(models.Model): default_divide_tax = float(1.11) base_price = discount = price = 0 pricelist_item = self.env['product.pricelist.item'].search([ - ('pricelist_id', '=', product_pricelist_tier), + ('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 @@ -235,15 +238,6 @@ class ProductProduct(models.Model): f'price_tier{tier_number}': price or 0 } return data - - def _get_pricelist_tier1(self): - return self._get_pricelist_tier(1) - - def _get_pricelist_tier2(self): - return self._get_pricelist_tier(2) - - def _get_pricelist_tier3(self): - return self._get_pricelist_tier(3) def _get_flashsale_price(self): result = {} -- cgit v1.2.3