From 52ed14a408f63bc7d93b7bc393a8a6eb4cd1ac08 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Tue, 8 Jul 2025 09:39:48 +0700 Subject: rev 77 check invoice --- indoteknik_custom/models/tukar_guling.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py index 339a1ff1..1aa5af5c 100644 --- a/indoteknik_custom/models/tukar_guling.py +++ b/indoteknik_custom/models/tukar_guling.py @@ -193,6 +193,20 @@ class TukarGuling(models.Model): ('state', '!=', 'cancel') ]) > 0 + @api.onchange('return_type', 'operations') + def _onchange_check_invoice(self): + for record in self: + if record.return_type == 'revisi_so' and record.origin: + # Cek invoice yang berhubungan dengan origin SO + invoices = self.env['account.move'].search([ + ('invoice_origin', 'ilike', record.origin), + ('state', 'not in', ['draft', 'cancel']) + ]) + if invoices: + raise UserError( + _("Tidak bisa memilih Return Type 'Revisi SO' karena dokumen SO %s sudah dibuat invoice.") % record.origin + ) + @api.model def create(self, vals): # Generate sequence number @@ -290,6 +304,7 @@ class TukarGuling(models.Model): if self.operations.picking_type_id.id != 30: if self._is_already_returned(self.operations): raise UserError("BU ini sudah pernah diretur oleh dokumen lain.") + self._onchange_check_invoice() self._validate_product_lines() @@ -300,6 +315,7 @@ class TukarGuling(models.Model): def action_approve(self): self.ensure_one() self._validate_product_lines() + self._onchange_check_invoice() if self.operations.picking_type_id.id == 30 and self.return_type == 'tukar_guling': raise UserError ("BU/PICK tidak boleh retur tukar guling") -- cgit v1.2.3