From b3cd6aeb021259b4004a58270a2a7b6b0d82ba1d Mon Sep 17 00:00:00 2001 From: Miqdad Date: Sun, 10 Aug 2025 19:42:25 +0700 Subject: show invoice rev --- indoteknik_custom/models/tukar_guling.py | 32 ++++++++++++++++++++++++-------- indoteknik_custom/views/tukar_guling.xml | 4 +++- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py index 6aedb70e..624de7a9 100644 --- a/indoteknik_custom/models/tukar_guling.py +++ b/indoteknik_custom/models/tukar_guling.py @@ -92,19 +92,35 @@ 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') + @api.depends('origin_so', 'mapping_koli_ids.product_id', 'line_ids.product_id') def _compute_is_has_invoice(self): for rec in self: - invoices = self.env['account.move'].search([ - ('invoice_origin', 'ilike', rec.origin), - ('move_type', '=', 'out_invoice'), # hanya invoice - ('state', 'not in', ['draft', 'cancel']) - ]) + 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) + ) + 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: diff --git a/indoteknik_custom/views/tukar_guling.xml b/indoteknik_custom/views/tukar_guling.xml index a8d8b7b7..9dd31905 100644 --- a/indoteknik_custom/views/tukar_guling.xml +++ b/indoteknik_custom/views/tukar_guling.xml @@ -86,7 +86,6 @@ - @@ -96,6 +95,9 @@ + + + -- cgit v1.2.3