diff options
| author | Miqdad <ahmadmiqdad27@gmail.com> | 2025-07-08 10:16:46 +0700 |
|---|---|---|
| committer | Miqdad <ahmadmiqdad27@gmail.com> | 2025-07-08 10:16:46 +0700 |
| commit | a8886eb056d62ace630f15fb3eaa5d55a360b277 (patch) | |
| tree | fe2ad261719501bd214cd7914897a2d4b6370e52 /indoteknik_custom/models | |
| parent | 52ed14a408f63bc7d93b7bc393a8a6eb4cd1ac08 (diff) | |
<miqdad> rev 77 check invoice
Diffstat (limited to 'indoteknik_custom/models')
| -rw-r--r-- | indoteknik_custom/models/tukar_guling.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py index 1aa5af5c..9fe7527c 100644 --- a/indoteknik_custom/models/tukar_guling.py +++ b/indoteknik_custom/models/tukar_guling.py @@ -193,18 +193,17 @@ class TukarGuling(models.Model): ('state', '!=', 'cancel') ]) > 0 - @api.onchange('return_type', 'operations') - def _onchange_check_invoice(self): + @api.constrains('return_type', 'operations') + def _check_invoice_on_revisi_so(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 + raise ValidationError( + _("Tidak bisa memilih Return Type 'Revisi SO' karena dokumen %s sudah dibuat invoice.") % record.origin ) @api.model @@ -252,6 +251,7 @@ class TukarGuling(models.Model): return new_record def write(self, vals): + self._check_invoice_on_revisi_so() if self.operations.picking_type_id.id == 30 and self.return_type == 'tukar_guling': raise UserError ("BU/PICK tidak boleh retur tukar guling") # if self.operations.picking_type_id.id != 30: @@ -304,7 +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._check_invoice_on_revisi_so() self._validate_product_lines() @@ -315,7 +315,7 @@ class TukarGuling(models.Model): def action_approve(self): self.ensure_one() self._validate_product_lines() - self._onchange_check_invoice() + self._check_invoice_on_revisi_so() if self.operations.picking_type_id.id == 30 and self.return_type == 'tukar_guling': raise UserError ("BU/PICK tidak boleh retur tukar guling") |
