diff options
| author | Miqdad <ahmadmiqdad27@gmail.com> | 2025-07-08 09:39:48 +0700 |
|---|---|---|
| committer | Miqdad <ahmadmiqdad27@gmail.com> | 2025-07-08 09:39:48 +0700 |
| commit | 52ed14a408f63bc7d93b7bc393a8a6eb4cd1ac08 (patch) | |
| tree | b5ef3f7c9c44496d343d76bff3d110b903b7c26f | |
| parent | 1ed9ce9ab59c12fa378cfab02f8919e08f424853 (diff) | |
<miqdad> rev 77 check invoice
| -rw-r--r-- | indoteknik_custom/models/tukar_guling.py | 16 |
1 files changed, 16 insertions, 0 deletions
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") |
