diff options
| author | Miqdad <ahmadmiqdad27@gmail.com> | 2025-07-16 08:47:04 +0700 |
|---|---|---|
| committer | Miqdad <ahmadmiqdad27@gmail.com> | 2025-07-16 08:47:04 +0700 |
| commit | 77d3bd2541a52270f03b84e38dd691630bcd82af (patch) | |
| tree | 7ef3c633591cb1d7fdf0d06e5037c647ba0541b0 /indoteknik_custom/models/tukar_guling_po.py | |
| parent | 85caa56671d90cde807c44179680ef790d1a58c5 (diff) | |
<miqdad> mapping koli tukar guling
Diffstat (limited to 'indoteknik_custom/models/tukar_guling_po.py')
| -rw-r--r-- | indoteknik_custom/models/tukar_guling_po.py | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/indoteknik_custom/models/tukar_guling_po.py b/indoteknik_custom/models/tukar_guling_po.py index 3292eb7d..88c4722a 100644 --- a/indoteknik_custom/models/tukar_guling_po.py +++ b/indoteknik_custom/models/tukar_guling_po.py @@ -389,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'] @@ -404,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 @@ -428,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({ @@ -444,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) @@ -456,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, @@ -477,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, @@ -491,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.") |
