summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiqdad <ahmadmiqdad27@gmail.com>2025-08-10 19:42:25 +0700
committerMiqdad <ahmadmiqdad27@gmail.com>2025-08-10 19:42:25 +0700
commitb3cd6aeb021259b4004a58270a2a7b6b0d82ba1d (patch)
tree3142d29c95c16b6a269e5b419ddf848faf57e960
parentdf5ff0fc9bcd45c19b74288d8e5cfee018ba5bdd (diff)
<miqdad> show invoice rev
-rw-r--r--indoteknik_custom/models/tukar_guling.py32
-rw-r--r--indoteknik_custom/views/tukar_guling.xml4
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 @@
<!-- <field name="origin" readonly="1"/>-->
<field name="origin_so" readonly="1"/>
<field name="is_has_invoice" readonly="1"/>
- <field name="invoice_id" readonly="1" widget="many2many_tags"/>
</group>
<group>
<field name="val_inv_opt" attrs="{'invisible': [('is_has_invoice', '=', False)]}"/>
@@ -96,6 +95,9 @@
<field name="date_finance" readonly="1"/>
<field name="date_logistic" readonly="1"/>
</group>
+ <group>
+ <field name="invoice_id" readonly="1" attrs="{'invisible': [('is_has_invoice', '=', False)]}"/>
+ </group>
</group>
<notebook>
<page string="Product Lines" name="product_lines">