summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiqdad <ahmadmiqdad27@gmail.com>2025-07-09 13:14:59 +0700
committerMiqdad <ahmadmiqdad27@gmail.com>2025-07-09 13:14:59 +0700
commit717dbfa7070e94c0af2bb39e2cebb4dc71d123b9 (patch)
tree9db580d9b6e5d005f2b3b98ade10b25e079aa1ea
parentaedf25e194d4ddddab9b158b473164151109edaf (diff)
<miqdad> rev 77 vals vals
-rw-r--r--indoteknik_custom/models/tukar_guling.py11
-rw-r--r--indoteknik_custom/models/tukar_guling_po.py41
2 files changed, 38 insertions, 14 deletions
diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py
index e2f68e6c..5762abbb 100644
--- a/indoteknik_custom/models/tukar_guling.py
+++ b/indoteknik_custom/models/tukar_guling.py
@@ -270,9 +270,7 @@ class TukarGuling(models.Model):
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.")
+
if 'operations' in vals and not vals.get('origin'):
picking = self.env['stock.picking'].browse(vals['operations'])
if picking.origin:
@@ -330,9 +328,8 @@ class TukarGuling(models.Model):
linked_bu_out = picking.linked_manual_bu_out
if linked_bu_out and linked_bu_out.state == 'done':
raise UserError("❌ Tidak bisa retur BU/PICK karena BU/OUT suda Done!")
- 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.")
+ if self._is_already_returned(self.operations):
+ raise UserError("BU ini sudah pernah diretur oleh dokumen lain.")
self._check_invoice_on_revisi_so()
self._validate_product_lines()
@@ -527,10 +524,12 @@ class TukarGuling(models.Model):
return return_picking
+ # CASE: Kalau retur BU/PICK jadi ort saja
if record.operations.picking_type_id.id == 30:
ort = _create_return_from_picking(record.operations)
if ort:
created_returns.append(ort)
+ # Kalau retur BU/OUT
else:
# CASE: Retur dari BU/OUT
srt = _create_return_from_picking(bu_out_to_return)
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: