From 6adb1cb5fe8dbe85b971dc1cad476718f24c38cb Mon Sep 17 00:00:00 2001 From: FIN-IT_AndriFP Date: Wed, 1 Oct 2025 13:49:26 +0700 Subject: (andri) add validasi approval pimpinan jika PO biasa tidak ada matches SO dan PO PJ terdapat matches SO line dengan SO margin <=15% --- indoteknik_custom/models/purchase_order.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index b34ec926..a76cdab1 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -1069,6 +1069,19 @@ class PurchaseOrder(models.Model): ) % order.name) def button_confirm(self): + if self.env.user.id != 7: # Pimpinan + if '/PJ/' in self.name: + low_margin_lines = self.order_sales_match_line.filtered( + lambda match: match.sale_line_id.item_percent_margin <= 34.0 + ) + if low_margin_lines: + raise UserError("Matches SO terdapat item dengan margin SO <= 15%. Approval Pimpinan diperlukan.") + else: + is_po_manual = '/A/' not in self.name and '/MO/' not in self.name + if is_po_manual: + if not self.order_sales_match_line: + raise UserError("Tidak ada matches SO, Approval Pimpinan diperlukan.") + self._check_assets_note() # self._check_payment_term() # check payment term res = super(PurchaseOrder, self).button_confirm() -- cgit v1.2.3 From c04dd5a6a38ba35b30a39ed6596514679067e541 Mon Sep 17 00:00:00 2001 From: FIN-IT_AndriFP Date: Wed, 1 Oct 2025 15:10:10 +0700 Subject: (andri) add so header margin pada matches SO + fix --- indoteknik_custom/models/purchase_order.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index a76cdab1..1a88d036 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -1072,10 +1072,10 @@ class PurchaseOrder(models.Model): if self.env.user.id != 7: # Pimpinan if '/PJ/' in self.name: low_margin_lines = self.order_sales_match_line.filtered( - lambda match: match.sale_line_id.item_percent_margin <= 34.0 + lambda match: match.so_header_margin <= 34.0 ) if low_margin_lines: - raise UserError("Matches SO terdapat item dengan margin SO <= 15%. Approval Pimpinan diperlukan.") + raise UserError("Matches SO terdapat item dengan header margin SO <= 15%. Approval Pimpinan diperlukan.") else: is_po_manual = '/A/' not in self.name and '/MO/' not in self.name if is_po_manual: -- cgit v1.2.3 From 7abcc2bd055eecea8caacae8187b7dacff671c46 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 16 Oct 2025 10:46:15 +0700 Subject: push --- indoteknik_custom/models/purchase_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index b34ec926..672db7cf 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -1354,7 +1354,7 @@ class PurchaseOrder(models.Model): for rec in self: if rec.from_apo: rec.compute_total_margin_from_apo() - return + continue sum_so_margin = sum_sales_price = sum_margin = 0 for line in self.order_line: -- cgit v1.2.3 From 8ff0270ee40b34d8eb85cd8d5e9572211a0e36a9 Mon Sep 17 00:00:00 2001 From: FIN-IT_AndriFP Date: Thu, 16 Oct 2025 11:52:52 +0700 Subject: (andri) off check po manual confirm --- indoteknik_custom/models/purchase_order.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 1a88d036..f8718a0d 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -1072,15 +1072,15 @@ class PurchaseOrder(models.Model): if self.env.user.id != 7: # Pimpinan if '/PJ/' in self.name: low_margin_lines = self.order_sales_match_line.filtered( - lambda match: match.so_header_margin <= 34.0 + lambda match: match.so_header_margin <= 15.0 ) if low_margin_lines: raise UserError("Matches SO terdapat item dengan header margin SO <= 15%. Approval Pimpinan diperlukan.") - else: - is_po_manual = '/A/' not in self.name and '/MO/' not in self.name - if is_po_manual: - if not self.order_sales_match_line: - raise UserError("Tidak ada matches SO, Approval Pimpinan diperlukan.") + # else: + # is_po_manual = '/A/' not in self.name and '/MO/' not in self.name + # if is_po_manual: + # if not self.order_sales_match_line: + # raise UserError("Tidak ada matches SO, Approval Pimpinan diperlukan.") self._check_assets_note() # self._check_payment_term() # check payment term -- cgit v1.2.3 From e210b6fa5ec6603920f550e5f8cc64e32e832e44 Mon Sep 17 00:00:00 2001 From: FIN-IT_AndriFP Date: Thu, 16 Oct 2025 12:01:20 +0700 Subject: (andri) fix --- indoteknik_custom/models/purchase_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index f8718a0d..7badff95 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -1069,7 +1069,7 @@ class PurchaseOrder(models.Model): ) % order.name) def button_confirm(self): - if self.env.user.id != 7: # Pimpinan + if self.env.user.id != 7 and not self.env.user.is_leader: # Pimpinan if '/PJ/' in self.name: low_margin_lines = self.order_sales_match_line.filtered( lambda match: match.so_header_margin <= 15.0 -- cgit v1.2.3 From bd0cc0fa2518e735cbe766bd0ea3726c63d3ebbd Mon Sep 17 00:00:00 2001 From: FIN-IT_AndriFP Date: Fri, 17 Oct 2025 11:08:26 +0700 Subject: (andri) off validasi approval matches SO --- indoteknik_custom/models/purchase_order.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index b596f365..a1c3c0c4 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -1069,13 +1069,13 @@ class PurchaseOrder(models.Model): ) % order.name) def button_confirm(self): - if self.env.user.id != 7 and not self.env.user.is_leader: # Pimpinan - if '/PJ/' in self.name: - low_margin_lines = self.order_sales_match_line.filtered( - lambda match: match.so_header_margin <= 15.0 - ) - if low_margin_lines: - raise UserError("Matches SO terdapat item dengan header margin SO <= 15%. Approval Pimpinan diperlukan.") + # if self.env.user.id != 7 and not self.env.user.is_leader: # Pimpinan + # if '/PJ/' in self.name: + # low_margin_lines = self.order_sales_match_line.filtered( + # lambda match: match.so_header_margin <= 15.0 + # ) + # if low_margin_lines: + # raise UserError("Matches SO terdapat item dengan header margin SO <= 15%. Approval Pimpinan diperlukan.") # else: # is_po_manual = '/A/' not in self.name and '/MO/' not in self.name # if is_po_manual: -- cgit v1.2.3 From 7ba88682ecb9d1445f5565723adaf93106e056e2 Mon Sep 17 00:00:00 2001 From: FIN-IT_AndriFP Date: Fri, 17 Oct 2025 11:10:33 +0700 Subject: (andri) on --- indoteknik_custom/models/purchase_order.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index a1c3c0c4..b596f365 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -1069,13 +1069,13 @@ class PurchaseOrder(models.Model): ) % order.name) def button_confirm(self): - # if self.env.user.id != 7 and not self.env.user.is_leader: # Pimpinan - # if '/PJ/' in self.name: - # low_margin_lines = self.order_sales_match_line.filtered( - # lambda match: match.so_header_margin <= 15.0 - # ) - # if low_margin_lines: - # raise UserError("Matches SO terdapat item dengan header margin SO <= 15%. Approval Pimpinan diperlukan.") + if self.env.user.id != 7 and not self.env.user.is_leader: # Pimpinan + if '/PJ/' in self.name: + low_margin_lines = self.order_sales_match_line.filtered( + lambda match: match.so_header_margin <= 15.0 + ) + if low_margin_lines: + raise UserError("Matches SO terdapat item dengan header margin SO <= 15%. Approval Pimpinan diperlukan.") # else: # is_po_manual = '/A/' not in self.name and '/MO/' not in self.name # if is_po_manual: -- cgit v1.2.3 From 66983246c83db072c62abba4a40a70e514b081d0 Mon Sep 17 00:00:00 2001 From: FIN-IT_AndriFP Date: Fri, 17 Oct 2025 13:40:39 +0700 Subject: (andri) fix --- indoteknik_custom/models/purchase_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index b596f365..701c0a3f 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -1090,7 +1090,7 @@ class PurchaseOrder(models.Model): self.check_different_vendor_so_po() # self.check_data_vendor() - if self.amount_untaxed >= 50000000 and not self.env.user.id == 21: + if self.amount_untaxed >= 50000000 and not self.env.user.id in (21, 7): raise UserError("Hanya Rafly Hanggara yang bisa approve") if not self.date_planned: -- cgit v1.2.3 From 2cd0d5ede34e2c46b3bcd1f1907cd0526ef42b9d Mon Sep 17 00:00:00 2001 From: FIN-IT_AndriFP Date: Fri, 17 Oct 2025 15:45:48 +0700 Subject: (andri) butuh approval pimpinan bila ada perubahan unit price pada PO PJ + matches SO margin header <=15% --- indoteknik_custom/models/purchase_order.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 701c0a3f..51517437 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -1074,8 +1074,10 @@ class PurchaseOrder(models.Model): low_margin_lines = self.order_sales_match_line.filtered( lambda match: match.so_header_margin <= 15.0 ) - if low_margin_lines: - raise UserError("Matches SO terdapat item dengan header margin SO <= 15%. Approval Pimpinan diperlukan.") + price_change_detected = any(line.price_unit_before for line in self.order_line) + if low_margin_lines and price_change_detected: + # raise UserError("Matches SO terdapat item dengan header margin SO <= 15%. Approval Pimpinan diperlukan.") + raise UserError("Approval Pimpinan diperlukan jika terdapat perubahan Unit Price pada PO Line yang Matches SO item memiliki header margin SO <= 15%") # else: # is_po_manual = '/A/' not in self.name and '/MO/' not in self.name # if is_po_manual: -- cgit v1.2.3 From 2a61388ec5938888710d7c15f660f19ed55def51 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Sat, 18 Oct 2025 11:27:24 +0700 Subject: push --- indoteknik_custom/models/purchase_order.py | 51 +++++++++++------------------- 1 file changed, 19 insertions(+), 32 deletions(-) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 51517437..7fc038a0 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -1420,63 +1420,50 @@ class PurchaseOrder(models.Model): ('product_id', '=', line.product_id.id), ('order_id', '=', line.purchase_order_id.id) ], limit=1) - sale_order_line = line.sale_line_id - if not sale_order_line: - sale_order_line = self.env['sale.order.line'].search([ - ('product_id', '=', line.product_id.id), - ('order_id', '=', line.sale_id.id) - ], limit=1, order='price_reduce_taxexcl') + sale_order_line = line.sale_line_id or self.env['sale.order.line'].search([ + ('product_id', '=', line.product_id.id), + ('order_id', '=', line.sale_id.id) + ], limit=1, order='price_reduce_taxexcl') if sale_order_line and po_line: - so_margin = (line.qty_po / line.qty_so) * sale_order_line.item_margin + qty_so = line.qty_so or 0 + qty_po = line.qty_po or 0 + + # Hindari division by zero + so_margin = (qty_po / qty_so) * sale_order_line.item_margin if qty_so > 0 else 0 sum_so_margin += so_margin - sales_price = sale_order_line.price_reduce_taxexcl * line.qty_po + sales_price = sale_order_line.price_reduce_taxexcl * qty_po if sale_order_line.order_id.shipping_cost_covered == 'indoteknik': - sales_price -= (sale_order_line.delivery_amt_line / sale_order_line.product_uom_qty) * line.qty_po + sales_price -= (sale_order_line.delivery_amt_line / sale_order_line.product_uom_qty) * qty_po if sale_order_line.order_id.fee_third_party > 0: - sales_price -= (sale_order_line.fee_third_party_line / sale_order_line.product_uom_qty) * line.qty_po + sales_price -= (sale_order_line.fee_third_party_line / sale_order_line.product_uom_qty) * qty_po sum_sales_price += sales_price - purchase_price = po_line.price_subtotal if po_line.ending_price > 0: if po_line.taxes_id.id == 22: - ending_price = po_line.ending_price / 1.11 - purchase_price = ending_price + purchase_price = po_line.ending_price / 1.11 else: purchase_price = po_line.ending_price if line.purchase_order_id.delivery_amount > 0: - purchase_price += (po_line.delivery_amt_line / po_line.product_qty) * line.qty_po + purchase_price += (po_line.delivery_amt_line / po_line.product_qty) * 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 - if sum_so_margin != 0 and sum_sales_price != 0 and sum_margin != 0: + # Akumulasi hasil akhir + if sum_sales_price != 0: self.total_so_margin = sum_so_margin self.total_so_percent_margin = round((sum_so_margin / sum_sales_price), 2) * 100 self.total_margin = sum_margin self.total_percent_margin = round((sum_margin / sum_sales_price), 2) * 100 - else: - self.total_margin = 0 - self.total_percent_margin = 0 - self.total_so_margin = 0 - self.total_so_percent_margin = 0 - + self.total_margin = self.total_percent_margin = 0 + self.total_so_margin = self.total_so_percent_margin = 0 - if sum_so_margin != 0 and sum_sales_price != 0 and sum_margin != 0: - self.total_so_margin = sum_so_margin - self.total_so_percent_margin = round((sum_so_margin / sum_sales_price), 2) * 100 - self.total_margin = sum_margin - self.total_percent_margin = round((sum_margin / sum_sales_price), 2) * 100 - - else: - self.total_margin = 0 - self.total_percent_margin = 0 - self.total_so_margin = 0 - self.total_so_percent_margin = 0 def compute_amt_total_without_service(self): for order in self: -- cgit v1.2.3 From 29b3ec084ed1791330551c5de34f045565eef6f1 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 20 Oct 2025 13:18:14 +0700 Subject: push --- indoteknik_custom/models/purchase_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models/purchase_order.py') diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 7fc038a0..e79417aa 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -1369,7 +1369,7 @@ class PurchaseOrder(models.Model): for rec in self: if rec.from_apo: rec.compute_total_margin_from_apo() - continue + return sum_so_margin = sum_sales_price = sum_margin = 0 for line in self.order_line: -- cgit v1.2.3