diff options
| author | Miqdad <ahmadmiqdad27@gmail.com> | 2025-07-09 09:54:13 +0700 |
|---|---|---|
| committer | Miqdad <ahmadmiqdad27@gmail.com> | 2025-07-09 09:54:13 +0700 |
| commit | 21128e0f165045558c2c8ef6faf199d4379614b1 (patch) | |
| tree | 4441fe9c8d4464424505524d6ae097dfff557145 /indoteknik_custom/models/tukar_guling_po.py | |
| parent | aa217ff1809015908d7aa16683de9b9ca34e1910 (diff) | |
<miqdad> rev 77 vals
Diffstat (limited to 'indoteknik_custom/models/tukar_guling_po.py')
| -rw-r--r-- | indoteknik_custom/models/tukar_guling_po.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/indoteknik_custom/models/tukar_guling_po.py b/indoteknik_custom/models/tukar_guling_po.py index 2e0ab604..e9dfda33 100644 --- a/indoteknik_custom/models/tukar_guling_po.py +++ b/indoteknik_custom/models/tukar_guling_po.py @@ -65,6 +65,20 @@ class TukarGulingPO(models.Model): return super(TukarGulingPO, self).create(vals) + @api.constrains('return_type', 'operations') + def _check_bill_on_revisi_po(self): + for record in self: + if record.return_type == 'revisi_po' and record.origin: + bills = self.env['account.move'].search([ + ('invoice_origin', 'ilike', record.origin), + ('move_type', '=', 'in_invoice'), # hanya vendor bill + ('state', 'not in', ['draft', 'cancel']) + ]) + if bills: + raise ValidationError( + _("Tidak bisa memilih Return Type 'Revisi PO' karena PO %s sudah dibuat vendor bill.") % record.origin + ) + @api.onchange('operations') def _onchange_operations(self): """Auto-populate lines ketika operations dipilih""" @@ -224,6 +238,7 @@ class TukarGulingPO(models.Model): return new_record def write(self, vals): + self._check_bill_on_revisi_po() if self.operations.picking_type_id.id != 28: if self._is_already_returned(self.operations): raise UserError("BU ini sudah pernah diretur oleh dokumen lain.") @@ -234,6 +249,15 @@ class TukarGulingPO(models.Model): return super(TukarGulingPO, self).write(vals) + def unlink(self): + for record in self: + if record.state == 'done': + raise UserError ("Tidak bisa hapus pengajuan jika sudah done, set ke draft terlebih dahulu") + ongoing_bu = self.po_picking_ids.filtered(lambda p: p.state != 'done') + for picking in ongoing_bu: + picking.action_cancel() + return super(TukarGulingPO, self).unlink() + def action_view_picking(self): self.ensure_one() action = self.env.ref('stock.action_picking_tree_all').read()[0] @@ -255,6 +279,7 @@ class TukarGulingPO(models.Model): def action_submit(self): self.ensure_one() + self._check_bill_on_revisi_po() picking = self.operations if picking.picking_type_id.id == 75: if picking.state != 'done': @@ -276,6 +301,7 @@ class TukarGulingPO(models.Model): def action_approve(self): self.ensure_one() self._validate_product_lines() + self._check_bill_on_revisi_po() if not self.operations: raise UserError("Operations harus diisi!") @@ -307,6 +333,12 @@ class TukarGulingPO(models.Model): self.ensure_one() # if self.state == 'done': # raise UserError("Tidak bisa cancel jika sudah done") + bu_done = self.po_picking_ids.filtered(lambda p: p.state == 'done') + if bu_done: + raise UserError("Dokuemn BU sudah Done, tidak bisa di cancel") + ongoing_bu = self.po_picking_ids.filtered(lambda p: p.state != 'done') + for picking in ongoing_bu: + picking.action_cancel() self.state = 'cancel' def _create_pickings(self): |
