summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/tukar_guling.py
diff options
context:
space:
mode:
authorIndoteknik . <it@fixcomart.co.id>2025-08-13 16:59:14 +0700
committerIndoteknik . <it@fixcomart.co.id>2025-08-13 16:59:14 +0700
commita19a78db2e3ff278ef56007629f3d9f5e9c89110 (patch)
treeb6adadf3db706ef2c50129f6b4b3019a90939b22 /indoteknik_custom/models/tukar_guling.py
parent2f31e36104c0b92bf022dc78b3952f08815dd1cc (diff)
parent497cb94e2c75f6f3b0066700ed1f4b1be9ed1a59 (diff)
Merge branch 'odoo-backup' of https://bitbucket.org/altafixco/indoteknik-addons into pum-v2
Diffstat (limited to 'indoteknik_custom/models/tukar_guling.py')
-rw-r--r--indoteknik_custom/models/tukar_guling.py37
1 files changed, 28 insertions, 9 deletions
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: