diff options
| author | Miqdad <ahmadmiqdad27@gmail.com> | 2025-07-09 13:14:59 +0700 |
|---|---|---|
| committer | Miqdad <ahmadmiqdad27@gmail.com> | 2025-07-09 13:14:59 +0700 |
| commit | 717dbfa7070e94c0af2bb39e2cebb4dc71d123b9 (patch) | |
| tree | 9db580d9b6e5d005f2b3b98ade10b25e079aa1ea /indoteknik_custom/models/tukar_guling_po.py | |
| parent | aedf25e194d4ddddab9b158b473164151109edaf (diff) | |
<miqdad> rev 77 vals vals
Diffstat (limited to 'indoteknik_custom/models/tukar_guling_po.py')
| -rw-r--r-- | indoteknik_custom/models/tukar_guling_po.py | 41 |
1 files changed, 33 insertions, 8 deletions
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: |
