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 | |
| parent | aa217ff1809015908d7aa16683de9b9ca34e1910 (diff) | |
<miqdad> rev 77 vals
| -rw-r--r-- | indoteknik_custom/models/tukar_guling.py | 50 | ||||
| -rw-r--r-- | indoteknik_custom/models/tukar_guling_po.py | 32 | ||||
| -rw-r--r-- | indoteknik_custom/views/tukar_guling.xml | 2 |
3 files changed, 76 insertions, 8 deletions
diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py index 9fe7527c..e2f68e6c 100644 --- a/indoteknik_custom/models/tukar_guling.py +++ b/indoteknik_custom/models/tukar_guling.py @@ -251,9 +251,25 @@ class TukarGuling(models.Model): return new_record def write(self, vals): + self.ensure_one() 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") + operasi = self.operations.picking_type_id.id + tipe = self.return_type + pp = vals.get('return_type', tipe) + + if not self.operations: + raise UserError("Operations harus diisi!") + + if not self.return_type: + raise UserError("Return Type harus diisi!") + + if operasi == 30 and self.operations.linked_manual_bu_out.state == 'done': + raise UserError("❌ Tidak bisa retur BU/PICK karena BU/OUT sudah done") + if operasi == 30 and pp == 'tukar_guling': + raise UserError("❌ BU/PICK tidak boleh di retur tukar guling") + else: + _logger.info("hehhe") + # 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.") @@ -267,7 +283,11 @@ class TukarGuling(models.Model): 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") + raise UserError( + "Tidak bisa hapus pengajuan jika sudah done, set ke draft terlebih dahulu jika ingin menghapus") + ongoing_bu = self.picking_ids.filtered(lambda p: p.state != 'done') + for picking in ongoing_bu: + picking.action_cancel() return super(TukarGuling, self).unlink() def action_view_picking(self): @@ -291,6 +311,15 @@ class TukarGuling(models.Model): def action_submit(self): self.ensure_one() + + existing_tukar_guling = self.env['tukar.guling'].search([ + ('operations', '=', self.operations.id), + ('id', '!=', self.id), + ('state', '!=', 'cancel'), + ], limit=1) + + if existing_tukar_guling: + raise UserError("BU ini sudah pernah diretur oleh dokumen %s." % existing_tukar_guling.name) picking = self.operations if picking.picking_type_id.id == 30 and self.return_type == 'tukar_guling': raise UserError("❌ BU/PICK tidak boleh di retur tukar guling") @@ -307,7 +336,6 @@ class TukarGuling(models.Model): self._check_invoice_on_revisi_so() self._validate_product_lines() - if self.state != 'draft': raise UserError("Submit hanya bisa dilakukan dari Draft.") self.state = 'approval_sales' @@ -317,8 +345,16 @@ class TukarGuling(models.Model): self._validate_product_lines() 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") + operasi = self.operations.picking_type_id.id + tipe = self.return_type + pp = vals.get('return_type', tipe) + + if operasi == 30 and self.operations.linked_manual_bu_out.state == 'done': + raise UserError("❌ Tidak bisa retur BU/PICK karena BU/OUT sudah done") + if operasi == 30 and pp == 'tukar_guling': + raise UserError("❌ BU/PICK tidak boleh di retur tukar guling") + else: + _logger.info("hehhe") if not self.operations: raise UserError("Operations harus diisi!") @@ -351,7 +387,7 @@ class TukarGuling(models.Model): # picking = self.env['stock.picking'] bu_done = self.picking_ids.filtered(lambda p: p.state == 'done') if bu_done: - raise UserError("Dokuemn BU sudah Done, tidak bisa di cancel") + raise UserError("Dokuemen BU sudah Done, tidak bisa di cancel") ongoing_bu = self.picking_ids.filtered(lambda p: p.state != 'done') for picking in ongoing_bu: picking.action_cancel() 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): diff --git a/indoteknik_custom/views/tukar_guling.xml b/indoteknik_custom/views/tukar_guling.xml index 201031c4..41e9a18d 100644 --- a/indoteknik_custom/views/tukar_guling.xml +++ b/indoteknik_custom/views/tukar_guling.xml @@ -50,7 +50,7 @@ attrs="{'invisible': [('state', 'not in', ['approval_sales', 'approval_logistic', 'approval_finance'])]}"/> <button name="action_cancel" string="Cancel" type="object" class="btn-secondary" - attrs="{'invisible': [('state', 'in', ['draft', 'cancel'])]}" + attrs="{'invisible': [('state', '=', 'cancel')]}" confirm="Are you sure you want to cancel this record?"/> <button name="action_draft" string="Set to Draft" type="object" class="btn-secondary" |
