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 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'indoteknik_custom/models') 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: -- 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/models') 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 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/models') 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 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/models') 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/models') 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 + 1 file changed, 1 insertion(+) (limited to 'indoteknik_custom/models') 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([{ -- 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/models') 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/models') 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/models') 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/models') 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 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models') 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 -- 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/models') 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/models') 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/models') 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/models') 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/models') 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/models') 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/models') 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 ++++ 1 file changed, 4 insertions(+) (limited to 'indoteknik_custom/models') 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: -- 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/models') 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/models') 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models') 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') -- 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 +- 2 files changed, 54 insertions(+), 3 deletions(-) (limited to 'indoteknik_custom/models') 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 -- cgit v1.2.3 From 013a3e4d73327c138ede6f224b32969dc8f85c1f Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 4 Sep 2024 17:18:02 +0700 Subject: solr category management --- indoteknik_custom/models/solr/__init__.py | 3 +- .../models/solr/website_categories_management.py | 108 +++++++++++++++++++++ 2 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 indoteknik_custom/models/solr/website_categories_management.py (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/solr/__init__.py b/indoteknik_custom/models/solr/__init__.py index 606c0035..dafd5a1e 100644 --- a/indoteknik_custom/models/solr/__init__.py +++ b/indoteknik_custom/models/solr/__init__.py @@ -10,4 +10,5 @@ from . import x_banner_banner from . import product_public_category from . import x_banner_category from . import promotion_program -from . import promotion_program_line \ No newline at end of file +from . import promotion_program_line +from . import website_categories_management \ No newline at end of file diff --git a/indoteknik_custom/models/solr/website_categories_management.py b/indoteknik_custom/models/solr/website_categories_management.py new file mode 100644 index 00000000..c3851f4b --- /dev/null +++ b/indoteknik_custom/models/solr/website_categories_management.py @@ -0,0 +1,108 @@ +from odoo import models, fields, api +from datetime import datetime +import json + + +class WebsiteCategoriesHomepage(models.Model): + _inherit = 'website.categories.management' + + last_update_solr = fields.Datetime('Last Update Solr') + + def solr(self): + return self.env['apache.solr'].connect('category_management') + + def update_last_update_solr(self): + self.last_update_solr = datetime.utcnow() + + def _create_solr_queue(self, function_name): + for rec in self: + self.env['apache.solr.queue'].create_unique({ + 'res_model': self._name, + 'res_id': rec.id, + 'function_name': function_name + }) + + @api.constrains('status') + def _create_solr_queue_sync_status(self): + self._create_solr_queue('_sync_status_category_homepage_solr') + + @api.constrains('category_id', 'category_id2', 'sequence') + def _create_solr_queue_sync_category_homepage(self): + self._create_solr_queue('_sync_category_management_to_solr') + + def action_sync_to_solr(self): + category_ids = self.env.context.get('active_ids', []) + categories = self.search([('id', 'in', category_ids)]) + categories._create_solr_queue('_sync_category_management_to_solr') + + def unlink(self): + res = super(WebsiteCategoriesHomepage, self).unlink() + for rec in self: + self.solr().delete(rec.id) + self.solr().optimize() + self.solr().commit() + return res + + def _sync_status_category_homepage_solr(self): + for rec in self: + if rec.status == 'tayang': + rec._sync_category_management_to_solr() + else: + rec.unlink() + + def _sync_category_management_to_solr(self): + solr_model = self.env['apache.solr'] + + for category in self: + if category.status != 'tayang': + continue + + # Level 1 Document + document = solr_model.get_doc('category_management', category.id) + document.update({ + 'id': category.id, + 'category_id_i': category.category_id.id, + 'name_s': category.category_id.name, + 'image_s': self.env['ir.attachment'].api_image('product.public.category', 'image_1920', category.category_id.id), + 'sequence_i': category.sequence or '', + 'numFound_i': len(category.category_id.product_tmpl_ids.ids), + }) + + # Level 2 and Level 3 Documents + level_2_docs = [] + for x in category.category_id2: + level_2_doc = { + 'id_level_2': x.id, + 'name_level_2': x.name, + 'numFound_level_2': len(x.product_tmpl_ids.ids), + 'image_level_2': self.env['ir.attachment'].api_image('product.public.category', 'image_1920', x.id), + 'categories_level_3': [] + } + + # Level 3 Data + for child in x.child_frontend_id2: + level_3_doc = { + 'id_level_3': child.id, + 'name_level_3': child.name, + 'numFound_level_3': len(child.product_tmpl_ids.ids), + 'image_level_3': self.env['ir.attachment'].api_image('product.public.category', 'image_1920', child.id), + } + level_2_doc['categories_level_3'].append(level_3_doc) + + level_2_docs.append(level_2_doc) + + # Add level 2 documents to level 1 document + document['categories_level_2'] = level_2_docs + + # Add document to Solr + self.solr().add([document]) + category.update_last_update_solr() + + self.solr().commit() + + + # def _sync_delete_solr(self): + # for rec in self: + # self.solr().delete(rec.id) + # self.solr().optimize() + # self.solr().commit() \ No newline at end of file -- cgit v1.2.3 From 4252e1b1b58499443a29c4a9fcf7d8ea8c2d2d31 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Thu, 5 Sep 2024 16:43:11 +0700 Subject: update category management slinder --- indoteknik_custom/models/__init__.py | 1 + .../models/website_categories_management.py | 36 +++++++++++++--------- .../models/website_categories_management_line.py | 22 +++++++++++++ 3 files changed, 44 insertions(+), 15 deletions(-) create mode 100644 indoteknik_custom/models/website_categories_management_line.py (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index e9ce587c..ad7b1d09 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -39,6 +39,7 @@ from . import website_brand_homepage from . import website_categories_homepage from . import website_categories_lob from . import website_categories_management +from . import website_categories_management_line from . import website_content from . import website_page_content from . import website_user_cart diff --git a/indoteknik_custom/models/website_categories_management.py b/indoteknik_custom/models/website_categories_management.py index 208b07a2..e430ef5f 100644 --- a/indoteknik_custom/models/website_categories_management.py +++ b/indoteknik_custom/models/website_categories_management.py @@ -6,8 +6,8 @@ class WebsiteCategoriesManagement(models.Model): _rec_name = 'category_id' category_id = fields.Many2one('product.public.category', string='Category Level 1', help='table ecommerce category', domain=lambda self: self._get_default_category_domain()) - category_id2 = fields.Many2many(comodel_name='product.public.category', relation='website_categories_category_id2_rel',column1='website_categories_homepage_id', column2='product_public_category_id', string='Category Level 2', copy=False) sequence = fields.Integer(string='Sequence') + line_ids = fields.One2many('website.categories.management.line', 'management_id', string='Category Level 2 Lines', auto_join=True) status = fields.Selection([ ('tayang', 'Tayang'), ('tidak_tayang', 'Tidak Tayang') @@ -17,11 +17,11 @@ class WebsiteCategoriesManagement(models.Model): def _onchange_category_id(self): domain = {} if self.category_id != self._origin.category_id: # Check if the category_id has changed - self.category_id2 = [(5, 0, 0)] # Clear the category_id2 field if category_id has changed + self.line_ids = [(5, 0, 0)] # Clear the lines if category_id has changed if self.category_id: - domain['category_id2'] = [('parent_frontend_id', '=', self.category_id.id)] + domain['line_ids'] = [('parent_frontend_id', '=', self.category_id.id)] else: - domain['category_id2'] = [] + domain['line_ids'] = [] return {'domain': domain} @@ -42,24 +42,30 @@ class WebsiteCategoriesManagement(models.Model): def _check_category_consistency(self): for record in self: - category_ids = record.category_id2.ids - for category in record.category_id2: - for child_category in category.child_frontend_id2: - if child_category.parent_frontend_id.id not in category_ids: + category_level2_ids = record.line_ids.mapped('category_id2.id') # Get all Category Level 2 IDs + for line in record.line_ids: + for category_level3 in line.category_id3_ids: # Loop through selected Category Level 3 + if category_level3.parent_frontend_id.id not in category_level2_ids: raise ValidationError( - f"Category Level 3 {child_category.name} bukan bagian dari category Level 2 {category.name}") + f"Category Level 3 '{category_level3.name}' bukan bagian dari Category Level 2 '{line.category_id2.name}'") def unlink(self): - for record in self.category_id2: - if record.id: + for record in self.line_ids: + if record.category_id2: related_categories = self.env['product.public.category'].search([ - ('id', 'in', record.ids) + ('id', '=', record.category_id2.id) ]) for category in related_categories: - for category3 in record.child_frontend_id2.ids: - if category3 in category.child_frontend_id2.ids: + # Iterate through the Category Level 3 related to the current Category Level 2 + for category3 in record.category_id3_ids: + # If Category Level 3 is linked to Category Level 2, remove the link + if category3.id in category.child_frontend_id2.ids: category.write({ - 'child_frontend_id2': [(3, category3)] + 'child_frontend_id2': [(3, category3.id)] + # Remove the link between Category Level 2 and Category Level 3 }) + return super(WebsiteCategoriesManagement, self).unlink() + + diff --git a/indoteknik_custom/models/website_categories_management_line.py b/indoteknik_custom/models/website_categories_management_line.py new file mode 100644 index 00000000..2f97ddfa --- /dev/null +++ b/indoteknik_custom/models/website_categories_management_line.py @@ -0,0 +1,22 @@ +from odoo import fields, models, api +from odoo.exceptions import ValidationError + +class WebsiteCategoriesManagementLine(models.Model): + _name = 'website.categories.management.line' + _order = 'sequence' + + sequence = fields.Integer(string='Sequence') + management_id = fields.Many2one('website.categories.management', string='Management Reference', required=True, ondelete='cascade') + category_id2 = fields.Many2one('product.public.category', string='Category Level 2', required=True,) + category_id3_ids = fields.Many2many('product.public.category', string='Category Level 3') + + @api.onchange('category_id2') + def _onchange_category_id2(self): + """ Update domain for category_id3_ids based on category_id2 """ + if self.category_id2: + domain_category_id3_ids = [('parent_frontend_id', '=', self.category_id2.id)] + else: + domain_category_id3_ids = [] + + return {'domain': {'category_id3_ids': domain_category_id3_ids}} + -- cgit v1.2.3 From 1b55d65464b9789164ba45bdef03c56428e026f2 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Thu, 5 Sep 2024 17:49:30 +0700 Subject: update category management --- .../models/solr/website_categories_management.py | 54 +++++++++++----------- 1 file changed, 28 insertions(+), 26 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/solr/website_categories_management.py b/indoteknik_custom/models/solr/website_categories_management.py index c3851f4b..fe85f8e7 100644 --- a/indoteknik_custom/models/solr/website_categories_management.py +++ b/indoteknik_custom/models/solr/website_categories_management.py @@ -2,19 +2,21 @@ from odoo import models, fields, api from datetime import datetime import json - class WebsiteCategoriesHomepage(models.Model): _inherit = 'website.categories.management' last_update_solr = fields.Datetime('Last Update Solr') def solr(self): + """Returns the Solr connection object.""" return self.env['apache.solr'].connect('category_management') def update_last_update_solr(self): + """Updates the last sync time for the record.""" self.last_update_solr = datetime.utcnow() def _create_solr_queue(self, function_name): + """Creates unique Solr queue for each record.""" for rec in self: self.env['apache.solr.queue'].create_unique({ 'res_model': self._name, @@ -24,26 +26,30 @@ class WebsiteCategoriesHomepage(models.Model): @api.constrains('status') def _create_solr_queue_sync_status(self): + """Triggers Solr sync when the status changes.""" self._create_solr_queue('_sync_status_category_homepage_solr') @api.constrains('category_id', 'category_id2', 'sequence') def _create_solr_queue_sync_category_homepage(self): + """Triggers Solr sync when categories or sequence change.""" self._create_solr_queue('_sync_category_management_to_solr') def action_sync_to_solr(self): + """Manual action to sync selected categories to Solr.""" category_ids = self.env.context.get('active_ids', []) categories = self.search([('id', 'in', category_ids)]) categories._create_solr_queue('_sync_category_management_to_solr') def unlink(self): - res = super(WebsiteCategoriesHomepage, self).unlink() + """Overrides unlink method to remove records from Solr.""" for rec in self: self.solr().delete(rec.id) self.solr().optimize() self.solr().commit() - return res + return super(WebsiteCategoriesHomepage, self).unlink() def _sync_status_category_homepage_solr(self): + """Syncs status to Solr or deletes if not active.""" for rec in self: if rec.status == 'tayang': rec._sync_category_management_to_solr() @@ -51,13 +57,14 @@ class WebsiteCategoriesHomepage(models.Model): rec.unlink() def _sync_category_management_to_solr(self): + """Syncs categories (Level 1, 2, and 3) to Solr.""" solr_model = self.env['apache.solr'] for category in self: if category.status != 'tayang': continue - # Level 1 Document + # Prepare Level 1 document document = solr_model.get_doc('category_management', category.id) document.update({ 'id': category.id, @@ -65,44 +72,39 @@ class WebsiteCategoriesHomepage(models.Model): 'name_s': category.category_id.name, 'image_s': self.env['ir.attachment'].api_image('product.public.category', 'image_1920', category.category_id.id), 'sequence_i': category.sequence or '', - 'numFound_i': len(category.category_id.product_tmpl_ids.ids), + 'numFound_i': len(category.category_id.product_tmpl_ids), }) - # Level 2 and Level 3 Documents + # Prepare Level 2 documents level_2_docs = [] - for x in category.category_id2: + for category_level_2 in category.line_ids.mapped('category_id2'): level_2_doc = { - 'id_level_2': x.id, - 'name_level_2': x.name, - 'numFound_level_2': len(x.product_tmpl_ids.ids), - 'image_level_2': self.env['ir.attachment'].api_image('product.public.category', 'image_1920', x.id), + 'id_level_2': category_level_2.id, + 'name_level_2': category_level_2.name, + 'numFound_level_2': len(category_level_2.product_tmpl_ids), + 'image_level_2': self.env['ir.attachment'].api_image('product.public.category', 'image_1920', category_level_2.id), 'categories_level_3': [] } - # Level 3 Data - for child in x.child_frontend_id2: + # Prepare Level 3 documents + for category_level_3 in category_level_2.child_frontend_id2: level_3_doc = { - 'id_level_3': child.id, - 'name_level_3': child.name, - 'numFound_level_3': len(child.product_tmpl_ids.ids), - 'image_level_3': self.env['ir.attachment'].api_image('product.public.category', 'image_1920', child.id), + 'id_level_3': category_level_3.id, + 'name_level_3': category_level_3.name, + 'numFound_level_3': len(category_level_3.product_tmpl_ids), + 'image_level_3': self.env['ir.attachment'].api_image('product.public.category', 'image_1920', category_level_3.id), } level_2_doc['categories_level_3'].append(level_3_doc) level_2_docs.append(level_2_doc) - # Add level 2 documents to level 1 document + # Add Level 2 documents to Level 1 document document['categories_level_2'] = level_2_docs - # Add document to Solr + # Sync document with Solr self.solr().add([document]) category.update_last_update_solr() + # Commit and optimize Solr changes self.solr().commit() - - - # def _sync_delete_solr(self): - # for rec in self: - # self.solr().delete(rec.id) - # self.solr().optimize() - # self.solr().commit() \ No newline at end of file + self.solr().optimize() -- cgit v1.2.3 From 94be2756aa2ab4c5a403877e9085eab344468f1a Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 6 Sep 2024 09:31:28 +0700 Subject: update category management --- .../models/solr/website_categories_management.py | 44 ++++++++++++---------- .../models/website_categories_management.py | 4 ++ 2 files changed, 28 insertions(+), 20 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/solr/website_categories_management.py b/indoteknik_custom/models/solr/website_categories_management.py index fe85f8e7..1f4caac3 100644 --- a/indoteknik_custom/models/solr/website_categories_management.py +++ b/indoteknik_custom/models/solr/website_categories_management.py @@ -65,41 +65,44 @@ class WebsiteCategoriesHomepage(models.Model): continue # Prepare Level 1 document - document = solr_model.get_doc('category_management', category.id) - document.update({ + document = { 'id': category.id, + 'sequence': category.sequence or '', 'category_id_i': category.category_id.id, - 'name_s': category.category_id.name, - 'image_s': self.env['ir.attachment'].api_image('product.public.category', 'image_1920', category.category_id.id), - 'sequence_i': category.sequence or '', - 'numFound_i': len(category.category_id.product_tmpl_ids), - }) + 'name': category.category_id.name, + 'numFound': len(category.category_id.product_tmpl_ids), + 'image': self.env['ir.attachment'].api_image( + 'product.public.category', 'image_1920', category.category_id.id + ), + 'categories': [] + } # Prepare Level 2 documents - level_2_docs = [] for category_level_2 in category.line_ids.mapped('category_id2'): level_2_doc = { 'id_level_2': category_level_2.id, - 'name_level_2': category_level_2.name, - 'numFound_level_2': len(category_level_2.product_tmpl_ids), - 'image_level_2': self.env['ir.attachment'].api_image('product.public.category', 'image_1920', category_level_2.id), - 'categories_level_3': [] + 'name': category_level_2.name, + 'numFound': len(category_level_2.product_tmpl_ids), + 'image': self.env['ir.attachment'].api_image( + 'product.public.category', 'image_1920', category_level_2.id + ), + 'child_frontend_id_i': [] } # Prepare Level 3 documents for category_level_3 in category_level_2.child_frontend_id2: level_3_doc = { 'id_level_3': category_level_3.id, - 'name_level_3': category_level_3.name, - 'numFound_level_3': len(category_level_3.product_tmpl_ids), - 'image_level_3': self.env['ir.attachment'].api_image('product.public.category', 'image_1920', category_level_3.id), + 'name': category_level_3.name, + 'numFound': len(category_level_3.product_tmpl_ids), + 'image': self.env['ir.attachment'].api_image( + 'product.public.category', 'image_1920', category_level_3.id + ), } - level_2_doc['categories_level_3'].append(level_3_doc) - - level_2_docs.append(level_2_doc) + level_2_doc['child_frontend_id_i'].append(level_3_doc) - # Add Level 2 documents to Level 1 document - document['categories_level_2'] = level_2_docs + # Add Level 2 document to Level 1 + document['categories'].append(level_2_doc) # Sync document with Solr self.solr().add([document]) @@ -108,3 +111,4 @@ class WebsiteCategoriesHomepage(models.Model): # Commit and optimize Solr changes self.solr().commit() self.solr().optimize() + diff --git a/indoteknik_custom/models/website_categories_management.py b/indoteknik_custom/models/website_categories_management.py index e430ef5f..3b1db7dd 100644 --- a/indoteknik_custom/models/website_categories_management.py +++ b/indoteknik_custom/models/website_categories_management.py @@ -7,6 +7,10 @@ class WebsiteCategoriesManagement(models.Model): category_id = fields.Many2one('product.public.category', string='Category Level 1', help='table ecommerce category', domain=lambda self: self._get_default_category_domain()) sequence = fields.Integer(string='Sequence') + category_id2 = fields.Many2many(comodel_name='product.public.category', + relation='website_categories_category_id2_rel', + column1='website_categories_homepage_id', column2='product_public_category_id', + string='Category Level 2', copy=False) line_ids = fields.One2many('website.categories.management.line', 'management_id', string='Category Level 2 Lines', auto_join=True) status = fields.Selection([ ('tayang', 'Tayang'), -- cgit v1.2.3 From f6a26ebaa1b960b0ad5de8f6f28238c1e31cd621 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 6 Sep 2024 14:32:39 +0700 Subject: upadate category management sync to solr --- .../models/solr/website_categories_management.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/solr/website_categories_management.py b/indoteknik_custom/models/solr/website_categories_management.py index 1f4caac3..0a40a356 100644 --- a/indoteknik_custom/models/solr/website_categories_management.py +++ b/indoteknik_custom/models/solr/website_categories_management.py @@ -67,11 +67,11 @@ class WebsiteCategoriesHomepage(models.Model): # Prepare Level 1 document document = { 'id': category.id, - 'sequence': category.sequence or '', + 'sequence_i': category.sequence or '', 'category_id_i': category.category_id.id, - 'name': category.category_id.name, - 'numFound': len(category.category_id.product_tmpl_ids), - 'image': self.env['ir.attachment'].api_image( + 'name_s': category.category_id.name, + 'numFound_i': len(category.category_id.product_tmpl_ids), + 'image_s': self.env['ir.attachment'].api_image( 'product.public.category', 'image_1920', category.category_id.id ), 'categories': [] @@ -99,10 +99,10 @@ class WebsiteCategoriesHomepage(models.Model): 'product.public.category', 'image_1920', category_level_3.id ), } - level_2_doc['child_frontend_id_i'].append(level_3_doc) + level_2_doc['child_frontend_id_i'].append(json.dumps(level_3_doc)) # Add Level 2 document to Level 1 - document['categories'].append(level_2_doc) + document['categories'].append(json.dumps(level_2_doc)) # Sync document with Solr self.solr().add([document]) -- cgit v1.2.3 From 494acce1cb7490ab27ad06d2bb9f36d98fbb2256 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Sat, 7 Sep 2024 09:34:40 +0700 Subject: fix bug commision --- indoteknik_custom/models/commision.py | 1 + 1 file changed, 1 insertion(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/commision.py b/indoteknik_custom/models/commision.py index c5809005..48f1c7f6 100644 --- a/indoteknik_custom/models/commision.py +++ b/indoteknik_custom/models/commision.py @@ -261,6 +261,7 @@ class CustomerCommision(models.Model): ('move_id.invoice_date', '>=', self.date_from), ('move_id.invoice_date', '<=', self.date_to), ('product_id.x_manufacture', 'in', brand), + ('exclude_from_invoice_tab', '=', False), ] invoice_lines = self.env['account.move.line'].search(where, order='id') for invoice_line in invoice_lines: -- cgit v1.2.3 From 0aacd16c72067c0bb5c9c8ca24bb19a7995b132b Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 9 Sep 2024 10:34:58 +0700 Subject: delete not lines category management --- indoteknik_custom/models/website_categories_management.py | 4 ---- 1 file changed, 4 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/website_categories_management.py b/indoteknik_custom/models/website_categories_management.py index 3b1db7dd..e430ef5f 100644 --- a/indoteknik_custom/models/website_categories_management.py +++ b/indoteknik_custom/models/website_categories_management.py @@ -7,10 +7,6 @@ class WebsiteCategoriesManagement(models.Model): category_id = fields.Many2one('product.public.category', string='Category Level 1', help='table ecommerce category', domain=lambda self: self._get_default_category_domain()) sequence = fields.Integer(string='Sequence') - category_id2 = fields.Many2many(comodel_name='product.public.category', - relation='website_categories_category_id2_rel', - column1='website_categories_homepage_id', column2='product_public_category_id', - string='Category Level 2', copy=False) line_ids = fields.One2many('website.categories.management.line', 'management_id', string='Category Level 2 Lines', auto_join=True) status = fields.Selection([ ('tayang', 'Tayang'), -- cgit v1.2.3 From 894d4806067463fceaa2c6e6a67882e8f0bed974 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 9 Sep 2024 11:04:35 +0700 Subject: remove product sementara validation --- indoteknik_custom/models/product_template.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index e6778758..000ee3bf 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -338,9 +338,9 @@ class ProductTemplate(models.Model): return values def write(self, vals): - for rec in self: - if rec.id == 224484: - raise UserError('Tidak dapat mengubah produk sementara') + # for rec in self: + # if rec.id == 224484: + # raise UserError('Tidak dapat mengubah produk sementara') return super(ProductTemplate, self).write(vals) -- cgit v1.2.3 From ee22bb5c668c346c5f8ba2c4e148324dab0c6a3e Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 10 Sep 2024 10:27:15 +0700 Subject: bill dp --- indoteknik_custom/models/purchase_order.py | 47 ++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 8ec904a9..83e401b7 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -66,6 +66,53 @@ class PurchaseOrder(models.Model): ('printed', 'Printed') ], string='Printed?', copy=False, tracking=True) date_done_picking = fields.Datetime(string='Date Done Picking', compute='get_date_done') + bills_dp_id = fields.Many2one('account.move', string='Bills DP') + + def create_bill_dp(self): + if not self.env.user.is_accounting: + raise UserError('Hanya Accounting yang bisa bikin bill dp') + + current_date = datetime.utcnow() + data_bills = { + 'partner_id': self.partner_id.id, + 'partner_shipping_id': self.partner_id.id, + 'ref': self.name, + 'invoice_date': current_date, + 'date': current_date, + 'move_type': 'in_invoice' + + } + + bills = self.env['account.move'].create([data_bills]) + + product_dp = self.env['product.product'].browse(229625) + + data_line_bills = { + 'move_id': bills.id, + 'product_id': product_dp.id, #product down payment + 'account_id': 401, #Uang Muka persediaan barang dagang + 'quantity': 1, + 'product_uom_id': 1, + 'tax_ids': [line[0].taxes_id.id for line in self.order_line], + } + + + bills_line = self.env['account.move.line'].create([data_line_bills]) + + self.bills_dp_id = bills.id + + move_line = bills.line_ids + move_line.name = '[IT.121456] Down Payment' + move_line.partner_id = self.partner_id.id + + return { + 'name': _('Account Move'), + 'view_mode': 'tree,form', + 'res_model': 'account.move', + 'target': 'current', + 'type': 'ir.actions.act_window', + 'domain': [('id', '=', bills.id)] + } def get_date_done(self): picking = self.env['stock.picking'].search([ -- cgit v1.2.3 From b61d191e9d5663acb81338de133789fd0c43bdf0 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 10 Sep 2024 16:10:15 +0700 Subject: add payment terms on users --- indoteknik_custom/models/res_users.py | 1 + 1 file changed, 1 insertion(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/res_users.py b/indoteknik_custom/models/res_users.py index 33f64ce3..70a7dc53 100755 --- a/indoteknik_custom/models/res_users.py +++ b/indoteknik_custom/models/res_users.py @@ -11,6 +11,7 @@ class ResUsers(models.Model): activation_token = fields.Char(string="Activation Token") otp_code = fields.Char(string='OTP Code') otp_create_date = fields.Datetime(string='OTP Create Date') + payment_terms_id = fields.Many2one('account.payment.term', related='partner_id.property_payment_term_id', string='Payment Terms') def _generate_otp(self): for user in self: -- cgit v1.2.3 From 1371df38b6818960e6e9520ae783f041694209d8 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 11 Sep 2024 13:39:13 +0700 Subject: ongkos kirim po --- indoteknik_custom/models/purchase_order.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 83e401b7..edcbbb19 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -31,6 +31,7 @@ class PurchaseOrder(models.Model): ('approved', 'Approved'), ], string='Approval Status', readonly=True, copy=False, index=True, tracking=3) delivery_amount = fields.Float('Delivery Amount', compute='compute_delivery_amount') + delivery_amt = fields.Float('Delivery Amt') total_margin = fields.Float( 'Margin', compute='compute_total_margin', help="Total Margin in Sales Order Header") @@ -67,6 +68,14 @@ class PurchaseOrder(models.Model): ], string='Printed?', copy=False, tracking=True) date_done_picking = fields.Datetime(string='Date Done Picking', compute='get_date_done') bills_dp_id = fields.Many2one('account.move', string='Bills DP') + grand_total = fields.Monetary(string='Grand Total', help='Amount total + amount delivery', compute='_compute_grand_total') + + def _compute_grand_total(self): + for order in self: + if order.delivery_amt: + order.grand_total = order.delivery_amt + order.amount_total + else: + order.grand_total = order.amount_total def create_bill_dp(self): if not self.env.user.is_accounting: @@ -671,6 +680,8 @@ class PurchaseOrder(models.Model): purchase_price = line.price_subtotal if line.order_id.delivery_amount > 0: purchase_price += line.delivery_amt_line + if line.order_id.delivery_amt > 0: + purchase_price += line.order_id.delivery_amt real_item_margin = sales_price - purchase_price sum_margin += real_item_margin @@ -713,6 +724,8 @@ class PurchaseOrder(models.Model): purchase_price = po_line.price_subtotal / po_line.product_qty * line.qty_po if line.purchase_order_id.delivery_amount > 0: purchase_price += (po_line.delivery_amt_line / po_line.product_qty) * line.qty_po + if line.purchase_order_id.delivery_amt > 0: + purchase_price += line.purchase_order_id.delivery_amt real_item_margin = sales_price - purchase_price sum_margin += real_item_margin -- cgit v1.2.3 From d8e60a974097058482167eefe658f9b4e89c0dd2 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 11 Sep 2024 16:07:56 +0700 Subject: mandatory delivery date --- indoteknik_custom/models/sale_order.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index b6759306..5e792b05 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -633,6 +633,9 @@ class SaleOrder(models.Model): if not order.client_order_ref and order.create_date > datetime(2024, 6, 27): raise UserError("Customer Reference kosong, di isi dengan NO PO jika PO tidak ada mohon ditulis Tanpa PO") + + if not order.commitment_date and order.create_date > datetime(2024, 9, 10): + raise UserError("Expected Delivery Date kosong, wajib diisi") if order.validate_partner_invoice_due(): return self._create_notification_action('Notification', 'Terdapat invoice yang telah melewati batas waktu, mohon perbarui pada dokumen Due Extension') -- cgit v1.2.3 From a8e539c92236453ce7aad06d23cf117f4b7239fc Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 11 Sep 2024 16:08:30 +0700 Subject: revise --- indoteknik_custom/models/sale_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 5e792b05..9506aedb 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -634,7 +634,7 @@ class SaleOrder(models.Model): if not order.client_order_ref and order.create_date > datetime(2024, 6, 27): raise UserError("Customer Reference kosong, di isi dengan NO PO jika PO tidak ada mohon ditulis Tanpa PO") - if not order.commitment_date and order.create_date > datetime(2024, 9, 10): + if not order.commitment_date and order.create_date > datetime(2024, 9, 12): raise UserError("Expected Delivery Date kosong, wajib diisi") if order.validate_partner_invoice_due(): -- cgit v1.2.3 From fdd67910ef7d4dd66803d09a7c49b1c3faabdd18 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 12 Sep 2024 10:53:10 +0700 Subject: deactivate function update_purchase_price_so_line --- indoteknik_custom/models/automatic_purchase.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py index 1d1322fa..13c83b04 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -262,7 +262,7 @@ class AutomaticPurchase(models.Model): new_po_line = self.env['purchase.order.line'].create([param_line]) line.current_po_id = new_po.id line.current_po_line_id = new_po_line.id - self.update_purchase_price_so_line(line) + # self.update_purchase_price_so_line(line) self.create_purchase_order_sales_match(new_po) -- cgit v1.2.3 From a37bc839612b5162b4446182ac23c1dfd1c3253e Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 12 Sep 2024 14:17:36 +0700 Subject: calculate margin after purchase delivery deduction --- indoteknik_custom/models/automatic_purchase.py | 6 ++++- indoteknik_custom/models/purchase_order.py | 11 +++++++++ .../models/purchase_order_sales_match.py | 12 +++++++++- indoteknik_custom/models/sale_order.py | 26 ++++++++++++++++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py index 1d1322fa..4531cff9 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -293,6 +293,9 @@ class AutomaticPurchase(models.Model): sale_ids_set.add(sale_id_with_salesperson) sale_ids_name.add(sale_order.sale_id.name) + margin_item = sale_order.sale_line_id.item_margin / sale_order.qty_so if sale_order.qty_so else 0 + margin_item = margin_item * sale_order.qty_po + matches_so_line = { 'purchase_order_id': purchase_order.id, 'sale_id': sale_order.sale_id.id, @@ -305,7 +308,8 @@ class AutomaticPurchase(models.Model): 'product_id': sale_order.product_id.id, 'qty_so': sale_order.qty_so, 'qty_po': sale_order.qty_po, - 'margin_so': sale_order.sale_line_id.item_percent_margin + 'margin_so': sale_order.sale_line_id.item_percent_margin, + 'margin_item': margin_item } po_matches_so_line = self.env['purchase.order.sales.match'].create([matches_so_line]) diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index edcbbb19..afa67cf2 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -69,6 +69,17 @@ class PurchaseOrder(models.Model): date_done_picking = fields.Datetime(string='Date Done Picking', compute='get_date_done') bills_dp_id = fields.Many2one('account.move', string='Bills DP') grand_total = fields.Monetary(string='Grand Total', help='Amount total + amount delivery', compute='_compute_grand_total') + total_margin_match = fields.Float(string='Total Margin Match', compute='_compute_total_margin_match') + + def _compute_total_margin_match(self): + for purchase in self: + match = self.env['purchase.order.sales.match'] + result = match.read_group( + [('purchase_order_id.id', '=', purchase.id)], + ['margin_item'], + [] + ) + purchase.total_margin_match = result[0].get('margin_item', 0.0) def _compute_grand_total(self): for order in self: diff --git a/indoteknik_custom/models/purchase_order_sales_match.py b/indoteknik_custom/models/purchase_order_sales_match.py index 78581409..d1d929d3 100644 --- a/indoteknik_custom/models/purchase_order_sales_match.py +++ b/indoteknik_custom/models/purchase_order_sales_match.py @@ -20,7 +20,17 @@ class PurchaseOrderSalesMatch(models.Model): product_id = fields.Many2one('product.product', string='Product') qty_so = fields.Float(string='Qty SO') qty_po = fields.Float(string='Qty PO') - margin_so = fields.Float(string='Margin SO') + margin_so = fields.Float(string='Margin SO') + margin_item = fields.Float(string='Margin') + delivery_amt = fields.Float(string='Delivery Amount', compute='_compute_delivery_amt') + margin_deduct = fields.Float(string='After Deduct', compute='_compute_delivery_amt') + + def _compute_delivery_amt(self): + for line in self: + percent_margin = line.margin_item / line.purchase_order_id.total_margin_match \ + if line.purchase_order_id.total_margin_match else 0 + line.delivery_amt = line.purchase_order_id.delivery_amt * percent_margin + line.margin_deduct = line.margin_item - line.delivery_amt @api.onchange('sale_id') def onchange_sale_id(self): diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 9506aedb..9a6dbd9e 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -112,6 +112,32 @@ class SaleOrder(models.Model): 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 Shipping', copy=False) + margin_after_delivery_purchase = fields.Float(string='Margin After Delivery Purchase', compute='_compute_margin_after_delivery_purchase') + percent_margin_after_delivery_purchase = fields.Float(string='% Margin After Delivery Purchase', compute='_compute_margin_after_delivery_purchase') + purchase_delivery_amt = fields.Float(string='Purchase Delivery Amount', compute='_compute_purchase_delivery_amount') + + def _compute_purchase_delivery_amount(self): + for order in self: + match = self.env['purchase.order.sales.match'] + result2 = match.search([ + ('sale_id.id', '=', order.id) + ]) + delivery_amt = 0 + for res in result2: + delivery_amt = res.delivery_amt + order.purchase_delivery_amt = delivery_amt + + def _compute_margin_after_delivery_purchase(self): + for order in self: + order.margin_after_delivery_purchase = order.total_margin - order.purchase_delivery_amt + if order.amount_untaxed == 0: + order.total_percent_margin = 0 + continue + if order.shipping_cost_covered == 'indoteknik': + delivery_amt = order.delivery_amt + else: + delivery_amt = 0 + order.percent_margin_after_delivery_purchase = round((order.margin_after_delivery_purchase / (order.amount_untaxed-delivery_amt-order.fee_third_party)) * 100, 2) def _compute_date_kirim(self): for rec in self: -- cgit v1.2.3 From c81f7b9f21d5ae9c77758a67bbf961fb42697dd8 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 13 Sep 2024 10:30:15 +0700 Subject: validation product sementara --- indoteknik_custom/models/sale_order_line.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py index a64a744c..50438dbe 100644 --- a/indoteknik_custom/models/sale_order_line.py +++ b/indoteknik_custom/models/sale_order_line.py @@ -348,7 +348,7 @@ class SaleOrderLine(models.Model): def validate_line(self): for line in self: - if line.product_id.id in [385544, 224484]: + if line.product_id.id in [385544, 224484, 417724]: raise UserError('Produk Sementara Tidak Bisa Di Confirm atau Ask Approval') if not line.product_id or line.product_id.type == 'service': continue -- cgit v1.2.3 From f44dc785ffcce7738c284fd40d79dbece7b2e5cb Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 13 Sep 2024 14:22:19 +0700 Subject: add validation on stock picking gudang selisih --- indoteknik_custom/models/stock_picking.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index d16d508e..3dd960e2 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -373,6 +373,9 @@ class StockPicking(models.Model): if self.picking_type_id.id == 28 and not self.env.user.is_logistic_approver: raise UserError("Harus di Approve oleh Logistik") + + if self.location_dest_id.id == 47 and not self.env.user.is_purchasing_manager: + raise UserError("Transfer ke gudang selisih harus di approve Rafly Hanggara") if self.group_id.sale_id: if self.group_id.sale_id.payment_link_midtrans: -- cgit v1.2.3 From 649a8f0d51b8fa7dc90dfbd0967e94dd586cd0aa Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 13 Sep 2024 16:21:50 +0700 Subject: bug fix sales order with amount equal zero --- indoteknik_custom/models/sale_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 9a6dbd9e..6348328e 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -131,7 +131,7 @@ class SaleOrder(models.Model): for order in self: order.margin_after_delivery_purchase = order.total_margin - order.purchase_delivery_amt if order.amount_untaxed == 0: - order.total_percent_margin = 0 + order.percent_margin_after_delivery_purchase = 0 continue if order.shipping_cost_covered == 'indoteknik': delivery_amt = order.delivery_amt -- cgit v1.2.3 From 2e9f95e8201692317d1ce23f6992fdb0e37dc95c Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 13 Sep 2024 16:51:28 +0700 Subject: cr archive product --- indoteknik_custom/models/product_template.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 000ee3bf..031d1b5b 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -388,8 +388,16 @@ class ProductProduct(models.Model): if product_template.active and product.active: if not product.active and len(variants) == 1: product_template.with_context(skip_active_constraint=True).active = False + product_template.unpublished = True elif not product.active and len(variants) > 1: - continue + all_inactive = all(not variant.active for variant in variants) + if all_inactive: + product_template.with_context(skip_active_constraint=True).active = False + product_template.unpublished = True + else: + continue + if any(variant.active for variant in variants): + product_template.unpublished = False def update_internal_reference_variants(self, limit=100): variants = self.env['product.product'].search([ -- cgit v1.2.3 From 98bdb05daa79c46b0a1f4284d19e65ed3a7d2f48 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Sat, 14 Sep 2024 13:30:14 +0700 Subject: bug fix delete purchase order line cause of calculate margin match --- indoteknik_custom/models/purchase_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index afa67cf2..8a47482a 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -75,7 +75,7 @@ class PurchaseOrder(models.Model): for purchase in self: match = self.env['purchase.order.sales.match'] result = match.read_group( - [('purchase_order_id.id', '=', purchase.id)], + [('purchase_order_id', '=', purchase.id)], ['margin_item'], [] ) -- cgit v1.2.3 From f0aaf4476c8b92cb68503e9760216ca20fe4e34d Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 17 Sep 2024 14:05:31 +0700 Subject: api check_tempo and add type promotion on sale order --- indoteknik_custom/models/sale_order.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 6348328e..43ee3ef9 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -115,6 +115,17 @@ class SaleOrder(models.Model): margin_after_delivery_purchase = fields.Float(string='Margin After Delivery Purchase', compute='_compute_margin_after_delivery_purchase') percent_margin_after_delivery_purchase = fields.Float(string='% Margin After Delivery Purchase', compute='_compute_margin_after_delivery_purchase') purchase_delivery_amt = fields.Float(string='Purchase Delivery Amount', compute='_compute_purchase_delivery_amount') + type_promotion = fields.Char(string='Type Promotion', compute='_compute_type_promotion') + + def _compute_type_promotion(self): + for rec in self: + promotion_types = [] + for promotion in rec.order_promotion_ids: + for line_program in promotion.program_line_id: + if line_program.promotion_type: + promotion_types.append(dict(line_program._fields['promotion_type'].selection).get(line_program.promotion_type)) + + rec.type_promotion = ', '.join(promotion_types) def _compute_purchase_delivery_amount(self): for order in self: -- cgit v1.2.3 From 1698ec300f2e7c363e41cb51ce94a39f66d6088b Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 17 Sep 2024 14:43:22 +0700 Subject: cr type promotion --- indoteknik_custom/models/sale_order.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 43ee3ef9..65b92601 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -125,7 +125,9 @@ class SaleOrder(models.Model): if line_program.promotion_type: promotion_types.append(dict(line_program._fields['promotion_type'].selection).get(line_program.promotion_type)) - rec.type_promotion = ', '.join(promotion_types) + # Removing duplicates by converting to a set, then back to a list + rec.type_promotion = ', '.join(sorted(set(promotion_types))) + def _compute_purchase_delivery_amount(self): for order in self: -- cgit v1.2.3 From fd66c221b48c28a3aaf45500572821aaae84c0de Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 17 Sep 2024 15:38:00 +0700 Subject: add is_efaktur_exported to tree invoices --- indoteknik_custom/models/sale_order.py | 1 - 1 file changed, 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 65b92601..bd0fb75e 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -128,7 +128,6 @@ class SaleOrder(models.Model): # Removing duplicates by converting to a set, then back to a list rec.type_promotion = ', '.join(sorted(set(promotion_types))) - def _compute_purchase_delivery_amount(self): for order in self: match = self.env['purchase.order.sales.match'] -- cgit v1.2.3 From b34c5cc5d6cc3dc1e9ccf43cecc14a5a7a427992 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 18 Sep 2024 11:02:51 +0700 Subject: change condition --- indoteknik_custom/models/account_move.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index a7010bbe..725b3c2d 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -174,7 +174,7 @@ class AccountMove(models.Model): def _compute_mark_upload_efaktur(self): for move in self: - if move.date_efaktur_exported or move.is_efaktur_exported or move.efaktur_document: + if move.efaktur_document: move.mark_upload_efaktur = 'sudah_upload' else: move.mark_upload_efaktur = 'belum_upload' -- cgit v1.2.3 From d2bb21ae878db2a3b77dbb3341046c9d12ba1de5 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 20 Sep 2024 14:12:00 +0700 Subject: add grand total on dunning run and bill receipt --- indoteknik_custom/models/bill_receipt.py | 10 +++++++++- indoteknik_custom/models/dunning_run.py | 9 ++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/bill_receipt.py b/indoteknik_custom/models/bill_receipt.py index 76449c1f..7d38d5ad 100644 --- a/indoteknik_custom/models/bill_receipt.py +++ b/indoteknik_custom/models/bill_receipt.py @@ -22,8 +22,16 @@ class BillReceipt(models.Model): resi_tukar_faktur = fields.Char(string='Resi Faktur') date_terima_tukar_faktur = fields.Date(string='Terima Faktur') shipper_faktur_id = fields.Many2one('delivery.carrier', string='Shipper Faktur') - is_validated = fields.Boolean(string='Validated') + is_validated = fields.Boolean(string='Validated') notification = fields.Char(string='Notification') + grand_total = fields.Float(string='Grand Total', compute="_compute_grand_total") + + def _compute_grand_total(self): + for record in self: + grand_total = 0 + for line in record.bill_line: + grand_total += line.total_amt + record.grand_total = grand_total def copy_date_faktur(self): if not self.is_validated: diff --git a/indoteknik_custom/models/dunning_run.py b/indoteknik_custom/models/dunning_run.py index 90159cd0..c167aab7 100644 --- a/indoteknik_custom/models/dunning_run.py +++ b/indoteknik_custom/models/dunning_run.py @@ -30,7 +30,14 @@ class DunningRun(models.Model): is_paid = fields.Boolean(string='Paid') description = fields.Char(string='Description') comment = fields.Char(string='Comment') - + grand_total = fields.Float(string='Grand Total', compute="_compute_grand_total") + + def _compute_grand_total(self): + for record in self: + grand_total = 0 + for line in record.dunning_line: + grand_total += line.total_amt + record.grand_total = grand_total def copy_date_faktur(self): if not self.is_validated: -- cgit v1.2.3