diff options
| author | Miqdad <ahmadmiqdad27@gmail.com> | 2025-08-12 15:10:16 +0700 |
|---|---|---|
| committer | Miqdad <ahmadmiqdad27@gmail.com> | 2025-08-12 15:10:16 +0700 |
| commit | d896d5cb51437d366c10e854616faee46736688c (patch) | |
| tree | 066e2784c2bad72cbf925b94eb390d75460e4e94 /indoteknik_custom/models/tukar_guling.py | |
| parent | 10c2bf7111f0743941354e21f7b7ab57bb5b1d79 (diff) | |
<miqdad> get bill based on product
Diffstat (limited to 'indoteknik_custom/models/tukar_guling.py')
| -rw-r--r-- | indoteknik_custom/models/tukar_guling.py | 37 |
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: |
