From 717dbfa7070e94c0af2bb39e2cebb4dc71d123b9 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Wed, 9 Jul 2025 13:14:59 +0700 Subject: rev 77 vals vals --- indoteknik_custom/models/tukar_guling_po.py | 41 +++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 8 deletions(-) (limited to 'indoteknik_custom/models/tukar_guling_po.py') diff --git a/indoteknik_custom/models/tukar_guling_po.py b/indoteknik_custom/models/tukar_guling_po.py index aa8fd1f3..9bcced0d 100644 --- a/indoteknik_custom/models/tukar_guling_po.py +++ b/indoteknik_custom/models/tukar_guling_po.py @@ -241,11 +241,22 @@ class TukarGulingPO(models.Model): self._check_bill_on_revisi_po() tipe = vals.get('return_type', self.return_type) + if self.operations and self.operations.picking_type_id.id == 28 and tipe == 'tukar_guling': + group = self.operations.group_id + if group: + # Cari BU/PUT dalam group yang sama + bu_put = self.env['stock.picking'].search([ + ('group_id', '=', group.id), + ('picking_type_id.id', '=', 75), # 75 = ID BU/PUT + ('state', '=', 'done') + ], limit=1) + + if bu_put: + raise UserError("❌ Tidak bisa retur BU/INPUT karena BU/PUT sudah Done!") if self.operations.picking_type_id.id == 28 and tipe == 'tukar_guling': raise UserError("❌ BU/INPUT tidak boleh di retur tukar guling") - 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.") @@ -287,19 +298,31 @@ class TukarGulingPO(models.Model): def action_submit(self): self.ensure_one() self._check_bill_on_revisi_po() + self._validate_product_lines() + + if self.operations and self.operations.picking_type_id.id == 28 and self.return_type == 'tukar_guling': + group = self.operations.group_id + if group: + # Cari BU/PUT dalam group yang sama + bu_put = self.env['stock.picking'].search([ + ('group_id', '=', group.id), + ('picking_type_id.id', '=', 75), + ('state', '=', 'done') + ], limit=1) + + if bu_put: + raise UserError("❌ Tidak bisa retur BU/INPUT karena BU/PUT sudah Done!") + picking = self.operations if picking.picking_type_id.id == 75: if picking.state != 'done': raise UserError("BU/PUT belum Done!") - elif picking.picking_type_id.id == 28: - linked_bu_out = picking.linked_manual_bu_out - if linked_bu_out and linked_bu_out.state == 'done': - raise UserError("❌ Tidak bisa retur BU/INPUT karena BU/PUT suda Done!") + if picking.picking_type_id.id != 75 or picking.picking_type_id.id != 28: - if self._is_already_returned(self.operations): - raise UserError("BU ini sudah pernah diretur oleh dokumen lain.") - self._validate_product_lines() + raise UserError("❌ Tidak bisa retur bukan BU/INPUT atau BU/PUT!") + if self._is_already_returned(self.operations): + raise UserError("BU ini sudah pernah diretur oleh dokumen lain.") if self.state != 'draft': raise UserError("Submit hanya bisa dilakukan dari Draft.") @@ -457,10 +480,12 @@ class TukarGulingPO(models.Model): return return_picking + # Kalau retur BU/INPUT Buat prt saja if record.operations.picking_type_id.id == 28: prt = _create_return_from_picking(record.operations) if prt: created_returns.append(prt) + # Kalau retur BU/PUT else: vrt = _create_return_from_picking(bu_put_to_return) if vrt: -- cgit v1.2.3