diff options
| author | HafidBuroiroh <hafidburoiroh09@gmail.com> | 2026-01-30 15:52:21 +0700 |
|---|---|---|
| committer | HafidBuroiroh <hafidburoiroh09@gmail.com> | 2026-01-30 15:52:21 +0700 |
| commit | 4ac8b06616a0dce80029e1063078b31b6100084e (patch) | |
| tree | 4f15246c31154c1f3174d111aa9129532d7432d9 | |
| parent | 4560970a9bdfd9fab483019f24d78cfe78330e32 (diff) | |
<hafid> refund kebutuhan BA dan cahsback
| -rw-r--r-- | indoteknik_custom/models/refund_sale_order.py | 53 | ||||
| -rw-r--r-- | indoteknik_custom/models/sale_order_line.py | 42 | ||||
| -rwxr-xr-x | indoteknik_custom/views/sale_order.xml | 2 | ||||
| -rwxr-xr-x | indoteknik_custom/views/x_manufactures.xml | 2 |
4 files changed, 63 insertions, 36 deletions
diff --git a/indoteknik_custom/models/refund_sale_order.py b/indoteknik_custom/models/refund_sale_order.py index 1c482619..c3b7a356 100644 --- a/indoteknik_custom/models/refund_sale_order.py +++ b/indoteknik_custom/models/refund_sale_order.py @@ -62,7 +62,8 @@ class RefundSaleOrder(models.Model): ('uang', 'Refund Lebih Bayar'), ('retur_half', 'Refund Retur Sebagian'), ('retur', 'Refund Retur Full'), - ('salah_transfer', 'Salah Transfer') + ('salah_transfer', 'Salah Transfer'), + ('berita_acara', 'Kebutuhan Berita Acara') ], string='Refund Type', required=True) tukar_guling_ids = fields.One2many( @@ -251,7 +252,7 @@ class RefundSaleOrder(models.Model): 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 [] invoices = self.env['account.move'].browse(invoice_ids) - if invoice_ids and refund_type and refund_type not in ['uang', 'barang_kosong_sebagian', 'barang_kosong', 'retur_half']: + if invoice_ids and refund_type and refund_type not in ['uang', 'barang_kosong_sebagian', 'barang_kosong', 'retur_half', 'berita_acara']: 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', 'retur_half']: @@ -434,13 +435,17 @@ class RefundSaleOrder(models.Model): 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) - can_refund = sisa_uang_masuk - total_invoice - - if amount_refund > can_refund or can_refund == 0.0: - raise ValidationError( - _("Maksimal refund yang bisa dilakukan adalah sebesar %s. " - "Silakan sesuaikan jumlah refund.") % (can_refund) - ) + can_refund = 0.0 + if refund_type == 'berita_acara': + can_refund = sisa_uang_masuk + else: + can_refund = sisa_uang_masuk - total_invoice + if refund_type != 'berita_acara': + if amount_refund > can_refund or can_refund == 0.0: + raise ValidationError( + _("Maksimal refund yang bisa dilakukan adalah sebesar %s. " + "Silakan sesuaikan jumlah refund.") % (can_refund) + ) if amount_refund <= 0.00: raise ValidationError('Total Refund harus lebih dari 0 jika ingin mengajukan refund') @@ -451,7 +456,11 @@ class RefundSaleOrder(models.Model): raise UserError("❌ Refund multi SO hanya bisa 1 kali.") vals['remaining_refundable'] = 0.0 elif so_ids and len(so_ids) == 1 and refund_type != 'salah_transfer': - remaining = vals['uang_masuk'] - amount_refund + remaining = 0.0 + if refund_type == 'berita_acara': + vals['remaining_refundable'] = vals['uang_masuk'] - amount_refund + else: + vals['remaining_refundable'] = remaining if remaining < 0: raise ValidationError("❌ Tidak ada sisa transaksi untuk di-refund di SO ini. Semua dana sudah dikembalikan.") vals['remaining_refundable'] = remaining @@ -548,10 +557,28 @@ class RefundSaleOrder(models.Model): 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 = rec.uang_masuk - can_refund = uang_masuk - total_invoice - + uang_masuk = vals.get('uang_masuk', rec.uang_masuk) amount_refund = vals.get('amount_refund', rec.amount_refund) + can_refund = 0.0 + total_refunded = 0.0 + + if refund_type == 'berita_acara': + can_refund = uang_masuk + remaining = uang_masuk - amount_refund + else: + can_refund = uang_masuk - total_invoice + + existing_refunds = self.search([ + ('sale_order_ids', 'in', so_ids), + ('id', '!=', rec.id) + ]) + total_refunded = sum(existing_refunds.mapped('amount_refund')) + + if existing_refunds: + remaining = uang_masuk - total_refunded + else: + remaining = uang_masuk - amount_refund + if amount_refund > can_refund: raise ValidationError( diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py index d36c03e5..55bea22c 100644 --- a/indoteknik_custom/models/sale_order_line.py +++ b/indoteknik_custom/models/sale_order_line.py @@ -167,8 +167,8 @@ class SaleOrderLine(models.Model): if line.purchase_tax_id.price_include: purchase_price = line.purchase_price / (1 + (line.purchase_tax_id.amount / 100)) - if line.amount_cashback > 0: - purchase_price = purchase_price - line.amount_cashback + # if line.amount_cashback > 0: + # purchase_price = purchase_price - line.amount_cashback purchase_price = purchase_price * line.product_uom_qty margin_per_item = sales_price - purchase_price @@ -221,8 +221,8 @@ class SaleOrderLine(models.Model): if line.purchase_tax_id.price_include: purchase_price = line.purchase_price / (1 + (line.purchase_tax_id.amount / 100)) - if line.amount_cashback > 0: - purchase_price = purchase_price - line.amount_cashback + # if line.amount_cashback > 0: + # purchase_price = purchase_price - line.amount_cashback purchase_price = purchase_price * line.product_uom_qty margin_per_item = sales_price - purchase_price @@ -254,29 +254,29 @@ class SaleOrderLine(models.Model): margin_per_item = sales_price - purchase_price line.item_before_margin = margin_per_item - def _compute_cashback_brand(self): - for line in self: - line.amount_cashback = 0 + # def _compute_cashback_brand(self): + # for line in self: + # line.amount_cashback = 0 - if not line.product_id: - continue + # if not line.product_id: + # continue - cashback_percent = line.product_id.x_manufacture.cashback_percent or 0 - if cashback_percent <= 0: - continue + # cashback_percent = line.product_id.x_manufacture.cashback_percent or 0 + # if cashback_percent <= 0: + # continue - price, taxes, vendor = self._get_purchase_price(line.product_id) + # price, taxes, vendor = self._get_purchase_price(line.product_id) - price_tax_excl = price + # price_tax_excl = price - if taxes: - tax = self.env['account.tax'].browse(taxes) - if tax.price_include: - price_tax_excl = price / (1 + (tax.amount / 100)) - else: - price_tax_excl = price + # if taxes: + # tax = self.env['account.tax'].browse(taxes) + # if tax.price_include: + # price_tax_excl = price / (1 + (tax.amount / 100)) + # else: + # price_tax_excl = price - line.amount_cashback = price_tax_excl * cashback_percent + # line.amount_cashback = price_tax_excl * cashback_percent # @api.onchange('vendor_id') # def onchange_vendor_id(self): diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index c3df92ec..7a517ca7 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -302,7 +302,7 @@ ] } "/> - <field name="amount_cashback"/> + <!-- <field name="amount_cashback"/> --> <field name="purchase_price_md" optional="hide"/> <field name="purchase_tax_id" attrs="{'readonly': [('parent.approval_status', '!=', False)]}" diff --git a/indoteknik_custom/views/x_manufactures.xml b/indoteknik_custom/views/x_manufactures.xml index b52fe795..d5cec350 100755 --- a/indoteknik_custom/views/x_manufactures.xml +++ b/indoteknik_custom/views/x_manufactures.xml @@ -82,7 +82,7 @@ <field name="x_negara_asal"/> <field name="x_short_desc"/> <field name="x_manufacture_level"/> - <field name="cashback_percent" widget="percentage"/> + <!-- <field name="cashback_percent" widget="percentage"/> --> <field name="x_produk_aksesoris_sparepart"/> <field name="cache_reset_status"/> <field name="parent_id"/> |
