summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiqdad <ahmadmiqdad27@gmail.com>2025-08-10 20:16:09 +0700
committerMiqdad <ahmadmiqdad27@gmail.com>2025-08-10 20:16:09 +0700
commit356e53b85511c98cf4c942c32f2f370f58c9d849 (patch)
tree05de1a12da1e621f5ee3ca5405ad5de752a1e9a6
parentb3cd6aeb021259b4004a58270a2a7b6b0d82ba1d (diff)
<miqdad> pengajuan return so revert
-rw-r--r--indoteknik_custom/models/tukar_guling.py32
1 files changed, 8 insertions, 24 deletions
diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py
index 624de7a9..6aedb70e 100644
--- a/indoteknik_custom/models/tukar_guling.py
+++ b/indoteknik_custom/models/tukar_guling.py
@@ -92,35 +92,19 @@ 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_so', 'mapping_koli_ids.product_id', 'line_ids.product_id')
+ @api.depends('origin')
def _compute_is_has_invoice(self):
for rec in self:
- rec.is_has_invoice = False
- rec.invoice_id = False
-
- if not rec.origin_so:
- continue
-
- # Ambil produk dari mapping_koli kalau ada, kalau kosong pakai line_ids
- if rec.mapping_koli_ids:
- retur_products = rec.mapping_koli_ids.mapped('product_id')
- else:
- retur_products = rec.line_ids.mapped('product_id')
-
- # Semua invoice dari SO asal
- invoices = rec.origin_so.invoice_ids.filtered(
- lambda inv: inv.state not in ('draft', 'cancel')
- and inv.move_type in ('out_invoice', 'out_refund')
- )
-
- # Filter invoice yang punya produk yang diretur
- invoices = invoices.filtered(
- lambda inv: any(line.product_id in retur_products for line in inv.invoice_line_ids)
- )
-
+ invoices = self.env['account.move'].search([
+ ('invoice_origin', 'ilike', rec.origin),
+ ('move_type', '=', 'out_invoice'), # hanya invoice
+ ('state', 'not in', ['draft', 'cancel'])
+ ])
if invoices:
rec.is_has_invoice = True
rec.invoice_id = invoices
+ else:
+ rec.is_has_invoice = False
def set_opt(self):
if not self.val_inv_opt and self.is_has_invoice == True: