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 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'indoteknik_custom/models/tukar_guling.py') 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: -- cgit v1.2.3 From 356e53b85511c98cf4c942c32f2f370f58c9d849 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Sun, 10 Aug 2025 20:16:09 +0700 Subject: pengajuan return so revert --- indoteknik_custom/models/tukar_guling.py | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) (limited to 'indoteknik_custom/models/tukar_guling.py') 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: -- cgit v1.2.3 From d896d5cb51437d366c10e854616faee46736688c Mon Sep 17 00:00:00 2001 From: Miqdad Date: Tue, 12 Aug 2025 15:10:16 +0700 Subject: get bill based on product --- indoteknik_custom/models/tukar_guling.py | 37 ++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'indoteknik_custom/models/tukar_guling.py') diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py index 6aedb70e..ff641f34 100644 --- a/indoteknik_custom/models/tukar_guling.py +++ b/indoteknik_custom/models/tukar_guling.py @@ -92,19 +92,38 @@ 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', 'origin_so', 'partner_id', 'line_ids.product_id') def _compute_is_has_invoice(self): + Move = self.env['account.move'] 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 = [(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 - 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: -- cgit v1.2.3