From 414b741f6fdd3ba37754db516c695231e3fbca6e Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 25 Jul 2025 09:22:20 +0700 Subject: hold refund --- indoteknik_custom/__manifest__.py | 1 + indoteknik_custom/models/refund_sale_order.py | 8 ++++---- indoteknik_custom/models/sale_order.py | 2 +- indoteknik_custom/views/account_move.xml | 6 +++--- indoteknik_custom/views/sale_order.xml | 14 +++++++------- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 21afc26f..93c437af 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -170,6 +170,7 @@ 'views/public_holiday.xml', 'views/stock_inventory.xml', 'views/sale_order_delay.xml', + 'views/refund_sale_order.xml', ], 'demo': [], 'css': [], diff --git a/indoteknik_custom/models/refund_sale_order.py b/indoteknik_custom/models/refund_sale_order.py index 11bfd07f..2a55f16d 100644 --- a/indoteknik_custom/models/refund_sale_order.py +++ b/indoteknik_custom/models/refund_sale_order.py @@ -175,7 +175,7 @@ class RefundSaleOrder(models.Model): if refund_type == 'retur_half' and not invoice_ids: raise ValidationError(f"SO {', '.join(so.mapped('name'))} belum memiliki invoice untuk Retur Sebagian.") - total_invoice = sum(self.env['account.move'].browse(invoice_ids).mapped('amount_total')) if invoice_ids else 0.0 + total_invoice = sum(self.env['account.move'].browse(invoice_ids).mapped('amount_total_signed')) if invoice_ids else 0.0 uang_masuk = vals.get('uang_masuk', 0.0) ongkir = vals.get('ongkir', 0.0) pengurangan = total_invoice + ongkir @@ -266,7 +266,7 @@ class RefundSaleOrder(models.Model): raise ValidationError(f"SO {', '.join(so.mapped('name'))} belum memiliki invoice untuk retur sebagian.") if any(field in vals for field in ['uang_masuk', 'invoice_ids', 'ongkir', 'sale_order_ids']): - total_invoice = sum(self.env['account.move'].browse(invoice_ids).mapped('amount_total')) + total_invoice = sum(self.env['account.move'].browse(invoice_ids).mapped('amount_total_signed')) uang_masuk = vals.get('uang_masuk', rec.uang_masuk) ongkir = vals.get('ongkir', rec.ongkir) @@ -325,7 +325,7 @@ class RefundSaleOrder(models.Model): lambda inv: inv.move_type in ['out_invoice', 'out_refund'] and inv.state != 'cancel' ) all_invoices |= valid_invoices - total_invoice += sum(valid_invoices.mapped('amount_total')) + total_invoice += sum(valid_invoices.mapped('amount_total_signed')) self.invoice_ids = all_invoices @@ -464,7 +464,7 @@ class RefundSaleOrder(models.Model): if self.refund_type not in ['uang', 'barang_kosong']: self.refund_type = False - self.total_invoice = sum(self.invoice_ids.mapped('amount_total')) + self.total_invoice = sum(self.invoice_ids.mapped('amount_total_signed')) def action_ask_approval(self): for rec in self: diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index febdaabd..c4de0d3a 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -3144,7 +3144,7 @@ class SaleOrder(models.Model): invoice_ids = self.mapped('invoice_ids').filtered(lambda inv: inv.state != 'cancel') delivery_total = sum(self.mapped('delivery_amt')) - total_invoice = sum(invoice_ids.mapped('amount_total')) + total_invoice = sum(invoice_ids.mapped('amount_total_signed')) return { 'type': 'ir.actions.act_window', diff --git a/indoteknik_custom/views/account_move.xml b/indoteknik_custom/views/account_move.xml index 9b1c791b..ae944a4a 100644 --- a/indoteknik_custom/views/account_move.xml +++ b/indoteknik_custom/views/account_move.xml @@ -36,9 +36,9 @@ - - + + + diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index 5bcd7641..1a4726d6 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -35,13 +35,13 @@ string="UangMuka" type="action" attrs="{'invisible': [('approval_status', '!=', 'approved')]}"/> - +
- +
@@ -176,7 +176,7 @@ - + - + -- cgit v1.2.3 From b4fa8f4df995f946b642eda78ca5fc2b8badada2 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 28 Jul 2025 15:06:26 +0700 Subject: fixing journal --- indoteknik_custom/models/refund_sale_order.py | 32 ++++++++++++++++++++++----- indoteknik_custom/models/sale_order.py | 6 +++-- indoteknik_custom/views/refund_sale_order.xml | 6 ++--- indoteknik_custom/views/sale_order.xml | 2 +- 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/indoteknik_custom/models/refund_sale_order.py b/indoteknik_custom/models/refund_sale_order.py index 2a55f16d..80d66d8d 100644 --- a/indoteknik_custom/models/refund_sale_order.py +++ b/indoteknik_custom/models/refund_sale_order.py @@ -124,7 +124,7 @@ class RefundSaleOrder(models.Model): self.env.user.has_group('indoteknik_custom.group_role_fat') or self.env.user.id not in allowed_user_ids ): - raise UserError("❌ Hanya user Sales dan Finance yang boleh membuat refund.") + raise UserError("❌ Hanya Sales dan Finance yang boleh membuat refund.") if vals.get('name', 'New') == 'New': @@ -150,13 +150,18 @@ class RefundSaleOrder(models.Model): refund_type = vals.get('refund_type') invoice_ids_data = vals.get('invoice_ids', []) invoice_ids = invoice_ids_data[0][2] if invoice_ids_data and invoice_ids_data[0][0] == 6 else [] - if invoice_ids and refund_type and refund_type not in ['uang', 'barang_kosong_sebagian', 'barang_kosong', 'retur_half']: raise UserError("Refund type Hanya Bisa Lebih Bayar, Barang Kosong Sebagian, atau Retur Sebagian jika ada invoice") - if not invoice_ids and refund_type and refund_type in ['uang', 'barang_kosong_sebagian', 'barang_kosong', 'retur_half']: + if not invoice_ids and refund_type and refund_type in ['uang', 'barang_kosong_sebagian', 'retur_half']: raise UserError("Refund type Lebih Bayar, Barang Kosong Sebagian, atau Retur Sebagian Hanya Bisa dipilih Jika Ada Invoice") + if refund_type in ['barang_kosong', 'barang_kosong_sebagian'] and so_ids: + sale_orders = self.env['sale.order'].browse(so_ids) + zero_delivery_lines = sale_orders.mapped('order_line').filtered(lambda l: l.qty_delivered == 0) + if not zero_delivery_lines: + raise UserError("❌ Tidak ada barang yang Tidak Terikirim di Sales Order yang dipilih.") + if not so_ids and refund_type != 'lainnya': raise ValidationError("Jika tidak ada Sales Order yang dipilih, maka Tipe Refund hanya boleh 'Lainnya'.") @@ -180,6 +185,10 @@ class RefundSaleOrder(models.Model): ongkir = vals.get('ongkir', 0.0) pengurangan = total_invoice + ongkir + if refund_type == 'barang_kosong_sebagian' and so_ids: + sale_orders = self.env['sale.order'].browse(so_ids) + vals['uang_masuk'] = sum(sale_orders.mapped('amount_total')) + if uang_masuk > pengurangan: vals['amount_refund'] = uang_masuk - pengurangan else: @@ -229,8 +238,16 @@ class RefundSaleOrder(models.Model): refund_type = vals.get('refund_type', rec.refund_type) + if refund_type in ['barang_kosong', 'barang_kosong_sebagian'] and sale_orders: + zero_delivery_lines = sale_orders.mapped('order_line').filtered(lambda l: l.qty_delivered == 0) + if not zero_delivery_lines: + raise UserError("❌ Tidak ada barang yang Tidak Terikirim di Sales Order yang dipilih.") + if not so_ids and refund_type != 'lainnya': raise ValidationError("Jika tidak ada Sales Order yang dipilih, maka Tipe Refund hanya boleh 'Lainnya'.") + + if refund_type == 'barang_kosong_sebagian' and sale_orders: + vals['uang_masuk'] = sum(sale_orders.mapped('amount_total')) invoice_ids = vals.get('invoice_ids', False) @@ -248,7 +265,7 @@ class RefundSaleOrder(models.Model): if invoice_ids and vals.get('refund_type', rec.refund_type) not in ['uang', 'barang_kosong_sebagian', 'barang_kosong', 'retur_half']: raise UserError("Refund type Hanya Bisa Lebih Bayar, Barang Kosong Sebagian, atau Retur Sebagian jika ada invoice") - if not invoice_ids and vals.get('refund_type', rec.refund_type) in ['uang', 'barang_kosong_sebagian', 'barang_kosong', 'retur_half']: + if not invoice_ids and vals.get('refund_type', rec.refund_type) in ['uang', 'barang_kosong_sebagian', 'retur_half']: raise UserError("Refund type Lebih Bayar, Barang Kosong Sebagian, atau Retur Sebagian Hanya Bisa dipilih Jika Ada Invoice") if refund_type in ['retur', 'retur_half'] and so_ids: @@ -358,6 +375,9 @@ class RefundSaleOrder(models.Model): self.line_ids = line_vals + if self.refund_type == 'barang_kosong_sebagian' and self.sale_order_ids: + self.uang_masuk = sum(self.sale_order_ids.mapped('amount_total')) + sum(self.sale_order_ids.mapped('delivery_amt')) + elif self.refund_type in ['retur', 'retur_half'] and self.sale_order_ids: line_vals = [] StockPicking = self.env['stock.picking'] @@ -586,8 +606,8 @@ class RefundSaleOrder(models.Model): }) amount = refund.amount_refund - - second_account_id = 450 if has_invoice else 668 + # 450 Penerimaan Belum Teridentifikasi, 668 Penerimaan Belum Alokasi + second_account_id = 450 if refund.refund_type not in ['barang_kosong', 'barang_kosong_sebagian'] else 668 debit_line = { 'move_id': account_move.id, diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 4d0b1d7b..46dad6ff 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -3111,6 +3111,7 @@ class SaleOrder(models.Model): self.ensure_one() invoice_ids = self.invoice_ids.filtered(lambda inv: inv.state != 'cancel') + total_so = sum(self.mapped('amount_total')) return { 'name': 'Refund Sale Order', @@ -3121,7 +3122,7 @@ class SaleOrder(models.Model): 'context': { 'default_sale_order_ids': [(6, 0, [self.id])], 'default_invoice_ids': [(6, 0, invoice_ids.ids)], - 'default_uang_masuk': sum(invoice_ids.mapped('amount_total')) + (self.delivery_amt or 0.0) + 1000, + 'default_uang_masuk': total_so, 'default_ongkir': self.delivery_amt or 0.0, 'default_bank': '', # bisa isi default bank kalau mau 'default_account_name': '', @@ -3150,6 +3151,7 @@ class SaleOrder(models.Model): invoice_ids = self.mapped('invoice_ids').filtered(lambda inv: inv.state != 'cancel') delivery_total = sum(self.mapped('delivery_amt')) total_invoice = sum(invoice_ids.mapped('amount_total_signed')) + total_so = sum(self.mapped('amount_total')) return { 'type': 'ir.actions.act_window', @@ -3160,7 +3162,7 @@ class SaleOrder(models.Model): 'context': { 'default_sale_order_ids': [(6, 0, self.ids)], 'default_invoice_ids': [(6, 0, invoice_ids.ids)], - 'default_uang_masuk': total_invoice + delivery_total + 1000, + 'default_uang_masuk': total_so, 'default_ongkir': delivery_total, 'default_bank': '', 'default_account_name': '', diff --git a/indoteknik_custom/views/refund_sale_order.xml b/indoteknik_custom/views/refund_sale_order.xml index 4f791722..0c4eaa56 100644 --- a/indoteknik_custom/views/refund_sale_order.xml +++ b/indoteknik_custom/views/refund_sale_order.xml @@ -66,7 +66,7 @@ string="Journal Refund" type="object" class="oe_highlight" - attrs="{'invisible': ['|', ('status', 'not in', ['pengajuan3','refund']), ('journal_refund_state', '=', 'posted')]}"/> + attrs="{'invisible': [('journal_refund_state', '=', 'posted')]}"/> - - + + diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index 987303ba..08dcfbb7 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -40,7 +40,7 @@ type="object" string="Refund" class="btn-primary" - attrs="{'invisible': ['|', ('state', 'not in', ['sale', 'done']), ('has_refund', '=', True)]}" /> + attrs="{'invisible': [('has_refund', '=', 'True')]}" />
-- cgit v1.2.3 From 747075fb85372666b89d5ffd07a43664ecf169e1 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 4 Aug 2025 14:41:27 +0700 Subject: Fix problem --- indoteknik_custom/models/refund_sale_order.py | 20 ++++++++++++-------- indoteknik_custom/views/ir_sequence.xml | 2 +- indoteknik_custom/views/refund_sale_order.xml | 10 +++++----- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/indoteknik_custom/models/refund_sale_order.py b/indoteknik_custom/models/refund_sale_order.py index 65e93ba4..077809e9 100644 --- a/indoteknik_custom/models/refund_sale_order.py +++ b/indoteknik_custom/models/refund_sale_order.py @@ -181,14 +181,17 @@ class RefundSaleOrder(models.Model): raise ValidationError(f"SO {', '.join(so.mapped('name'))} belum memiliki invoice untuk Retur Sebagian.") total_invoice = sum(self.env['account.move'].browse(invoice_ids).mapped('amount_total_signed')) if invoice_ids else 0.0 - uang_masuk = vals.get('uang_masuk', 0.0) ongkir = vals.get('ongkir', 0.0) + vals['total_invoice'] = total_invoice pengurangan = total_invoice + ongkir if refund_type == 'barang_kosong_sebagian' and so_ids: sale_orders = self.env['sale.order'].browse(so_ids) vals['uang_masuk'] = sum(sale_orders.mapped('amount_total')) + + uang_masuk = vals.get('uang_masuk', 0.0) + if uang_masuk > pengurangan: vals['amount_refund'] = uang_masuk - pengurangan else: @@ -284,6 +287,7 @@ class RefundSaleOrder(models.Model): if any(field in vals for field in ['uang_masuk', 'invoice_ids', 'ongkir', 'sale_order_ids']): total_invoice = sum(self.env['account.move'].browse(invoice_ids).mapped('amount_total_signed')) + vals['total_invoice'] = total_invoice uang_masuk = vals.get('uang_masuk', rec.uang_masuk) ongkir = vals.get('ongkir', rec.ongkir) @@ -296,10 +300,10 @@ class RefundSaleOrder(models.Model): return super().write(vals) - @api.depends('status_payment') + @api.depends('status_payment', 'status') def _compute_is_locked(self): for rec in self: - rec.is_locked = rec.status_payment in ['done', 'reject'] + rec.is_locked = rec.status_payment in ['done', 'reject'] or rec.status in ['pengajuan3', 'refund', 'reject'] @api.depends('sale_order_ids.name', 'invoice_ids.name') def _compute_order_invoice_names(self): @@ -506,19 +510,19 @@ class RefundSaleOrder(models.Model): if not rec.status or rec.status == 'draft': rec.status = 'pengajuan1' - elif rec.status == 'pengajuan1' and self.env.user.id == 19: + elif rec.status == 'pengajuan1': rec.status = 'pengajuan2' rec.approved_by = f"{rec.approved_by}, {user_name}" if rec.approved_by else user_name rec.date_approved_sales = now rec.position_sales = 'Sales Manager' - elif rec.status == 'pengajuan2' and self.env.user.id == 688: + elif rec.status == 'pengajuan2': rec.status = 'pengajuan3' rec.approved_by = f"{rec.approved_by}, {user_name}" if rec.approved_by else user_name rec.date_approved_ar = now rec.position_ar = 'AR' - elif rec.status == 'pengajuan3' and self.env.user.id == 7: + elif rec.status == 'pengajuan3': rec.status = 'refund' rec.approved_by = f"{rec.approved_by}, {user_name}" if rec.approved_by else user_name rec.date_approved_pimpinan = now @@ -532,7 +536,7 @@ class RefundSaleOrder(models.Model): is_fat = self.env.user.has_group('indoteknik_custom.group_role_fat') allowed_user_ids = [19, 688, 7] for rec in self: - if self.user.id not in allowed_user_ids and not is_fat: + if self.env.uid not in allowed_user_ids and not is_fat: raise UserError("❌ Hanya user yang bersangkutan atau Finance (FAT) yang bisa melakukan penolakan.") if rec.status not in ['refund', 'reject']: rec.status = 'reject' @@ -548,7 +552,7 @@ class RefundSaleOrder(models.Model): is_fat = self.env.user.has_group('indoteknik_custom.group_role_fat') for rec in self: if not is_fat: - raise UserError("Hanya Finance yang dapat mengkonfirmasi refund.") + raise UserError("Hanya Finance yang dapat mengkonfirmasi pembayaran refund.") if rec.status_payment == 'pending': rec.status_payment = 'done' rec.refund_date = fields.Date.context_today(self) diff --git a/indoteknik_custom/views/ir_sequence.xml b/indoteknik_custom/views/ir_sequence.xml index 4915e4c5..94c2cd07 100644 --- a/indoteknik_custom/views/ir_sequence.xml +++ b/indoteknik_custom/views/ir_sequence.xml @@ -220,7 +220,7 @@ - Refund Sale Order + Refund Sales Order refund.sale.order RC/%(year)s/%(month)s/ 4 diff --git a/indoteknik_custom/views/refund_sale_order.xml b/indoteknik_custom/views/refund_sale_order.xml index e35e76b3..27c5feec 100644 --- a/indoteknik_custom/views/refund_sale_order.xml +++ b/indoteknik_custom/views/refund_sale_order.xml @@ -56,7 +56,7 @@
@@ -163,8 +163,8 @@ - - + + -- cgit v1.2.3 From bbc454fd6e13d12e9674769a555264f2c2343b5b Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Wed, 20 Aug 2025 09:06:33 +0700 Subject: refund system sisa uang muka --- indoteknik_custom/models/refund_sale_order.py | 226 +++++++++++++++++++++----- indoteknik_custom/models/sale_order.py | 80 +++++++-- indoteknik_custom/views/refund_sale_order.xml | 40 ++++- indoteknik_custom/views/sale_order.xml | 4 +- 4 files changed, 292 insertions(+), 58 deletions(-) diff --git a/indoteknik_custom/models/refund_sale_order.py b/indoteknik_custom/models/refund_sale_order.py index 077809e9..2dc72f0f 100644 --- a/indoteknik_custom/models/refund_sale_order.py +++ b/indoteknik_custom/models/refund_sale_order.py @@ -17,13 +17,17 @@ class RefundSaleOrder(models.Model): note_refund = fields.Text(string='Note Refund') sale_order_ids = fields.Many2many('sale.order', string='Sales Order Numbers') uang_masuk = fields.Float(string='Uang Masuk', required=True) - total_invoice = fields.Float(string='Total Invoice') + total_invoice = fields.Float(string='Total Order') ongkir = fields.Float(string='Ongkir', required=True, default=0.0) amount_refund = fields.Float(string='Total Refund', required=True) amount_refund_text = fields.Char(string='Total Refund Text', compute='_compute_refund_text') user_ids = fields.Many2many('res.users', string='Salespersons', compute='_compute_user_ids', domain=[('active', 'in', [True, False])]) create_uid = fields.Many2one('res.users', string='Created By', readonly=True) created_date = fields.Date(string='Tanggal Request Refund', readonly=True) + sale_order_count = fields.Integer( + string="Sale Order Count", + compute="_compute_sale_order_count", + ) status = fields.Selection([ ('draft', 'Draft'), ('pengajuan1', 'Approval Sales Manager'), @@ -55,7 +59,7 @@ class RefundSaleOrder(models.Model): ('uang', 'Refund Lebih Bayar'), ('retur_half', 'Refund Retur Sebagian'), ('retur', 'Refund Retur Full'), - ('lainnya', 'Lainnya') + ('salah_transfer', 'Salah Transfer') ], string='Refund Type', required=True) refund_type_display = fields.Char(string="Refund Type Label", compute="_compute_refund_type_display") @@ -89,7 +93,7 @@ class RefundSaleOrder(models.Model): bukti_refund_type = fields.Selection([ ('pdf', 'PDF'), ('image', 'Image'), - ], string="Attachment Type", default='image') + ], string="Attachment Type") bukti_uang_masuk_image = fields.Binary(string="Upload Bukti Uang Masuk") bukti_transfer_refund_image = fields.Binary(string="Upload Bukti Transfer Refund") bukti_uang_masuk_pdf = fields.Binary(string="Upload Bukti Uang Masuk") @@ -107,22 +111,44 @@ class RefundSaleOrder(models.Model): is_locked = fields.Boolean(string="Locked", compute="_compute_is_locked") sale_order_names_jasper = fields.Char(string='Sales Order List', compute='_compute_order_invoice_names') invoice_names_jasper = fields.Char(string='Invoice List', compute='_compute_order_invoice_names') - - - - @api.depends('refund_type') - def _compute_refund_type_display(self): - for rec in self: - rec.refund_type_display = dict(self.fields_get(allfields=['refund_type'])['refund_type']['selection']).get(rec.refund_type, '') + so_order_line_ids = fields.Many2many( + "sale.order.line", string="SO Order Lines", compute="_compute_so_order_lines", store=False + ) + currency_id = fields.Many2one( + "res.currency", string="Currency", + default=lambda self: self.env.company.currency_id, required=True + ) + + amount_untaxed = fields.Monetary( + string="Untaxed Amount", compute="_compute_amount_from_so", + ) + amount_tax = fields.Monetary( + string="Taxes", compute="_compute_amount_from_so", + ) + amount_total = fields.Monetary( + string="Total", compute="_compute_amount_from_so", + ) + total_margin = fields.Monetary( + string="Total Margin", compute="_compute_amount_from_so", + ) + grand_total = fields.Monetary( + string="Grand Total", compute="_compute_amount_from_so", + ) + delivery_amt = fields.Monetary( + string="Delivery Amount", help="Ongkos kirim yang Dibayarkan Customer", default=0.0, compute="_compute_amount_from_so", + ) + remaining_refundable = fields.Float( + string="Sisa Uang Masuk", + help="Sisa uang masuk yang masih bisa direfund (hanya berlaku untuk 1 SO)", + ) - @api.model def create(self, vals): allowed_user_ids = [23, 19, 688, 7] if not ( self.env.user.has_group('indoteknik_custom.group_role_sales') or self.env.user.has_group('indoteknik_custom.group_role_fat') or - self.env.user.id not in allowed_user_ids + self.env.user.id in allowed_user_ids ): raise UserError("❌ Hanya Sales dan Finance yang boleh membuat refund.") @@ -158,9 +184,20 @@ class RefundSaleOrder(models.Model): if refund_type in ['barang_kosong', 'barang_kosong_sebagian'] and so_ids: sale_orders = self.env['sale.order'].browse(so_ids) - zero_delivery_lines = sale_orders.mapped('order_line').filtered(lambda l: l.qty_delivered == 0) - if not zero_delivery_lines: - raise UserError("❌ Tidak ada barang yang Tidak Terikirim di Sales Order yang dipilih.") + + if refund_type == 'barang_kosong': + zero_delivery_lines = sale_orders.mapped('order_line').filtered( + lambda l: l.qty_delivered == 0 and l.product_uom_qty > 0 + ) + if not zero_delivery_lines: + raise UserError("❌ Tidak ada barang kosong di SO yang terpilih.") + + elif refund_type == 'barang_kosong_sebagian': + partial_delivery_lines = sale_orders.mapped('order_line').filtered( + lambda l: l.qty_delivered > 0 and l.product_uom_qty > l.qty_delivered + ) + if not partial_delivery_lines: + raise UserError("❌ Tidak ada barang yang tidak Terkirim/Kosong di SO yang dipilih.") if not so_ids and refund_type != 'lainnya': @@ -180,22 +217,40 @@ class RefundSaleOrder(models.Model): if refund_type == 'retur_half' and not invoice_ids: raise ValidationError(f"SO {', '.join(so.mapped('name'))} belum memiliki invoice untuk Retur Sebagian.") - total_invoice = sum(self.env['account.move'].browse(invoice_ids).mapped('amount_total_signed')) if invoice_ids else 0.0 - ongkir = vals.get('ongkir', 0.0) - vals['total_invoice'] = total_invoice - pengurangan = total_invoice + ongkir - if refund_type == 'barang_kosong_sebagian' and so_ids: sale_orders = self.env['sale.order'].browse(so_ids) vals['uang_masuk'] = sum(sale_orders.mapped('amount_total')) - - uang_masuk = vals.get('uang_masuk', 0.0) + moves = self.env['account.move'].search([ + ('sale_id', 'in', so_ids), + ('journal_id', '=', 11), + ('state', '=', 'posted'), + ]) + total_uang_muka = sum(moves.mapped('amount_total_signed')) - if uang_masuk > pengurangan: - vals['amount_refund'] = uang_masuk - pengurangan - else: - raise UserError("Uang masuk harus lebih besar dari total invoice + ongkir untuk melakukan refund") + uang_masuk = total_uang_muka if moves else sum(self.env['sale.order'].browse(so_ids).mapped('gross_amount')) + vals['uang_masuk'] = uang_masuk + ongkir = vals.get('ongkir', 0.0) + total_invoice = sum(self.env['account.move'].browse(invoice_ids).mapped('amount_total_signed')) if invoice_ids else 0.0 + + vals['total_invoice'] = total_invoice + amount_refund = vals.get('amount_refund', 0.0) + if amount_refund <= 0.00: + raise ValidationError('Total Refund harus lebih dari 0 jika ingin mengajukan refund') + + if so_ids and len(so_ids) > 1: + existing_refund = self.search([('sale_order_ids', 'in', so_ids)], limit=1) + if existing_refund: + raise UserError("❌ Refund multi SO hanya bisa 1 kali.") + vals['remaining_refundable'] = 0.0 + elif so_ids and len(so_ids) == 1: + so = self.env['sale.order'].browse(so_ids[0]) + existing_refunds = self.search([('sale_order_ids', 'in', so_ids)]) + total_refunded = sum(existing_refunds.mapped('amount_refund')) + amount_refund + remaining = uang_masuk - total_refunded + if remaining < 0: + raise ValidationError("❌ Tidak ada sisa transaksi untuk di-refund di SO ini. Semua dana sudah dikembalikan.") + vals['remaining_refundable'] = remaining return super().create(vals) @@ -285,20 +340,41 @@ class RefundSaleOrder(models.Model): if refund_type == 'retur_half' and not invoice_ids: raise ValidationError(f"SO {', '.join(so.mapped('name'))} belum memiliki invoice untuk retur sebagian.") - if any(field in vals for field in ['uang_masuk', 'invoice_ids', 'ongkir', 'sale_order_ids']): + if any(field in vals for field in ['uang_masuk', 'invoice_ids', 'ongkir', 'sale_order_ids', 'amount_refund']): total_invoice = sum(self.env['account.move'].browse(invoice_ids).mapped('amount_total_signed')) vals['total_invoice'] = total_invoice - uang_masuk = vals.get('uang_masuk', rec.uang_masuk) - ongkir = vals.get('ongkir', rec.ongkir) + uang_masuk = rec.uang_masuk + amount_refund = vals.get('amount_refund', rec.amount_refund) + + if amount_refund <= 0: + raise ValidationError("Total Refund harus lebih dari 0.") + + existing_refunds = self.search([ + ('sale_order_ids', 'in', so_ids), + ('id', '!=', rec.id) + ]) + total_refunded = sum(existing_refunds.mapped('amount_refund')) + amount_refund + remaining = uang_masuk - total_refunded - if uang_masuk <= (total_invoice + ongkir): - raise UserError("Uang masuk harus lebih besar dari total invoice + ongkir") - vals['amount_refund'] = uang_masuk - (total_invoice + ongkir) + if remaining < 0: + raise ValidationError("❌ Dana uang masuk telah sepenuhnya di refund tidak bisa Mengubah Nominal Refund") - if vals.get('status') == 'refund' and not vals.get('refund_date'): - vals['refund_date'] = fields.Date.context_today(self) + vals['remaining_refundable'] = remaining return super().write(vals) + + @api.onchange('ongkir', 'amount_refund') + def _onchange_refund_fields(self): + for rec in self: + uang_masuk = rec.uang_masuk or 0.0 + ongkir = rec.ongkir or 0.0 + refund_input = rec.amount_refund or 0.0 + + total_refund_with_ongkir = refund_input + ongkir + if total_refund_with_ongkir > uang_masuk: + raise UserError("❌ Refund + Ongkir tidak boleh melebihi Uang Masuk.") + remaining = uang_masuk - refund_input + rec.remaining_refundable = remaining @api.depends('status_payment', 'status') def _compute_is_locked(self): @@ -362,6 +438,37 @@ class RefundSaleOrder(models.Model): if self.sale_order_ids: self.partner_id = self.sale_order_ids[0].partner_id + @api.constrains('sale_order_ids') + def _check_sale_orders_payment(self): + """ Validasi SO harus punya uang masuk (Journal Uang Muka / Midtrans) """ + for rec in self: + invalid_orders = [] + total_uang_masuk = 0.0 + + for so in rec.sale_order_ids: + # cari journal uang muka + moves = self.env['account.move'].search([ + ('sale_id', '=', so.id), + ('journal_id', '=', 11), # Journal Uang Muka + ('state', '=', 'posted'), + ]) + + if not moves and so.payment_status != 'settlement': + invalid_orders.append(so.name) + + if moves: + total_uang_muka = sum(moves.mapped('amount_total_signed')) or 0.0 + total_uang_masuk += total_uang_muka + else: + # fallback Midtrans gross_amount + total_uang_masuk += so.gross_amount or 0.0 + + if invalid_orders: + raise ValidationError( + f"Tidak dapat membuat refund untuk SO {', '.join(invalid_orders)} " + "karena tidak memiliki Record Uang Masuk (Journal Uang Muka/Midtrans).\n" + "Pastikan semua SO yang dipilih sudah memiliki Record pembayaran yang valid." + ) @api.onchange('refund_type') def _onchange_refund_type(self): @@ -374,14 +481,12 @@ class RefundSaleOrder(models.Model): line_vals.append((0, 0, { 'product_id': line.product_id.id, 'quantity': line.product_uom_qty, + 'product_from': line.order_id.name, 'reason': '', })) self.line_ids = line_vals - if self.refund_type == 'barang_kosong_sebagian' and self.sale_order_ids: - self.uang_masuk = sum(self.sale_order_ids.mapped('amount_total')) + sum(self.sale_order_ids.mapped('delivery_amt')) - elif self.refund_type in ['retur', 'retur_half'] and self.sale_order_ids: line_vals = [] StockPicking = self.env['stock.picking'] @@ -476,6 +581,7 @@ class RefundSaleOrder(models.Model): line_vals.append((0, 0, { 'product_id': line.product_id.id, 'quantity': line.product_uom_qty, + 'product_from': line.order_id.name, 'reason': '', })) res['line_ids'] = line_vals @@ -671,7 +777,52 @@ class RefundSaleOrder(models.Model): } + @api.depends( + "sale_order_ids", + "sale_order_ids.order_line.price_subtotal", + "sale_order_ids.order_line.price_tax", + "sale_order_ids.order_line.price_total", + "sale_order_ids.order_line.purchase_price", + "sale_order_ids.order_line.product_uom_qty", + "sale_order_ids.delivery_amt", + "sale_order_ids.shipping_cost_covered", + ) + def _compute_amount_from_so(self): + for rec in self: + untaxed = tax = total_margin = delivery = 0.0 + for so in rec.sale_order_ids: + if so.shipping_cost_covered == 'customer': + delivery += so.delivery_amt or 0.0 + for line in so.order_line: + untaxed += line.price_subtotal + tax += line.price_tax + cost = line.purchase_price * line.product_uom_qty + margin = line.price_subtotal - cost + total_margin += margin + rec.amount_untaxed = untaxed + rec.amount_tax = tax + rec.amount_total = untaxed + tax + rec.total_margin = total_margin + rec.delivery_amt = delivery + rec.grand_total = rec.amount_total + rec.delivery_amt + + + @api.depends("sale_order_ids", "sale_order_ids.order_line") + def _compute_so_order_lines(self): + for rec in self: + rec.so_order_line_ids = rec.sale_order_ids.mapped("order_line") + + + + @api.depends('refund_type') + def _compute_refund_type_display(self): + for rec in self: + rec.refund_type_display = dict(self.fields_get(allfields=['refund_type'])['refund_type']['selection']).get(rec.refund_type, '') + + def _compute_sale_order_count(self): + for rec in self: + rec.sale_order_count = len(rec.sale_order_ids) class RefundSaleOrderLine(models.Model): _name = 'refund.sale.order.line' @@ -682,3 +833,4 @@ class RefundSaleOrderLine(models.Model): product_id = fields.Many2one('product.product', string='Product') quantity = fields.Float(string='Qty') reason = fields.Char(string='Reason') + product_from = fields.Char(string='Product Reference') diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index aa534d0c..2acee890 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -358,7 +358,6 @@ class SaleOrder(models.Model): help="Tanggal pertama kali barang berhasil di-reservasi pada DO (BU/PICK/) yang berstatus Siap Dikirim." ) refund_ids = fields.Many2many('refund.sale.order', compute='_compute_refund_ids', string='Refunds') - has_refund = fields.Boolean(string='Has Refund', compute='_compute_has_refund') refund_count = fields.Integer(string='Refund Count', compute='_compute_refund_count') advance_payment_move_id = fields.Many2one( 'account.move', @@ -3197,9 +3196,35 @@ class SaleOrder(models.Model): def button_refund(self): self.ensure_one() + moves = self.env['account.move'].search([ + ('sale_id', '=', self.id), + ('journal_id', '=', 11), + ('state', '=', 'posted'), + ]) + + # Default 0 + total_uang_muka = 0.0 + has_moves = bool(moves) + has_settlement = self.payment_status == 'settlement' + + if has_moves and has_settlement: + total_uang_muka = sum(moves.mapped('amount_total_signed')) + self.gross_amount + elif has_moves: + total_uang_muka = sum(moves.mapped('amount_total_signed')) + elif has_settlement: + total_uang_muka = self.gross_amount + else: + raise UserError( + "Tidak bisa melakukan refund karena SO tidak memiliki Record Uang Masuk " + "(Journal Uang Muka/Midtrans Payment)." + ) invoice_ids = self.invoice_ids.filtered(lambda inv: inv.state != 'cancel') - total_so = sum(self.mapped('amount_total')) + total_refunded = sum(self.refund_ids.mapped('amount_refund')) or 0.0 + sisa_uang_muka = total_uang_muka - total_refunded + + if sisa_uang_muka <= 0: + raise UserError("❌ Tidak ada sisa transaksi untuk di-refund. Semua dana sudah dikembalikan.") return { 'name': 'Refund Sale Order', @@ -3210,9 +3235,9 @@ class SaleOrder(models.Model): 'context': { 'default_sale_order_ids': [(6, 0, [self.id])], 'default_invoice_ids': [(6, 0, invoice_ids.ids)], - 'default_uang_masuk': total_so, + 'default_uang_masuk': sisa_uang_muka, 'default_ongkir': self.delivery_amt or 0.0, - 'default_bank': '', # bisa isi default bank kalau mau + 'default_bank': '', 'default_account_name': '', 'default_account_no': '', 'default_refund_type': '', @@ -3231,15 +3256,43 @@ class SaleOrder(models.Model): if len(invoice_status_set) > 1: raise UserError("Tidak dapat membuat refund untuk SO dengan status invoice berbeda. Harus memiliki status invoice yang sama.") - already_refunded = self.filtered(lambda so: so.has_refund) - if already_refunded: - so_names = ', '.join(already_refunded.mapped('name')) - raise UserError(f"❌ Tidak bisa refund ulang. {so_names} sudah melakukan refund.") + refunded_orders = self.filtered(lambda so: self.env['refund.sale.order'].search([('sale_order_ids', 'in', so.id)], limit=1)) + if refunded_orders: + raise ValidationError( + f"SO {', '.join(refunded_orders.mapped('name'))} sudah pernah di-refund dan tidak bisa ikut dalam refund Multi SO." + ) + + total_uang_masuk = 0.0 + invalid_orders=[] + for order in self: + moves = self.env['account.move'].search([ + ('sale_id', '=', order.id), + ('journal_id', '=', 11), + ('state', '=', 'posted'), + ]) + + total_uang_muka = 0.0 + + if moves and order.payment_status == 'settlement': + total_uang_muka = order.gross_amount + sum(moves.mapped('amount_total_signed')) or 0.0 + elif moves: + total_uang_muka = sum(moves.mapped('amount_total_signed')) or 0.0 + elif order.payment_status == 'settlement': + total_uang_muka = order.gross_amount + else: + invalid_orders.append(order.name) + + total_uang_masuk += total_uang_muka + + if invalid_orders: + raise ValidationError( + f"Tidak dapat membuat refund untuk SO {', '.join(invalid_orders)} karena tidak memiliki Record Uang Masuk (Journal Uang Muka/Midtrans).\n" + "Pastikan semua SO yang dipilih sudah memiliki Record pembayaran yang valid." + ) + invoice_ids = self.mapped('invoice_ids').filtered(lambda inv: inv.state != 'cancel') delivery_total = sum(self.mapped('delivery_amt')) - total_invoice = sum(invoice_ids.mapped('amount_total_signed')) - total_so = sum(self.mapped('amount_total')) return { 'type': 'ir.actions.act_window', @@ -3250,7 +3303,7 @@ class SaleOrder(models.Model): 'context': { 'default_sale_order_ids': [(6, 0, self.ids)], 'default_invoice_ids': [(6, 0, invoice_ids.ids)], - 'default_uang_masuk': total_so, + 'default_uang_masuk': total_uang_masuk, 'default_ongkir': delivery_total, 'default_bank': '', 'default_account_name': '', @@ -3259,11 +3312,6 @@ class SaleOrder(models.Model): } } - @api.depends('refund_ids') - def _compute_has_refund(self): - for so in self: - so.has_refund = bool(so.refund_ids) - def action_view_related_refunds(self): self.ensure_one() return { diff --git a/indoteknik_custom/views/refund_sale_order.xml b/indoteknik_custom/views/refund_sale_order.xml index 27c5feec..dd47c2ab 100644 --- a/indoteknik_custom/views/refund_sale_order.xml +++ b/indoteknik_custom/views/refund_sale_order.xml @@ -14,6 +14,7 @@ + - + + + @@ -133,7 +136,8 @@ - + + @@ -168,6 +172,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index 1d51fd69..8f8e4288 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -39,8 +39,7 @@ + + - + -- cgit v1.2.3 From 3139c592dd1f74b7c6a6c4917419628895296406 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 29 Aug 2025 14:23:18 +0700 Subject: refund abis testing aman --- indoteknik_custom/models/refund_sale_order.py | 306 ++++++++++++++++++++------ indoteknik_custom/models/sale_order.py | 36 ++- indoteknik_custom/models/tukar_guling.py | 61 ++--- indoteknik_custom/views/refund_sale_order.xml | 76 ++++++- 4 files changed, 374 insertions(+), 105 deletions(-) diff --git a/indoteknik_custom/models/refund_sale_order.py b/indoteknik_custom/models/refund_sale_order.py index 0b4d2893..086c7a81 100644 --- a/indoteknik_custom/models/refund_sale_order.py +++ b/indoteknik_custom/models/refund_sale_order.py @@ -10,7 +10,7 @@ from lxml import etree class RefundSaleOrder(models.Model): _name = 'refund.sale.order' _description = 'Refund Sales Order' - _inherit = ['mail.thread'] + _inherit = ['mail.thread', 'mail.activity.mixin'] _rec_name = 'name' name = fields.Char(string='Refund Number', default='New', copy=False, readonly=True) @@ -49,6 +49,7 @@ class RefundSaleOrder(models.Model): bank = fields.Char(string='Bank', required=True) account_name = fields.Char(string='Account Name', required=True) account_no = fields.Char(string='Account No', required=True) + kcp = fields.Char(string='Alamat KCP') finance_note = fields.Text(string='Finance Note') invoice_names = fields.Html(string="Group Invoice Number", compute="_compute_invoice_names") so_names = fields.Html(string="Group SO Number", compute="_compute_so_names") @@ -63,8 +64,19 @@ class RefundSaleOrder(models.Model): ], string='Refund Type', required=True) tukar_guling_ids = fields.One2many( - 'tukar.guling', 'refund_id', - string="Tukar Guling" + 'tukar.guling', 'refund_id', string="Pengajuan Return SO", + ) + + picking_ids = fields.Many2many( + 'stock.picking', + string="Pickings", + compute="_compute_picking_ids", + ) + + transfer_move_id = fields.Many2one( + 'account.move', + string="Journal Payment", + help="Pilih transaksi salah transfer dari jurnal Uang Muka (journal_id=11) yang tidak terkait SO." ) tukar_guling_count = fields.Integer( @@ -72,6 +84,11 @@ class RefundSaleOrder(models.Model): compute="_compute_tukar_guling_count" ) + has_picking = fields.Boolean( + string="Has Picking", + compute="_compute_has_picking", + ) + refund_type_display = fields.Char(string="Refund Type Label", compute="_compute_refund_type_display") line_ids = fields.One2many('refund.sale.order.line', 'refund_id', string='Refund Lines') @@ -152,6 +169,34 @@ class RefundSaleOrder(models.Model): help="Sisa uang masuk yang masih bisa direfund (hanya berlaku untuk 1 SO)", ) show_return_alert = fields.Boolean(compute="_compute_show_return_alert") + show_approval_alert = fields.Boolean(compute="_compute_show_approval_alert") + + + @api.onchange('refund_type', 'partner_id') + def _onchange_refund_type_partner(self): + if self.refund_type == 'salah_transfer' and self.partner_id: + return { + 'domain': { + 'transfer_move_id': [ + ('journal_id', '=', 11), + ('line_ids.partner_id', '=', self.partner_id.id), + ('state', '=', 'posted'), + ('sale_id', '=', False), + ] + } + } + else: + return { + 'domain': {'transfer_move_id': [('id', '=', 0)]} + } + + @api.onchange('transfer_move_id') + def _onchange_transfer_move_id(self): + """Set nilai uang_masuk dari move yang dipilih""" + if self.transfer_move_id and self.refund_type == 'salah_transfer': + self.uang_masuk = self.transfer_move_id.amount_total_signed + elif self.refund_type != 'salah_transfer' and not self.sale_order_ids: + self.uang_masuk = 0.0 @api.model def create(self, vals): @@ -176,6 +221,9 @@ class RefundSaleOrder(models.Model): so_ids = so_cmd[0][2] if so_cmd and so_cmd[0][0] == 6 else [] if so_ids: sale_orders = self.env['sale.order'].browse(so_ids) + partner = sale_orders.mapped('partner_id.id') + if len(partner) > 1: + raise UserError("❌ Tidak dapat membuat refund untuk Multi SO dengan Customer berbeda. Harus memiliki Customer yang sama.") vals['partner_id'] = sale_orders[0].partner_id.id invoices = sale_orders.mapped('invoice_ids').filtered( @@ -188,10 +236,10 @@ class RefundSaleOrder(models.Model): refund_type = vals.get('refund_type') invoice_ids_data = vals.get('invoice_ids', []) invoice_ids = invoice_ids_data[0][2] if invoice_ids_data and invoice_ids_data[0][0] == 6 else [] - if invoice_ids and refund_type and refund_type not in ['uang', 'barang_kosong_sebagian', 'barang_kosong', 'retur_half', 'retur']: + if invoice_ids and refund_type and refund_type not in ['uang', 'barang_kosong_sebagian', 'barang_kosong', 'retur_half']: raise UserError("Refund type Hanya Bisa Lebih Bayar, Barang Kosong Sebagian, atau Retur jika ada invoice") - if not invoice_ids and refund_type and refund_type in ['uang', 'barang_kosong_sebagian']: + if not invoice_ids and refund_type and refund_type in ['uang', 'barang_kosong_sebagian', 'retur_half']: raise UserError("Refund type Lebih Bayar dan Barang Kosong Sebagian Hanya Bisa dipilih Jika Ada Invoice") if refund_type in ['barang_kosong', 'barang_kosong_sebagian'] and so_ids: @@ -206,7 +254,7 @@ class RefundSaleOrder(models.Model): elif refund_type == 'barang_kosong_sebagian': partial_delivery_lines = sale_orders.mapped('order_line').filtered( - lambda l: l.qty_delivered > 0 and l.product_uom_qty > l.qty_delivered + lambda l: l.qty_delivered >= 0 and l.product_uom_qty > l.qty_delivered ) if not partial_delivery_lines: raise UserError("❌ Tidak ada barang yang tidak Terkirim/Kosong di SO yang dipilih.") @@ -215,21 +263,37 @@ class RefundSaleOrder(models.Model): if not so_ids and refund_type != 'salah_transfer': raise ValidationError("Jika tidak ada Sales Order yang dipilih, maka Tipe Refund hanya boleh 'Salah Transfer'.") - if refund_type == 'barang_kosong_sebagian' and so_ids: - sale_orders = self.env['sale.order'].browse(so_ids) - vals['uang_masuk'] = sum(sale_orders.mapped('amount_total')) - - moves = self.env['account.move'].search([ - ('sale_id', 'in', so_ids), - ('journal_id', '=', 11), - ('state', '=', 'posted'), + if refund_type == 'salah_transfer' and vals.get('transfer_move_id'): + move = self.env['account.move'].browse(vals['transfer_move_id']) + if move: + vals['uang_masuk'] = move.amount_total_signed + vals['remaining_refundable'] = 0 + else: + # ==== perhitungan normal ==== + moves = self.env['account.move'].search([ + ('sale_id', 'in', so_ids), + ('journal_id', '=', 11), + ('state', '=', 'posted'), ]) - total_uang_muka = sum(moves.mapped('amount_total_signed')) + total_uang_muka = sum(moves.mapped('amount_total_signed')) if moves else 0.0 + total_midtrans = sum(self.env['sale.order'].browse(so_ids).mapped('gross_amount')) if so_ids else 0.0 + total_pembayaran = total_uang_muka + total_midtrans - uang_masuk = total_uang_muka if moves else sum(self.env['sale.order'].browse(so_ids).mapped('gross_amount')) - vals['uang_masuk'] = uang_masuk - total_invoice = sum(self.env['account.move'].browse(invoice_ids).mapped('amount_total_signed')) if invoice_ids else 0.0 + existing_refunds = self.env['refund.sale.order'].search([ + ('sale_order_ids', 'in', so_ids) + ], order='id desc', limit=1) + if existing_refunds: + sisa_uang_masuk = existing_refunds.remaining_refundable + else: + sisa_uang_masuk = total_pembayaran + + if sisa_uang_masuk < 0: + raise UserError("❌ Tidak ada sisa transaksi untuk di-refund.") + + vals['uang_masuk'] = sisa_uang_masuk + + total_invoice = sum(self.env['account.move'].browse(invoice_ids).mapped('amount_total_signed')) if invoice_ids else 0.0 vals['total_invoice'] = total_invoice amount_refund = vals.get('amount_refund', 0.0) if amount_refund <= 0.00: @@ -240,16 +304,13 @@ class RefundSaleOrder(models.Model): if existing_refund: raise UserError("❌ Refund multi SO hanya bisa 1 kali.") vals['remaining_refundable'] = 0.0 - elif so_ids and len(so_ids) == 1: - so = self.env['sale.order'].browse(so_ids[0]) - existing_refunds = self.search([('sale_order_ids', 'in', so_ids)]) - total_refunded = sum(existing_refunds.mapped('amount_refund')) + amount_refund - remaining = uang_masuk - total_refunded + elif so_ids and len(so_ids) == 1 and refund_type != 'salah_transfer': + remaining = vals['uang_masuk'] - amount_refund if remaining < 0: raise ValidationError("❌ Tidak ada sisa transaksi untuk di-refund di SO ini. Semua dana sudah dikembalikan.") vals['remaining_refundable'] = remaining - return super().create(vals) + return super().create(vals) def write(self, vals): @@ -276,6 +337,9 @@ class RefundSaleOrder(models.Model): if so_ids: sale_orders = self.env['sale.order'].browse(so_ids) + partner = sale_orders.mapped('partner_id.id') + if len(partner) > 1: + raise UserError("❌ Tidak dapat membuat refund untuk Multi SO dengan Customer berbeda. Harus memiliki Customer yang sama.") vals['partner_id'] = sale_orders[0].partner_id.id sale_orders = self.env['sale.order'].browse(so_ids) @@ -294,15 +358,12 @@ class RefundSaleOrder(models.Model): refund_type = vals.get('refund_type', rec.refund_type) if refund_type in ['barang_kosong', 'barang_kosong_sebagian'] and sale_orders: - zero_delivery_lines = sale_orders.mapped('order_line').filtered(lambda l: l.qty_delivered == 0) + zero_delivery_lines = sale_orders.mapped('order_line').filtered(lambda l: l.qty_delivered >= 0 or l.product_uom_qty > l.qty_delivered) if not zero_delivery_lines: raise UserError("❌ Tidak ada barang yang Tidak Terikirim di Sales Order yang dipilih.") - if not so_ids and refund_type != 'lainnya': - raise ValidationError("Jika tidak ada Sales Order yang dipilih, maka Tipe Refund hanya boleh 'Lainnya'.") - - if refund_type == 'barang_kosong_sebagian' and sale_orders: - vals['uang_masuk'] = sum(sale_orders.mapped('amount_total')) + if not so_ids and refund_type != 'salah_transfer': + raise ValidationError("Jika tidak ada Sales Order yang dipilih, maka Tipe Refund hanya boleh 'Salah Transfer'.") invoice_ids = vals.get('invoice_ids', False) @@ -320,8 +381,12 @@ class RefundSaleOrder(models.Model): if invoice_ids and vals.get('refund_type', rec.refund_type) not in ['uang', 'barang_kosong_sebagian', 'barang_kosong', 'retur_half', 'retur']: raise UserError("Refund type Hanya Bisa Lebih Bayar, Barang Kosong Sebagian, atau Retur jika ada invoice") - if not invoice_ids and vals.get('refund_type', rec.refund_type) in ['uang', 'barang_kosong_sebagian']: - raise UserError("Refund type Lebih Bayar, Barang Kosong Sebagian, atau Retur Hanya Bisa dipilih Jika Ada Invoice") + if not invoice_ids and vals.get('refund_type', rec.refund_type) in ['uang', 'barang_kosong_sebagian', 'retur_half']: + raise UserError("Refund type Lebih Bayar, Barang Kosong Sebagian, atau Retur Sebagian Hanya Bisa dipilih Jika Ada Invoice") + if refund_type == 'salah_transfer' and vals.get('transfer_move_id'): + move = self.env['account.move'].browse(vals['transfer_move_id']) + if move: + vals['uang_masuk'] = move.amount_total_signed if any(field in vals for field in ['uang_masuk', 'invoice_ids', 'ongkir', 'sale_order_ids', 'amount_refund']): total_invoice = sum(self.env['account.move'].browse(invoice_ids).mapped('amount_total_signed')) @@ -349,15 +414,23 @@ class RefundSaleOrder(models.Model): @api.onchange('ongkir', 'amount_refund') def _onchange_refund_fields(self): for rec in self: - uang_masuk = rec.uang_masuk or 0.0 - ongkir = rec.ongkir or 0.0 refund_input = rec.amount_refund or 0.0 - total_refund_with_ongkir = refund_input + ongkir - if total_refund_with_ongkir > uang_masuk: - raise UserError("❌ Refund + Ongkir tidak boleh melebihi Uang Masuk.") - remaining = uang_masuk - refund_input - rec.remaining_refundable = remaining + # ambil refund terakhir untuk SO + existing_refund = self.env['refund.sale.order'].search([ + ('sale_order_ids', 'in', rec.sale_order_ids.ids) + ], order='id desc', limit=1) + + if existing_refund: + sisa_uang_masuk = existing_refund.remaining_refundable + else: + sisa_uang_masuk = rec.uang_masuk or 0.0 + + # update field uang_masuk supaya form menampilkan sisa aktual + rec.uang_masuk = sisa_uang_masuk + + # hitung remaining setelah input refund + rec.remaining_refundable = sisa_uang_masuk - refund_input @api.depends('status_payment', 'status') def _compute_is_locked(self): @@ -399,6 +472,8 @@ class RefundSaleOrder(models.Model): all_invoices = self.env['account.move'] total_invoice = 0.0 + so_ids = self.sale_order_ids.ids + for so in self.sale_order_ids: self.ongkir += so.delivery_amt or 0.0 valid_invoices = so.invoice_ids.filtered( @@ -407,6 +482,15 @@ class RefundSaleOrder(models.Model): all_invoices |= valid_invoices total_invoice += sum(valid_invoices.mapped('amount_total_signed')) + moves = self.env['account.move'].search([ + ('sale_id', 'in', so_ids), + ('journal_id', '=', 11), + ('state', '=', 'posted'), + ]) + total_uang_muka = sum(moves.mapped('amount_total_signed')) if moves else 0.0 + total_midtrans = sum(self.env['sale.order'].browse(so_ids).mapped('gross_amount')) if so_ids else 0.0 + self.uang_masuk = total_uang_muka + total_midtrans + self.invoice_ids = all_invoices self.total_invoice = total_invoice @@ -464,9 +548,15 @@ class RefundSaleOrder(models.Model): line_vals.append((0, 0, { 'product_id': line.product_id.id, 'quantity': line.product_uom_qty, - 'ref_id': line.order_id.id, + 'from_name': so.name, + 'prod_id': so.id, 'reason': '', + 'price_unit': line.price_unit, + 'discount': line.discount, + 'tax_amt': line.price_tax, + 'tax': [(6, 0, line.tax_id.ids)], })) + self.line_ids = line_vals @@ -495,33 +585,57 @@ class RefundSaleOrder(models.Model): ]) for picking in product_out: for move in picking.move_lines: - line_vals.append((0, 0, { - 'product_id': move.product_id.id, - 'ref_id': picking.id, - 'quantity': move.product_uom_qty, - 'reason': '', - })) + so_lines = so.order_line.filtered( + lambda l: l.product_id == move.product_id + ) + for so_line in so_lines: + line_vals.append((0, 0, { + 'product_id': move.product_id.id, + 'ref_id': picking.id, + 'from_name': picking.name, + 'quantity': move.product_uom_qty, + 'reason': '', + 'price_unit': so_line.price_unit, + 'discount': so_line.discount, + 'tax': [(6, 0, so_line.tax_id.ids)], + })) has_bu_pick = any(p.picking_type_id.id == 30 for p in so.picking_ids) if not has_bu_pick: for picking in pickings_srt: for move in picking.move_lines: - line_vals.append((0, 0, { - 'product_id': move.product_id.id, - 'ref_id': picking.ref_id, - 'quantity': move.product_uom_qty, - 'reason': '', - })) + so_lines = so.order_line.filtered( + lambda l: l.product_id == move.product_id + ) + for so_line in so_lines: + line_vals.append((0, 0, { + 'product_id': move.product_id.id, + 'ref_id': picking.id, + 'from_name': picking.name, + 'quantity': move.product_uom_qty, + 'reason': '', + 'price_unit': so_line.price_unit, + 'discount': so_line.discount, + 'tax': [(6, 0, so_line.tax_id.ids)], + })) else: for picking in pickings_ort: for move in picking.move_lines: - line_vals.append((0, 0, { - 'product_id': move.product_id.id, - 'ref_id': picking.ref_id, - 'quantity': move.product_uom_qty, - 'reason': '', - })) - self.line_ids = line_vals + so_lines = so.order_line.filtered( + lambda l: l.product_id == move.product_id + ) + for so_line in so_lines: + line_vals.append((0, 0, { + 'product_id': move.product_id.id, + 'ref_id': picking.id, + 'from_name': picking.name, + 'quantity': move.product_uom_qty, + 'reason': '', + 'price_unit': so_line.price_unit, + 'discount': so_line.discount, + 'tax': [(6, 0, so_line.tax_id.ids)], + })) + self.line_ids = line_vals @api.depends('invoice_ids') @@ -602,6 +716,10 @@ class RefundSaleOrder(models.Model): raise ValidationError( f"⚠️ SO {so.name} memiliki refund tipe Retur. Selesaikan pengajuan retur untuk melanjutkan refund" ) + allowed_sales_ids = rec.sale_order_ids.mapped("user_id.id") + if self.env.user.id not in allowed_sales_ids and rec.refund_type != 'salah_transfer': + raise ValidationError("❌ Hanya Sales pemilik Sales Order terkait yang boleh meminta approval refund ini.") + if rec.status == 'draft': rec.status = 'pengajuan1' @@ -856,6 +974,41 @@ class RefundSaleOrder(models.Model): ]) rec.show_return_alert = not retur_ort and not retur_srt and rec.refund_type in ['retur', 'retur_half'] + def _compute_show_approval_alert(self): + for rec in self: + retur_ort = self.env['stock.picking'].search([ + ('state', '=', 'done'), + ('picking_type_id', '=', 74), + ('sale_id', 'in', rec.sale_order_ids.ids) + ]) + + retur_srt = self.env['stock.picking'].search([ + ('state', '=', 'done'), + ('picking_type_id', '=', 73), + ('sale_id', 'in', rec.sale_order_ids.ids) + ]) + rec.show_approval_alert = retur_ort or retur_srt and rec.refund_type in ['retur', 'retur_half'] + + @api.depends('tukar_guling_ids', 'tukar_guling_ids.picking_ids') + def _compute_picking_ids(self): + for rec in self: + rec.picking_ids = rec.tukar_guling_ids.mapped('picking_ids') + + def action_view_picking(self): + self.ensure_one() + action = self.env.ref('stock.action_picking_tree_all').read()[0] + if len(self.picking_ids) == 1: + action['views'] = [(self.env.ref('stock.view_picking_form').id, 'form')] + action['res_id'] = self.picking_ids.id + else: + action['domain'] = [('id', 'in', self.picking_ids.ids)] + return action + + @api.depends('picking_ids') + def _compute_has_picking(self): + for rec in self: + rec.has_picking = bool(rec.picking_ids) + def action_create_tukar_guling(self): for refund in self: if refund.refund_type not in ['retur', 'retur_half']: @@ -897,8 +1050,7 @@ class RefundSaleOrder(models.Model): 'origin_so': refund.sale_order_ids.id, 'operations': picking.id, 'return_type': 'revisi_so', - 'is_has_invoice': bool(refund.invoice_ids.ids), - 'invoice_id': refund.invoice_ids.ids if refund.invoice_ids.ids else None, + 'invoice_id': [(6, 0, refund.invoice_ids.ids)], 'refund_id': refund.id, 'line_ids': line_vals, 'mapping_koli_ids': koli_lines @@ -933,10 +1085,38 @@ class RefundSaleOrder(models.Model): class RefundSaleOrderLine(models.Model): _name = 'refund.sale.order.line' _description = 'Refund Sales Order Line' - _inherit = ['mail.thread'] refund_id = fields.Many2one('refund.sale.order', string='Refund Ref') product_id = fields.Many2one('product.product', string='Product') quantity = fields.Float(string='Qty') reason = fields.Char(string='Reason') - ref_id = fields.Many2one('stock.picking',string='Product Reference') + ref_id = fields.Many2one('stock.picking', string='Picking Reference') + prod_id = fields.Many2one('sale.order', string='Sales Order Reference') + from_name = fields.Char(string="Product Reference") + price_unit = fields.Float(string="Unit Price") + tax_amt = fields.Float(string="Amount Tax", compute='_compute_amounts') + discount = fields.Float(string="Discount %") + tax = fields.Many2many('account.tax',string="Taxes") + subtotal = fields.Float(string="Subtotal", compute='_compute_amounts') + total = fields.Float(string="Grand Total", compute='_compute_amounts') + + @api.depends('quantity', 'price_unit', 'discount', 'tax') + def _compute_amounts(self): + for line in self: + price_unit = line.price_unit * (1 - (line.discount or 0.0) / 100.0) + + subtotal = price_unit * line.quantity + tax_amount = 0.0 + if line.tax: + taxes = line.tax.compute_all( + price_unit=price_unit, # Gunakan harga setelah diskon + quantity=line.quantity, + product=line.product_id, + partner=line.refund_id.partner_id + ) + tax_amount = taxes['total_included'] - taxes['total_excluded'] + subtotal = taxes['total_excluded'] + + line.subtotal = subtotal + line.tax_amt = tax_amount + line.total = subtotal + tax_amount \ No newline at end of file diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index a357eb70..998363ef 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -3196,6 +3196,16 @@ class SaleOrder(models.Model): def button_refund(self): self.ensure_one() + + if self.state not in ['cancel', 'sale']: + raise UserError(f"❌ SO {self.name} tidak bisa direfund. Status harus Cancel atau Sale.") + if self.state == 'sale': + not_done_pickings = self.picking_ids.filtered(lambda p: p.state not in ['done', 'cancel']) + if not_done_pickings: + raise UserError( + f"❌ SO {self.name} Belum melakukan kirim barang " + f"({', '.join(not_done_pickings.mapped('name'))}). Selesaikan Pengiriman untuk melakukan refund." + ) moves = self.env['account.move'].search([ ('sale_id', '=', self.id), ('journal_id', '=', 11), @@ -3220,7 +3230,7 @@ class SaleOrder(models.Model): "(Journal Uang Muka/Midtrans Payment)." ) invoice_ids = self.invoice_ids.filtered(lambda inv: inv.state != 'cancel') - total_refunded = sum(self.refund_ids.mapped('amount_refund')) or 0.0 + total_refunded = sum(self.refund_ids.mapped('amount_refund')) sisa_uang_muka = total_uang_muka - total_refunded if sisa_uang_muka <= 0: @@ -3249,6 +3259,30 @@ class SaleOrder(models.Model): if not self: raise UserError("Tidak ada Sale Order yang dipilih.") + if len(self) > 1: + not_cancel_orders = self.filtered(lambda so: so.state != 'cancel') + if not_cancel_orders: + raise ValidationError( + f"❌ Refund Multi SO hanya bisa dibuat untuk SO dengan status Cancel. " + f"SO berikut tidak Cancel: {', '.join(not_cancel_orders.mapped('name'))}" + ) + + + invalid_status_orders = [] + for order in self: + if order.state not in ['cancel', 'sale']: + invalid_status_orders.append(order.name) + elif order.state == 'sale': + not_done_pickings = order.picking_ids.filtered(lambda p: p.state != 'done') + if not_done_pickings: + invalid_status_orders.append(order.name) + + if invalid_status_orders: + raise ValidationError( + f"❌ Refund tidak bisa dibuat untuk SO {', '.join(invalid_status_orders)}. " + f"SO harus Cancel atau Sale dengan semua Pengiriman sudah selesai." + ) + partner_set = set(self.mapped('partner_id.id')) if len(partner_set) > 1: raise UserError("Tidak dapat membuat refund untuk Multi SO dengan Customer berbeda. Harus memiliki Customer yang sama.") diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py index 1309fcfe..ff4edc84 100644 --- a/indoteknik_custom/models/tukar_guling.py +++ b/indoteknik_custom/models/tukar_guling.py @@ -96,38 +96,39 @@ class TukarGuling(models.Model): so = self.env['sale.order'].search([('name', '=', origin_str)], limit=1) rec.origin_so = so.id if so else False - @api.depends('origin', 'origin_so', 'partner_id', 'line_ids.product_id') + @api.depends('origin', 'origin_so', 'partner_id', 'line_ids.product_id', 'invoice_id', 'operations') def _compute_is_has_invoice(self): Move = self.env['account.move'] for rec in self: - rec.is_has_invoice = False - rec.invoice_id = [(5, 0, 0)] - - product_ids = rec.line_ids.mapped('product_id').ids - if not product_ids: - continue - - domain = [ - ('move_type', 'in', ['out_invoice', 'in_invoice']), - ('state', 'not in', ['draft', 'cancel']), - ('invoice_line_ids.product_id', 'in', product_ids), - ] - - if rec.partner_id: - domain.append(('partner_id', '=', rec.partner_id.id)) - - extra = [] - if rec.origin: - extra.append(('invoice_origin', 'ilike', rec.origin)) - if rec.origin_so: - extra.append(('invoice_line_ids.sale_line_ids.order_id', '=', rec.origin_so.id)) - if extra: - domain = domain + ['|'] * (len(extra) - 1) + extra - - invoices = Move.search(domain).with_context(active_test=False) - if invoices: - rec.invoice_id = [(6, 0, invoices.ids)] - rec.is_has_invoice = True + invoices = rec.invoice_id + + if not invoices: + product_ids = rec.line_ids.mapped('product_id').ids + if product_ids: + domain = [ + ('move_type', 'in', ['out_invoice', 'out_refund', 'in_invoice']), + ('state', 'not in', ['draft', 'cancel']), + ('invoice_line_ids.product_id', 'in', product_ids), + ] + + # if rec.partner_id: + # domain.append( + # ('partner_id.commercial_partner_id', '=', rec.partner_id.commercial_partner_id.id) + # ) + + extra = [] + if rec.origin: + extra.append(('invoice_origin', 'ilike', rec.origin)) + if rec.origin_so: + extra.append(('invoice_line_ids.sale_line_ids.order_id', '=', rec.origin_so.id)) + if extra: + domain += ['|'] * (len(extra) - 1) + extra + + invoices = Move.search(domain).with_context(active_test=False) + if invoices: + rec.invoice_id = [(6, 0, invoices.ids)] + + rec.is_has_invoice = bool(invoices) def set_opt(self): if not self.val_inv_opt and self.is_has_invoice == True: @@ -1009,4 +1010,4 @@ class TukarGulingMappingKoli(models.Model): for rec in self: if rec.tukar_guling_id and rec.tukar_guling_id.state not in ['draft', 'cancel']: raise UserError("Tidak bisa menghapus Mapping Koli karena status Tukar Guling bukan Draft atau Cancel.") - return super(TukarGulingMappingKoli, self).unlink() + return super(TukarGulingMappingKoli, self).unlink() \ No newline at end of file diff --git a/indoteknik_custom/views/refund_sale_order.xml b/indoteknik_custom/views/refund_sale_order.xml index a2538f42..ae0861e2 100644 --- a/indoteknik_custom/views/refund_sale_order.xml +++ b/indoteknik_custom/views/refund_sale_order.xml @@ -90,6 +90,11 @@ attrs="{'invisible': [('show_return_alert', '=', False)]}"> ⚠️ SO belum melakukan retur barang. Silakan buat pengajuan retur. + +
@@ -101,12 +106,24 @@ attrs="{'invisible': [('journal_refund_move_id', '=', False)]}"> - + +
- - - - - + + + + + + +
- - + + + @@ -157,9 +179,17 @@ - + + + + + + + + + @@ -176,6 +206,7 @@ +
@@ -230,11 +261,34 @@ + + + + + + + + + + + + + + + + +
+
-- cgit v1.2.3 From fd2d67cacb3015e346b9656b7329606066c2f95a Mon Sep 17 00:00:00 2001 From: Miqdad Date: Fri, 29 Aug 2025 15:01:45 +0700 Subject: fix return selain SO PO --- indoteknik_custom/models/stock_picking_return.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/stock_picking_return.py b/indoteknik_custom/models/stock_picking_return.py index 1fc8d088..88acf83c 100644 --- a/indoteknik_custom/models/stock_picking_return.py +++ b/indoteknik_custom/models/stock_picking_return.py @@ -110,7 +110,7 @@ class ReturnPicking(models.TransientModel): if mapping_koli_vals: context['default_mapping_koli_ids'] = mapping_koli_vals - if picking.purchase_id or 'PO' in picking.origin: + if picking.purchase_id or 'PO' in (picking.origin or ''): _logger.info("Redirect ke Tukar Guling PO via purchase_id / origin") return { 'name': _('Tukar Guling PO'), @@ -120,7 +120,7 @@ class ReturnPicking(models.TransientModel): 'target': 'current', 'context': context, } - else: + if picking.sale_id or 'SO' in (picking.origin or ''): _logger.info("This picking is NOT from a PO, fallback to SO.") return { 'name': _('Tukar Guling SO'), @@ -130,6 +130,9 @@ class ReturnPicking(models.TransientModel): 'target': 'current', 'context': context, } + else: + _logger.info("Bukan SO/PO → retur standar (create_returns)") + return super(ReturnPicking, self).create_returns() class ReturnPickingLine(models.TransientModel): -- cgit v1.2.3 From 0298605049e29ef436a5e6984b743f89fed712b3 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Sat, 30 Aug 2025 09:23:35 +0700 Subject: last logic unlink --- indoteknik_custom/models/refund_sale_order.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/indoteknik_custom/models/refund_sale_order.py b/indoteknik_custom/models/refund_sale_order.py index 086c7a81..51907083 100644 --- a/indoteknik_custom/models/refund_sale_order.py +++ b/indoteknik_custom/models/refund_sale_order.py @@ -660,10 +660,10 @@ class RefundSaleOrder(models.Model): record.amount_refund_text = '' def unlink(self): - not_draft = self.filtered(lambda r: r.status != 'draft') - if not_draft: - names = ', '.join(not_draft.mapped('name')) - raise UserError(f"Refund hanya bisa dihapus jika statusnya masih draft.\nTidak bisa hapus: {names}") + incantdelete = self.filtered(lambda r: r.status in ['refund', 'reject']) + if incantdelete: + names = ', '.join(incantdelete.mapped('name')) + raise UserError(f"Refund tidak dapat di hapus jika sudah Confirm/Cancel.\nTidak bisa hapus: {names}") return super().unlink() @api.depends('invoice_ids') -- cgit v1.2.3 From 19e63a5715369a740f209c49115a90967a6aa7d6 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Sat, 30 Aug 2025 09:58:22 +0700 Subject: fix validation approval --- indoteknik_custom/models/refund_sale_order.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/indoteknik_custom/models/refund_sale_order.py b/indoteknik_custom/models/refund_sale_order.py index 51907083..6d0b5741 100644 --- a/indoteknik_custom/models/refund_sale_order.py +++ b/indoteknik_custom/models/refund_sale_order.py @@ -751,19 +751,19 @@ class RefundSaleOrder(models.Model): if not rec.status or rec.status == 'draft': rec.status = 'pengajuan1' - elif rec.status == 'pengajuan1': + elif rec.status == 'pengajuan1' and self.env.user.id == 19: rec.status = 'pengajuan2' rec.approved_by = f"{rec.approved_by}, {user_name}" if rec.approved_by else user_name rec.date_approved_sales = now rec.position_sales = 'Sales Manager' - elif rec.status == 'pengajuan2': + elif rec.status == 'pengajuan2' and self.env.user.id == 688: rec.status = 'pengajuan3' rec.approved_by = f"{rec.approved_by}, {user_name}" if rec.approved_by else user_name rec.date_approved_ar = now rec.position_ar = 'AR' - elif rec.status == 'pengajuan3': + elif rec.status == 'pengajuan3' and self.env.user.id == 7: rec.status = 'refund' rec.approved_by = f"{rec.approved_by}, {user_name}" if rec.approved_by else user_name rec.date_approved_pimpinan = now -- cgit v1.2.3 From 7186c4657cb85d2175222b4bebc55456e6970a3a Mon Sep 17 00:00:00 2001 From: Miqdad Date: Sat, 30 Aug 2025 10:09:06 +0700 Subject: unlink val vcm ccm --- indoteknik_custom/models/tukar_guling.py | 4 ++-- indoteknik_custom/models/tukar_guling_po.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py index 699ee670..e9cbf246 100644 --- a/indoteknik_custom/models/tukar_guling.py +++ b/indoteknik_custom/models/tukar_guling.py @@ -435,9 +435,9 @@ class TukarGuling(models.Model): # if self.state == 'done': # raise UserError ("Tidak Boleh delete ketika sudahh done") for record in self: - if record.state == 'approved' or record.state == 'done': + if record.state in [ 'approved', 'done', 'approval_logistic', 'approval_finance', 'approval_sales']: raise UserError( - "Tidak bisa hapus pengajuan jika sudah Approved, set ke draft terlebih dahulu jika ingin menghapus") + "Tidak bisa hapus pengajuan jika sudah Proses Approval, set ke draft terlebih dahulu atau cancel jika ingin menghapus") ongoing_bu = self.picking_ids.filtered(lambda p: p.state != 'approved') for picking in ongoing_bu: picking.action_cancel() diff --git a/indoteknik_custom/models/tukar_guling_po.py b/indoteknik_custom/models/tukar_guling_po.py index 94771f37..f2f37606 100644 --- a/indoteknik_custom/models/tukar_guling_po.py +++ b/indoteknik_custom/models/tukar_guling_po.py @@ -381,8 +381,8 @@ class TukarGulingPO(models.Model): def unlink(self): for record in self: - if record.state == 'done' or record.state == 'approved': - raise UserError("Tidak bisa hapus pengajuan jika sudah done, set ke draft terlebih dahulu") + if record.state in [ 'approved', 'done', 'approval_logistic', 'approval_finance', 'approval_purchase']: + raise UserError("Tidak bisa hapus pengajuan jika sudah proses approval atau done, set ke draft atau cancel terlebih dahulu") ongoing_bu = self.po_picking_ids.filtered(lambda p: p.state != 'done') for picking in ongoing_bu: picking.action_cancel() -- cgit v1.2.3 From d91498b1aae363a3c51023a0fc8bc8086a294838 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Mon, 1 Sep 2025 09:40:59 +0700 Subject: --- indoteknik_custom/security/ir.model.access.csv | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index 866a7140..3a320510 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -194,4 +194,5 @@ access_tukar_guling_line_po_all_users,tukar.guling.line.po.all.users,model_tukar access_tukar_guling_mapping_koli_all_users,tukar.guling.mapping.koli.all.users,model_tukar_guling_mapping_koli,base.group_user,1,1,1,1 access_purchase_order_update_date_wizard,access.purchase.order.update.date.wizard,model_purchase_order_update_date_wizard,base.group_user,1,1,1,1 access_sync_promise_date_wizard,access.sync.promise.date.wizard,model_sync_promise_date_wizard,base.group_user,1,1,1,1 -access_sync_promise_date_wizard_line,access.sync.promise.date.wizard.line,model_sync_promise_date_wizard_line,base.group_user,1,1,1,1 \ No newline at end of file +access_sync_promise_date_wizard_line,access.sync.promise.date.wizard.line,model_sync_promise_date_wizard_line,base.group_user,1,1,1,1 +access_change_date_planned_wizard,access.change.date.planned.wizard,model_change_date_planned_wizard,,1,1,1,1 \ No newline at end of file -- cgit v1.2.3 From d7a5e47f741211e9750c21ac148331d6e29bdc16 Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Mon, 1 Sep 2025 10:00:32 +0700 Subject: (andri) add sum grand total tree dunning run --- indoteknik_custom/views/dunning_run.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indoteknik_custom/views/dunning_run.xml b/indoteknik_custom/views/dunning_run.xml index 210f7917..f624c42e 100644 --- a/indoteknik_custom/views/dunning_run.xml +++ b/indoteknik_custom/views/dunning_run.xml @@ -13,7 +13,7 @@ - + -- cgit v1.2.3