summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/tukar_guling_po.py
diff options
context:
space:
mode:
Diffstat (limited to 'indoteknik_custom/models/tukar_guling_po.py')
-rw-r--r--indoteknik_custom/models/tukar_guling_po.py44
1 files changed, 20 insertions, 24 deletions
diff --git a/indoteknik_custom/models/tukar_guling_po.py b/indoteknik_custom/models/tukar_guling_po.py
index 6d7d7335..88c4722a 100644
--- a/indoteknik_custom/models/tukar_guling_po.py
+++ b/indoteknik_custom/models/tukar_guling_po.py
@@ -311,7 +311,7 @@ class TukarGulingPO(models.Model):
self._validate_product_lines()
self._check_not_allow_tukar_guling_on_bu_input()
- if self.operations and self.operations.picking_type_id.id == 28 and self.return_type == 'tukar_guling':
+ if self.operations.picking_type_id.id == 28:
group = self.operations.group_id
if group:
# Cari BU/PUT dalam group yang sama
@@ -325,11 +325,12 @@ class TukarGulingPO(models.Model):
raise UserError("❌ Tidak bisa retur BU/INPUT karena BU/PUT sudah Done!")
picking = self.operations
- if picking.picking_type_id.id == 75:
+ pick_id = self.operations.picking_type_id.id
+ if pick_id == 75:
if picking.state != 'done':
raise UserError("BU/PUT belum Done!")
- if picking.picking_type_id.id != 75 or picking.picking_type_id.id != 28:
+ if pick_id not in [75, 28]:
raise UserError("❌ Tidak bisa retur bukan BU/INPUT atau BU/PUT!")
if self._is_already_returned(self.operations):
@@ -388,7 +389,7 @@ class TukarGulingPO(models.Model):
if not record.operations:
raise UserError("BU Operations belum dipilih.")
- created_returns = []
+ created_returns = self.env['stock.picking']
group = record.operations.group_id
bu_inputs = bu_puts = self.env['stock.picking']
@@ -403,17 +404,17 @@ class TukarGulingPO(models.Model):
else:
raise UserError("Group ID tidak ditemukan pada BU Operations.")
- PARTNER_LOCATION_ID = 4
- BU_INPUT_LOCATION_ID = 58
- BU_STOCK_LOCATION_ID = 57
-
def _create_return_from_picking(picking):
if not picking:
- return None
+ return self.env['stock.picking']
grup = record.operations.group_id
- # Mapping lokasi sesuai picking type
+ # Tentukan location
+ PARTNER_LOCATION_ID = 4
+ BU_INPUT_LOCATION_ID = 58
+ BU_STOCK_LOCATION_ID = 57
+
if picking.picking_type_id.id == 28:
default_location_id = BU_INPUT_LOCATION_ID
default_location_dest_id = PARTNER_LOCATION_ID
@@ -427,7 +428,7 @@ class TukarGulingPO(models.Model):
default_location_id = PARTNER_LOCATION_ID
default_location_dest_id = BU_INPUT_LOCATION_ID
else:
- return None
+ return self.env['stock.picking']
return_context = dict(self.env.context)
return_context.update({
@@ -443,7 +444,6 @@ class TukarGulingPO(models.Model):
'original_location_id': default_location_id
})
- # Sesuai line tukar guling
return_lines = []
for line in record.line_ids:
move = picking.move_lines.filtered(lambda m: m.product_id == line.product_id)
@@ -455,20 +455,17 @@ class TukarGulingPO(models.Model):
}))
else:
raise UserError(
- _("Tidak ditemukan move line di picking %s untuk produk %s")
- % (picking.name, line.product_id.display_name)
+ _("Tidak ditemukan move line di picking %s untuk produk %s") %
+ (picking.name, line.product_id.display_name)
)
if not return_lines:
- return None
+ raise UserError(_("Tidak ada product line valid untuk retur picking %s") % picking.name)
return_wizard.product_return_moves = return_lines
return_vals = return_wizard.create_returns()
return_picking = self.env['stock.picking'].browse(return_vals.get('res_id'))
- if not return_picking:
- raise UserError("Retur gagal dibuat. Hasil create_returns: %s" % str(return_vals))
-
return_picking.write({
'location_id': default_location_id,
'location_dest_id': default_location_dest_id,
@@ -476,7 +473,6 @@ class TukarGulingPO(models.Model):
'tukar_guling_po_id': record.id,
})
- # Paksa lokasi di move lines juga
for move in return_picking.move_lines:
move.write({
'location_id': default_location_id,
@@ -490,31 +486,31 @@ class TukarGulingPO(models.Model):
# Kalau dari BU INPUT → hanya PRT
prt = _create_return_from_picking(record.operations)
if prt:
- created_returns.append(prt)
+ created_returns |= prt
else:
# 1. Dari BU PUT buat VRT
for bu_put in bu_puts:
vrt = _create_return_from_picking(bu_put)
if vrt:
- created_returns.append(vrt)
+ created_returns |= vrt
# 2. Dari BU INPUT buat PRT
for bu_input in bu_inputs:
prt = _create_return_from_picking(bu_input)
if prt:
- created_returns.append(prt)
+ created_returns |= prt
# 3. Kalau tukar guling buat lanjut INPUT & PUT
if record.return_type == 'tukar_guling':
for prt in created_returns.filtered(lambda p: p.picking_type_id.id == 76):
bu_input = _create_return_from_picking(prt)
if bu_input:
- created_returns.append(bu_input)
+ created_returns |= bu_input
for vrt in created_returns.filtered(lambda p: p.picking_type_id.id == 77):
bu_put = _create_return_from_picking(vrt)
if bu_put:
- created_returns.append(bu_put)
+ created_returns |= bu_put
if not created_returns:
raise UserError("Tidak ada dokumen retur yang berhasil dibuat.")