From 857fbbf8a46c9b933bd3fb13d274fbed2f3fea39 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 27 Aug 2024 10:08:47 +0700 Subject: add required to public_categ_ids product template & variant --- indoteknik_custom/models/product_template.py | 12 ++++++++++++ indoteknik_custom/views/product_template.xml | 3 +++ 2 files changed, 15 insertions(+) (limited to 'indoteknik_custom') diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index d51f903f..e6778758 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -61,6 +61,12 @@ class ProductTemplate(models.Model): tkdn = fields.Boolean(string='TKDN') short_spesification = fields.Char(string='Short Spesification') + @api.constrains('name', 'internal_reference', 'x_manufacture') + def required_public_categ_ids(self): + for rec in self: + if not rec.public_categ_ids: + raise UserError('Field Categories harus diisi') + def _get_qty_sold(self): for rec in self: rec.qty_sold = sum(x.qty_sold for x in rec.product_variant_ids) @@ -367,6 +373,12 @@ class ProductProduct(models.Model): qty_sold = fields.Float(string='Sold Quantity', compute='_get_qty_sold') short_spesification = fields.Char(string='Short Spesification') + @api.constrains('name', 'internal_reference', 'x_manufacture') + def required_public_categ_ids(self): + for rec in self: + if not rec.public_categ_ids: + raise UserError('Field Categories harus diisi') + @api.constrains('active') def archive_product(self): for product in self: diff --git a/indoteknik_custom/views/product_template.xml b/indoteknik_custom/views/product_template.xml index 520af5c8..e3a39412 100755 --- a/indoteknik_custom/views/product_template.xml +++ b/indoteknik_custom/views/product_template.xml @@ -21,6 +21,9 @@ + + 1 + -- cgit v1.2.3 From d776b60f89f827d2dc49df80d7852f98c820985f Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 27 Aug 2024 13:42:55 +0700 Subject: deactivate function check data vendor on po --- indoteknik_custom/models/purchase_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 3a11ab1e..8ec904a9 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -435,7 +435,7 @@ class PurchaseOrder(models.Model): res = super(PurchaseOrder, self).button_confirm() current_time = datetime.now() self.check_ppn_mix() - self.check_data_vendor() + # self.check_data_vendor() if self.total_percent_margin < self.total_so_percent_margin and not self.env.user.is_purchasing_manager and not self.env.user.is_leader: raise UserError("Beda Margin dengan Sales, harus approval Manager") -- cgit v1.2.3 From f4c67f4f8ef9ffc9da3e0406cb08fffb6ba44fd4 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 29 Aug 2024 10:26:52 +0700 Subject: add options no create on product template and variants --- indoteknik_custom/views/product_template.xml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom') diff --git a/indoteknik_custom/views/product_template.xml b/indoteknik_custom/views/product_template.xml index e3a39412..b6155eea 100755 --- a/indoteknik_custom/views/product_template.xml +++ b/indoteknik_custom/views/product_template.xml @@ -8,7 +8,7 @@ - + @@ -24,6 +24,9 @@ 1 + + {'no_create': True} + -- cgit v1.2.3 From 0e9e58da406e62a72ce2ba18c6317e3de57963a1 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 29 Aug 2024 13:09:54 +0700 Subject: cr api voucher --- indoteknik_custom/models/website_user_cart.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'indoteknik_custom') diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py index d9352abb..c233dfd7 100644 --- a/indoteknik_custom/models/website_user_cart.py +++ b/indoteknik_custom/models/website_user_cart.py @@ -91,7 +91,7 @@ class WebsiteUserCart(models.Model): products = carts.get_products() return products - def get_user_checkout(self, user_id, voucher=False, source=False): + def get_user_checkout(self, user_id, voucher=False, voucher_shipping=False, source=False): products = self.get_product_by_user(user_id=user_id, selected=True, source=source) total_purchase = 0 @@ -109,12 +109,12 @@ class WebsiteUserCart(models.Model): subtotal = total_purchase - total_discount discount_voucher = 0 - if voucher: - order_line = [] + discount_voucher_shipping = 0 + order_line = [] + + if voucher or voucher_shipping: for product in products: - if product['cart_type'] == 'promotion': - continue - + if product['cart_type'] == 'promotion': continue order_line.append({ 'product_id': self.env['product.product'].browse(product['id']), 'price': product['price']['price'], @@ -122,9 +122,16 @@ class WebsiteUserCart(models.Model): 'qty': product['quantity'], 'subtotal': product['subtotal'] }) + + if voucher: voucher_info = voucher.apply(order_line) discount_voucher = voucher_info['discount']['all'] subtotal -= discount_voucher + + if voucher_shipping: + voucher_shipping_info = voucher_shipping.apply(order_line) + discount_voucher_shipping = voucher_shipping_info['discount']['all'] + tax = round(subtotal * 0.11) grand_total = subtotal + tax total_weight = sum(x['weight'] * x['quantity'] for x in products) @@ -133,6 +140,7 @@ class WebsiteUserCart(models.Model): 'total_purchase': total_purchase, 'total_discount': total_discount, 'discount_voucher': discount_voucher, + 'discount_voucher_shipping': discount_voucher_shipping, 'subtotal': subtotal, 'tax': tax, 'grand_total': round(grand_total), -- cgit v1.2.3 From 18e3b9d7abe9210c74b321fda489a049795774a2 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 29 Aug 2024 13:30:18 +0700 Subject: add attrs to payment term po --- indoteknik_custom/views/purchase_order.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom') diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml index 25b7787b..b936086a 100755 --- a/indoteknik_custom/views/purchase_order.xml +++ b/indoteknik_custom/views/purchase_order.xml @@ -39,7 +39,7 @@ - + -- cgit v1.2.3 From 1b2d9c35be0e48e4aadc8d6e2578fd623ad7d03a Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 29 Aug 2024 14:29:26 +0700 Subject: fix bug voucher --- indoteknik_custom/models/voucher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom') diff --git a/indoteknik_custom/models/voucher.py b/indoteknik_custom/models/voucher.py index f7305999..37c97338 100644 --- a/indoteknik_custom/models/voucher.py +++ b/indoteknik_custom/models/voucher.py @@ -146,7 +146,7 @@ class Voucher(models.Model): def calc_discount_amount(self, total): result = { 'all': 0, 'brand': {} } - if self.apply_type == 'all': + if self.apply_type in ['all', 'shipping']: if total['all'] < self.min_purchase_amount: return result -- cgit v1.2.3 From 00b552bcdd7a689cf347aa2b882ec6796f42bc20 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 29 Aug 2024 14:38:17 +0700 Subject: fix voucher --- indoteknik_custom/models/website_user_cart.py | 1 + 1 file changed, 1 insertion(+) (limited to 'indoteknik_custom') diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py index c233dfd7..0af22d47 100644 --- a/indoteknik_custom/models/website_user_cart.py +++ b/indoteknik_custom/models/website_user_cart.py @@ -131,6 +131,7 @@ class WebsiteUserCart(models.Model): if voucher_shipping: voucher_shipping_info = voucher_shipping.apply(order_line) discount_voucher_shipping = voucher_shipping_info['discount']['all'] + subtotal -= discount_voucher_shipping tax = round(subtotal * 0.11) grand_total = subtotal + tax -- cgit v1.2.3 From 2719b8cdd45b356baa598255dcdbdd8e353478e7 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 30 Aug 2024 10:13:44 +0700 Subject: payment term po cr --- indoteknik_custom/models/automatic_purchase.py | 1 + indoteknik_custom/views/purchase_order.xml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom') diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py index 3561fc0f..1d1322fa 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -220,6 +220,7 @@ class AutomaticPurchase(models.Model): # i start from zero (0) for i in range(page): new_po = self.env['purchase.order'].create([param_header]) + new_po.payment_term_id = new_po.partner_id.property_supplier_payment_term_id new_po.name = new_po.name + name + str(i + 1) self.env['automatic.purchase.match'].create([{ diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml index b936086a..c301f3d3 100755 --- a/indoteknik_custom/views/purchase_order.xml +++ b/indoteknik_custom/views/purchase_order.xml @@ -39,7 +39,7 @@ - + -- cgit v1.2.3 From 1e44c76fa1b4f9aa63599a4efb0adb84b3adba75 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 2 Sep 2024 09:30:18 +0700 Subject: cr api get cart --- indoteknik_custom/models/website_user_cart.py | 1 + 1 file changed, 1 insertion(+) (limited to 'indoteknik_custom') diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py index 0af22d47..581ed4cd 100644 --- a/indoteknik_custom/models/website_user_cart.py +++ b/indoteknik_custom/models/website_user_cart.py @@ -32,6 +32,7 @@ class WebsiteUserCart(models.Model): if self.product_id: 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) -- cgit v1.2.3 From 6e049ba60b4ee6e20231787af3e7e3c0abcf188a Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 2 Sep 2024 13:26:11 +0700 Subject: add permission to button validate stock picking --- indoteknik_custom/models/stock_picking.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'indoteknik_custom') diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 6083e9e7..49f2ec80 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -354,6 +354,9 @@ class StockPicking(models.Model): def button_validate(self): + if not self.env.user.is_purchasing_manager: + raise UserError("Harus di Approve oleh Purchasing Manager") + if self._name != 'stock.picking': return super(StockPicking, self).button_validate() -- cgit v1.2.3 From b3cddd483107f9cf97c2651262d5770ba6a13d92 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 2 Sep 2024 13:37:38 +0700 Subject: fix bug --- indoteknik_custom/models/stock_picking.py | 3 --- 1 file changed, 3 deletions(-) (limited to 'indoteknik_custom') diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 49f2ec80..6083e9e7 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -354,9 +354,6 @@ class StockPicking(models.Model): def button_validate(self): - if not self.env.user.is_purchasing_manager: - raise UserError("Harus di Approve oleh Purchasing Manager") - if self._name != 'stock.picking': return super(StockPicking, self).button_validate() -- cgit v1.2.3 From 51e939b217a6ea0050cef2f5335b0dd310379b2d Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 2 Sep 2024 13:41:51 +0700 Subject: add permission to unreserve --- indoteknik_custom/models/stock_picking.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'indoteknik_custom') diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 6083e9e7..d16d508e 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -126,6 +126,8 @@ class StockPicking(models.Model): def do_unreserve(self): res = super(StockPicking, self).do_unreserve() + if not self.env.user.is_purchasing_manager: + raise UserError('Hanya Purchasing Manager yang bisa Unreserve') current_time = datetime.datetime.utcnow() self.date_unreserve = current_time return res -- cgit v1.2.3 From aa60fbca555f1ed654909ed11e87add53676f625 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 2 Sep 2024 13:52:59 +0700 Subject: add auto sync to solr when end date h+1 --- indoteknik_custom/models/product_pricelist.py | 14 +++++++++++++- indoteknik_custom/views/product_pricelist.xml | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom') diff --git a/indoteknik_custom/models/product_pricelist.py b/indoteknik_custom/models/product_pricelist.py index 2b17cf6e..c299ff2f 100644 --- a/indoteknik_custom/models/product_pricelist.py +++ b/indoteknik_custom/models/product_pricelist.py @@ -1,5 +1,5 @@ from odoo import models, fields -from datetime import datetime +from datetime import datetime, timedelta class ProductPricelist(models.Model): @@ -18,6 +18,18 @@ class ProductPricelist(models.Model): banner_top = fields.Binary(string='Banner Top') flashsale_tag = fields.Char(string='Flash Sale Tag') + def _check_end_date_and_update_solr(self): + today = datetime.utcnow().date() + one_day_ago = today - timedelta(days=1) + + pricelists = self.search([ + ('is_flash_sale', '=', True) + ]) + + for pricelist in pricelists: + if fields.Date.to_date(pricelist.end_date) == one_day_ago: + pricelist._constrains_related_solr_field() + def _remaining_time_in_second(self): if not self.end_date: return 0 diff --git a/indoteknik_custom/views/product_pricelist.xml b/indoteknik_custom/views/product_pricelist.xml index 0dfb69db..6eff0153 100644 --- a/indoteknik_custom/views/product_pricelist.xml +++ b/indoteknik_custom/views/product_pricelist.xml @@ -26,4 +26,18 @@ + + + + Pricelist: Check End Date and Update Solr + 1 + days + -1 + + + model._check_end_date_and_update_solr() + code + 55 + + \ No newline at end of file -- cgit v1.2.3 From 9808cae54a32a65a41d0a13a141e62d88abedfef Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 2 Sep 2024 16:14:26 +0700 Subject: cr api get user cart --- indoteknik_custom/models/website_user_cart.py | 110 +++++++++++++++++++------- 1 file changed, 81 insertions(+), 29 deletions(-) (limited to 'indoteknik_custom') diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py index 581ed4cd..0fd8df98 100644 --- a/indoteknik_custom/models/website_user_cart.py +++ b/indoteknik_custom/models/website_user_cart.py @@ -23,36 +23,46 @@ 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: - 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 + 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 - flashsales = self.product_id._get_active_flash_sale() - res['has_flashsale'] = True if len(flashsales) > 0 else False + 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 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, @@ -63,14 +73,56 @@ 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) -- cgit v1.2.3 From 643b93d9b57df8916714d898ba6457282d6756c2 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 3 Sep 2024 08:56:07 +0700 Subject: trying to add category parent to solr product template --- indoteknik_custom/models/solr/product_template.py | 31 +++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'indoteknik_custom') diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py index 6f76c529..2e34befe 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -101,6 +101,7 @@ class ProductTemplate(models.Model): "search_rank_i": template.search_rank, "search_rank_weekly_i": template.search_rank_weekly, "category_id_ids": category_ids, # ID kategori sebagai string yang dipisahkan koma + "category_parent_ids": self.get_category_hierarchy_ids(category_ids), # ID kategori sebagai string yang dipisahkan koma "category_name_s": ', '.join(category_names), # Nama kategori sebagai string yang dipisahkan koma "category_name": category_names, # Nama kategori sebagai list "description_t": template.website_description or '', @@ -127,6 +128,36 @@ class ProductTemplate(models.Model): if not document.get('has_price_info_b'): template._sync_price_to_solr() + def get_category_hierarchy_ids(category_id, env): + """ + Function to get category hierarchy IDs including the category itself and its parents. + + Args: + category_id (int): The ID of the category you want to retrieve. + env (Environment): The Odoo environment. + + Returns: + list: A list of IDs for the category and its parents. + """ + category_ids = [] + + def traverse_category(cat_id): + # Retrieve category object based on ID + category = env['product.category'].browse(cat_id) + + # Add the current category ID to the list + category_ids.append(category.id) + + # If there is a parent category, traverse upwards + if category.parent_id: + traverse_category(category.parent_id.id) + + # Start traversal from the initial category + traverse_category(category_id) + + # Reverse the list to get the hierarchy from top level to the current level + return list(reversed(category_ids)) + def _sync_price_to_solr(self): solr_model = self.env['apache.solr'] TIER_NUMBERS = ['1_v2', '2_v2', '3_v2', '4_v2', '5_v2'] -- cgit v1.2.3 From 8dab99ed68d5fdc3a47bcd2cd349cad1d93fd53d Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 3 Sep 2024 08:57:48 +0700 Subject: reverse code --- indoteknik_custom/models/website_user_cart.py | 109 +++++++------------------- 1 file changed, 28 insertions(+), 81 deletions(-) (limited to 'indoteknik_custom') 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) -- cgit v1.2.3 From c9621e309e9b9db20ac01359b9369fa2d2a32024 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 3 Sep 2024 09:03:29 +0700 Subject: cr solr --- indoteknik_custom/models/solr/product_template.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom') diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py index 2e34befe..9c5dc73e 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -128,7 +128,7 @@ class ProductTemplate(models.Model): if not document.get('has_price_info_b'): template._sync_price_to_solr() - def get_category_hierarchy_ids(category_id, env): + def get_category_hierarchy_ids(self, category_id): """ Function to get category hierarchy IDs including the category itself and its parents. @@ -143,7 +143,7 @@ class ProductTemplate(models.Model): def traverse_category(cat_id): # Retrieve category object based on ID - category = env['product.category'].browse(cat_id) + category = self.env['product.public.category'].browse(cat_id) # Add the current category ID to the list category_ids.append(category.id) -- cgit v1.2.3 From 3d70fa89180cd3318b0f952c0f628d3bb1313340 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 3 Sep 2024 09:24:33 +0700 Subject: add description_clean to solr --- indoteknik_custom/models/solr/product_template.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'indoteknik_custom') diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py index 9c5dc73e..b5fed4fa 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -1,4 +1,5 @@ from datetime import datetime +from bs4 import BeautifulSoup from odoo import api, fields, models @@ -78,6 +79,9 @@ class ProductTemplate(models.Model): is_in_bu = bool(stock_quant) + cleaned_desc = BeautifulSoup(template.website_description or '', "html.parser").get_text() + website_description = template.website_description if cleaned_desc else '' + document = solr_model.get_doc('product', template.id) document.update({ "id": template.id, @@ -105,6 +109,7 @@ class ProductTemplate(models.Model): "category_name_s": ', '.join(category_names), # Nama kategori sebagai string yang dipisahkan koma "category_name": category_names, # Nama kategori sebagai list "description_t": template.website_description or '', + "description_clean_t": website_description or '', 'has_product_info_b': True, 'publish_b': not template.unpublished, 'sni_b': template.unpublished, -- cgit v1.2.3 From 5372bb907b3ed65f5f4de1c8f9202eb1bcb1f93e Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 3 Sep 2024 09:33:24 +0700 Subject: add field promotion program line --- indoteknik_custom/models/solr/promotion_program_line.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom') diff --git a/indoteknik_custom/models/solr/promotion_program_line.py b/indoteknik_custom/models/solr/promotion_program_line.py index 4b0e67f6..c6dbf213 100644 --- a/indoteknik_custom/models/solr/promotion_program_line.py +++ b/indoteknik_custom/models/solr/promotion_program_line.py @@ -37,6 +37,9 @@ class PromotionProgramLine(models.Model): promotion_type = rec._res_promotion_type() + # Gathering all categories + category_names = [category.name for category in rec.product_ids.product_id.public_categ_ids] + # Set sequence_i to None if rec.sequence is 0 sequence_value = None if rec.sequence == 0 else rec.sequence @@ -57,7 +60,9 @@ class PromotionProgramLine(models.Model): 'free_products_s': json.dumps(free_products), 'total_qty_i': sum([x.qty for x in rec.product_ids] + [x.qty for x in rec.free_product_ids]), 'total_qty_sold_f': [x.product_id.qty_sold for x in rec.product_ids], - 'active_b': rec.active + 'active_b': rec.active, + "manufacture_name_s": rec.product_ids.product_id.x_manufacture.display_name, + "category_name": category_names, }) self.solr().add([document]) -- cgit v1.2.3 From c617ed4000d1683a5ca9bdcf88b8ec6da6d9f8f0 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 3 Sep 2024 09:35:11 +0700 Subject: fix bug description --- indoteknik_custom/models/solr/product_template.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom') diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py index b5fed4fa..d8dec47c 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -109,7 +109,7 @@ class ProductTemplate(models.Model): "category_name_s": ', '.join(category_names), # Nama kategori sebagai string yang dipisahkan koma "category_name": category_names, # Nama kategori sebagai list "description_t": template.website_description or '', - "description_clean_t": website_description or '', + "description_clean_t": cleaned_desc or '', 'has_product_info_b': True, 'publish_b': not template.unpublished, 'sni_b': template.unpublished, -- cgit v1.2.3 From 836936b33c8206cf5344df189642e7a65f095480 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 3 Sep 2024 10:16:32 +0700 Subject: add others info in dunning run --- indoteknik_custom/models/dunning_run.py | 4 ++++ indoteknik_custom/views/dunning_run.xml | 7 +++++++ 2 files changed, 11 insertions(+) (limited to 'indoteknik_custom') diff --git a/indoteknik_custom/models/dunning_run.py b/indoteknik_custom/models/dunning_run.py index d75d7c51..90159cd0 100644 --- a/indoteknik_custom/models/dunning_run.py +++ b/indoteknik_custom/models/dunning_run.py @@ -27,6 +27,10 @@ class DunningRun(models.Model): shipper_faktur_id = fields.Many2one('delivery.carrier', string='Shipper Faktur') is_validated = fields.Boolean(string='Validated') notification = fields.Char(string='Notification') + is_paid = fields.Boolean(string='Paid') + description = fields.Char(string='Description') + comment = fields.Char(string='Comment') + def copy_date_faktur(self): if not self.is_validated: diff --git a/indoteknik_custom/views/dunning_run.xml b/indoteknik_custom/views/dunning_run.xml index 567d5e8c..dd5bb120 100644 --- a/indoteknik_custom/views/dunning_run.xml +++ b/indoteknik_custom/views/dunning_run.xml @@ -77,6 +77,13 @@ + + + + + + +
-- cgit v1.2.3 From 51face2a473c347e338650d059445dc4f085d96e Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 3 Sep 2024 13:19:42 +0700 Subject: update field --- indoteknik_custom/models/solr/promotion_program_line.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom') diff --git a/indoteknik_custom/models/solr/promotion_program_line.py b/indoteknik_custom/models/solr/promotion_program_line.py index c6dbf213..3e3a2a28 100644 --- a/indoteknik_custom/models/solr/promotion_program_line.py +++ b/indoteknik_custom/models/solr/promotion_program_line.py @@ -61,7 +61,7 @@ class PromotionProgramLine(models.Model): 'total_qty_i': sum([x.qty for x in rec.product_ids] + [x.qty for x in rec.free_product_ids]), 'total_qty_sold_f': [x.product_id.qty_sold for x in rec.product_ids], 'active_b': rec.active, - "manufacture_name_s": rec.product_ids.product_id.x_manufacture.display_name, + "manufacture_name_s": rec.product_ids.product_id.x_manufacture.x_name or '', "category_name": category_names, }) -- cgit v1.2.3 From eced81efba75d710d164f1baa2d2e50b4d2d3c18 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 3 Sep 2024 14:14:40 +0700 Subject: fix bug --- indoteknik_custom/models/sale_order.py | 1 + 1 file changed, 1 insertion(+) (limited to 'indoteknik_custom') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 710e99de..348ea4d3 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -109,6 +109,7 @@ class SaleOrder(models.Model): date_driver_departure = fields.Datetime(string='Departure Date', compute='_compute_date_kirim', copy=False) note_website = fields.Char(string="Note Website") use_button = fields.Boolean(string='Using Calculate Selling Price', copy=False) + voucher_shipping_id = fields.Many2one(comodel_name='voucher', string='Voucher', copy=False) def _compute_date_kirim(self): for rec in self: -- cgit v1.2.3 From ca5c12f1ee40ea3c34cafcc9fe73d3d79a6a5b98 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 4 Sep 2024 15:53:40 +0700 Subject: fix margin with fee third party --- indoteknik_custom/models/sale_order.py | 2 +- indoteknik_custom/views/sale_order.xml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 348ea4d3..81c3f5ed 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -744,7 +744,7 @@ class SaleOrder(models.Model): delivery_amt = order.delivery_amt else: delivery_amt = 0 - order.total_percent_margin = round((order.total_margin / (order.amount_untaxed-delivery_amt)) * 100, 2) + order.total_percent_margin = round((order.total_margin / (order.amount_untaxed-delivery_amt-order.fee_third_party)) * 100, 2) # order.total_percent_margin = round((order.total_margin / (order.amount_untaxed)) * 100, 2) @api.onchange('sales_tax_id') diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index 1257ff85..a351607f 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -112,6 +112,7 @@ "/> + -- cgit v1.2.3 From 1bb074bb8f63072fb990c57c18986c50981f1402 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 4 Sep 2024 17:12:38 +0700 Subject: fix voucher shipping --- indoteknik_custom/models/sale_order.py | 54 ++++++++++++++++++++++++++- indoteknik_custom/models/website_user_cart.py | 3 +- indoteknik_custom/views/sale_order.xml | 16 ++++++++ 3 files changed, 70 insertions(+), 3 deletions(-) (limited to 'indoteknik_custom') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 348ea4d3..0268f27b 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -88,6 +88,8 @@ class SaleOrder(models.Model): voucher_id = fields.Many2one(comodel_name='voucher', string='Voucher', copy=False) applied_voucher_id = fields.Many2one(comodel_name='voucher', string='Applied Voucher', copy=False) amount_voucher_disc = fields.Float(string='Voucher Discount') + applied_voucher_shipping_id = fields.Many2one(comodel_name='voucher', string='Applied Voucher', copy=False) + amount_voucher_shipping_disc = fields.Float(string='Voucher Discount') source_id = fields.Many2one('utm.source', 'Source', domain="[('id', 'in', [32, 59, 60, 61])]", required=True) estimated_arrival_days = fields.Integer('Estimated Arrival Days', default=0) email = fields.Char(string='Email') @@ -109,7 +111,7 @@ class SaleOrder(models.Model): date_driver_departure = fields.Datetime(string='Departure Date', compute='_compute_date_kirim', copy=False) note_website = fields.Char(string="Note Website") use_button = fields.Boolean(string='Using Calculate Selling Price', copy=False) - voucher_shipping_id = fields.Many2one(comodel_name='voucher', string='Voucher', copy=False) + voucher_shipping_id = fields.Many2one(comodel_name='voucher', string='Voucher Shipping', copy=False) def _compute_date_kirim(self): for rec in self: @@ -781,6 +783,28 @@ class SaleOrder(models.Model): self.apply_voucher() + def action_apply_voucher_shipping(self): + for line in self.order_line: + if line.order_promotion_id: + raise UserError('Voucher tidak dapat digabung dengan promotion program') + + voucher = self.voucher_shipping_id + if voucher.limit > 0 and voucher.count_order >= voucher.limit: + raise UserError('Voucher tidak dapat digunakan karena sudah habis digunakan') + + partner_voucher_orders = [] + for order in voucher.order_ids: + if order.partner_id.id == self.partner_id.id: + partner_voucher_orders.append(order) + + if voucher.limit_user > 0 and len(partner_voucher_orders) >= voucher.limit_user: + raise UserError('Voucher tidak dapat digunakan karena Customer ini sudah menghabiskan kuota voucher') + + if self.pricelist_id.id in [x.id for x in voucher.excl_pricelist_ids]: + raise UserError('Voucher tidak dapat digunakan karena pricelist ini tidak berlaku pada voucher') + + self.apply_voucher_shipping() + def apply_voucher(self): order_line = [] for line in self.order_line: @@ -822,6 +846,29 @@ class SaleOrder(models.Model): self.amount_voucher_disc = voucher['discount']['all'] self.applied_voucher_id = self.voucher_id + def apply_voucher_shipping(self): + for order in self: + delivery_amt = order.delivery_amt + voucher = order.voucher_shipping_id + + if voucher: + max_discount_amount = voucher.discount_amount + voucher_type = voucher.discount_type + + if voucher_type == 'fixed_price': + discount = max_discount_amount + elif voucher_type == 'percentage': + discount = delivery_amt * (max_discount_amount / 100) + + delivery_amt -= discount + + delivery_amt = max(delivery_amt, 0) + + order.delivery_amt = delivery_amt + + order.amount_voucher_shipping_disc = discount + order.applied_voucher_shipping_id = order.voucher_id.id + def cancel_voucher(self): self.applied_voucher_id = False self.amount_voucher_disc = 0 @@ -830,6 +877,11 @@ class SaleOrder(models.Model): line.discount = line.initial_discount line.initial_discount = False + def cancel_voucher_shipping(self): + self.delivery_amt + self.amount_voucher_shipping_disc + self.applied_voucher_shipping_id = False + self.amount_voucher_shipping_disc = 0 + def action_web_approve(self): if self.env.uid != self.partner_id.user_id.id: raise UserError('You are not authorized to approve this order. Only %s can approve this order.' % self.partner_id.user_id.name) diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py index 0af22d47..b0cf47f7 100644 --- a/indoteknik_custom/models/website_user_cart.py +++ b/indoteknik_custom/models/website_user_cart.py @@ -130,8 +130,7 @@ class WebsiteUserCart(models.Model): if voucher_shipping: voucher_shipping_info = voucher_shipping.apply(order_line) - discount_voucher_shipping = voucher_shipping_info['discount']['all'] - subtotal -= discount_voucher_shipping + discount_voucher_shipping = voucher_shipping_info['discount']['all'] tax = round(subtotal * 0.11) grand_total = subtotal + tax diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index 1257ff85..44070f35 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -43,6 +43,17 @@ attrs="{'invisible': ['|', ('applied_voucher_id', '=', False), ('state', 'not in', ['draft','sent'])]}" />
+