summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/tukar_guling.py
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2025-08-29 14:23:18 +0700
committerit-fixcomart <it@fixcomart.co.id>2025-08-29 14:23:18 +0700
commit3139c592dd1f74b7c6a6c4917419628895296406 (patch)
treec77d8f30e9e6404be3237733b6f3e3e656f6729d /indoteknik_custom/models/tukar_guling.py
parent8fb3427f625867b7d47b7ed0d40f994fa52c00e6 (diff)
<hafid> refund abis testing aman
Diffstat (limited to 'indoteknik_custom/models/tukar_guling.py')
-rw-r--r--indoteknik_custom/models/tukar_guling.py61
1 files changed, 31 insertions, 30 deletions
diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py
index 1309fcfe..ff4edc84 100644
--- a/indoteknik_custom/models/tukar_guling.py
+++ b/indoteknik_custom/models/tukar_guling.py
@@ -96,38 +96,39 @@ 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', 'origin_so', 'partner_id', 'line_ids.product_id')
+ @api.depends('origin', 'origin_so', 'partner_id', 'line_ids.product_id', 'invoice_id', 'operations')
def _compute_is_has_invoice(self):
Move = self.env['account.move']
for rec in self:
- 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
+ invoices = rec.invoice_id
+
+ if not invoices:
+ product_ids = rec.line_ids.mapped('product_id').ids
+ if product_ids:
+ domain = [
+ ('move_type', 'in', ['out_invoice', 'out_refund', 'in_invoice']),
+ ('state', 'not in', ['draft', 'cancel']),
+ ('invoice_line_ids.product_id', 'in', product_ids),
+ ]
+
+ # if rec.partner_id:
+ # domain.append(
+ # ('partner_id.commercial_partner_id', '=', rec.partner_id.commercial_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 += ['|'] * (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 = bool(invoices)
def set_opt(self):
if not self.val_inv_opt and self.is_has_invoice == True:
@@ -1009,4 +1010,4 @@ class TukarGulingMappingKoli(models.Model):
for rec in self:
if rec.tukar_guling_id and rec.tukar_guling_id.state not in ['draft', 'cancel']:
raise UserError("Tidak bisa menghapus Mapping Koli karena status Tukar Guling bukan Draft atau Cancel.")
- return super(TukarGulingMappingKoli, self).unlink()
+ return super(TukarGulingMappingKoli, self).unlink() \ No newline at end of file