diff options
| author | AndriFP <113114423+andrifp@users.noreply.github.com> | 2025-09-10 17:56:31 +0700 |
|---|---|---|
| committer | AndriFP <113114423+andrifp@users.noreply.github.com> | 2025-09-10 17:56:31 +0700 |
| commit | 10da5e27e658030f171f694d6696f93e4a472447 (patch) | |
| tree | 14a5f684bae4bc0803ed3c61cb1ce1bed23e33f6 /indoteknik_custom/models/refund_sale_order.py | |
| parent | 914bcd75dd2baddb2841cbfba6a64ebd453fecdb (diff) | |
| parent | 4db6034c07414dcd09292e3c41d6fd4598868148 (diff) | |
Merge branch 'odoo-backup' of https://bitbucket.org/altafixco/indoteknik-addons into pum-v2
Diffstat (limited to 'indoteknik_custom/models/refund_sale_order.py')
| -rw-r--r-- | indoteknik_custom/models/refund_sale_order.py | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/indoteknik_custom/models/refund_sale_order.py b/indoteknik_custom/models/refund_sale_order.py index 6d0b5741..9ab18f27 100644 --- a/indoteknik_custom/models/refund_sale_order.py +++ b/indoteknik_custom/models/refund_sale_order.py @@ -76,6 +76,7 @@ class RefundSaleOrder(models.Model): transfer_move_id = fields.Many2one( 'account.move', string="Journal Payment", + copy=False, help="Pilih transaksi salah transfer dari jurnal Uang Muka (journal_id=11) yang tidak terkait SO." ) @@ -392,6 +393,7 @@ class RefundSaleOrder(models.Model): total_invoice = sum(self.env['account.move'].browse(invoice_ids).mapped('amount_total_signed')) vals['total_invoice'] = total_invoice uang_masuk = rec.uang_masuk + amount_refund = vals.get('amount_refund', rec.amount_refund) if amount_refund <= 0: @@ -401,36 +403,24 @@ class RefundSaleOrder(models.Model): ('sale_order_ids', 'in', so_ids), ('id', '!=', rec.id) ]) - total_refunded = sum(existing_refunds.mapped('amount_refund')) + amount_refund - remaining = uang_masuk - total_refunded + total_refunded = sum(existing_refunds.mapped('amount_refund')) + if existing_refunds: + remaining = uang_masuk - total_refunded + else: + remaining = uang_masuk - amount_refund if remaining < 0: - raise ValidationError("❌ Dana uang masuk telah sepenuhnya di refund tidak bisa Mengubah Nominal Refund") + raise ValidationError("Semua dana sudah dikembalikan, tidak bisa mengajukan refund") vals['remaining_refundable'] = remaining return super().write(vals) - @api.onchange('ongkir', 'amount_refund') + @api.onchange('amount_refund') def _onchange_refund_fields(self): for rec in self: refund_input = rec.amount_refund or 0.0 - - # 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 + rec.remaining_refundable = (rec.uang_masuk or 0.0) - refund_input @api.depends('status_payment', 'status') def _compute_is_locked(self): |
