diff options
| author | Miqdad <ahmadmiqdad27@gmail.com> | 2025-07-17 13:42:53 +0700 |
|---|---|---|
| committer | Miqdad <ahmadmiqdad27@gmail.com> | 2025-07-17 13:42:53 +0700 |
| commit | c18b38bc03d9c260532f4a8e956b51421283fa73 (patch) | |
| tree | a0b08389734138b13935d88eb28370540b900add | |
| parent | 3c7d7783aa15fee124d94839822614de4049b9c1 (diff) | |
<miqdad> FIx bug Tukar Guling SO
| -rw-r--r-- | indoteknik_custom/models/tukar_guling.py | 71 |
1 files changed, 36 insertions, 35 deletions
diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py index ded4e2a3..20d43e4c 100644 --- a/indoteknik_custom/models/tukar_guling.py +++ b/indoteknik_custom/models/tukar_guling.py @@ -580,41 +580,6 @@ class TukarGuling(models.Model): ### ======== Tukar Guling: BU/OUT dan BU/PICK baru ======== if record.return_type == 'tukar_guling': - # BU/OUT Baru dari SRT - if srt_picking: - return_lines = [] - for move in srt_picking.move_lines: - if move.product_uom_qty > 0: - return_lines.append((0, 0, { - 'product_id': move.product_id.id, - 'quantity': move.product_uom_qty, - 'move_id': move.id, - })) - _logger.info( - f"🔁 BU/OUT baru dari SRT | {move.product_id.display_name} | qty={move.product_uom_qty}") - - bu_out_wizard = self.env['stock.return.picking'].with_context({ - 'active_id': srt_picking.id, - 'default_location_id': BU_OUTPUT_LOCATION_ID, - 'default_location_dest_id': PARTNER_LOCATION_ID, - 'from_ui': False, - }).create({ - 'picking_id': srt_picking.id, - 'location_id': BU_OUTPUT_LOCATION_ID, - 'original_location_id': PARTNER_LOCATION_ID, - 'product_return_moves': return_lines - }) - bu_out_vals = bu_out_wizard.create_returns() - new_out = self.env['stock.picking'].browse(bu_out_vals['res_id']) - new_out.write({ - 'location_id': BU_OUTPUT_LOCATION_ID, - 'location_dest_id': PARTNER_LOCATION_ID, - 'group_id': bu_out.group_id.id, - 'tukar_guling_id': record.id, - 'sale_order': record.origin - }) - created_returns.append(new_out) - _logger.info(f"✅ BU/OUT Baru dari SRT created: {new_out.name}") # BU/PICK Baru dari ORT for ort_p in ort_pickings: @@ -658,6 +623,42 @@ class TukarGuling(models.Model): created_returns.append(new_pick) _logger.info(f"✅ BU/PICK Baru dari ORT created: {new_pick.name}") + # BU/OUT Baru dari SRT + if srt_picking: + return_lines = [] + for move in srt_picking.move_lines: + if move.product_uom_qty > 0: + return_lines.append((0, 0, { + 'product_id': move.product_id.id, + 'quantity': move.product_uom_qty, + 'move_id': move.id, + })) + _logger.info( + f"🔁 BU/OUT baru dari SRT | {move.product_id.display_name} | qty={move.product_uom_qty}") + + bu_out_wizard = self.env['stock.return.picking'].with_context({ + 'active_id': srt_picking.id, + 'default_location_id': BU_OUTPUT_LOCATION_ID, + 'default_location_dest_id': PARTNER_LOCATION_ID, + 'from_ui': False, + }).create({ + 'picking_id': srt_picking.id, + 'location_id': BU_OUTPUT_LOCATION_ID, + 'original_location_id': PARTNER_LOCATION_ID, + 'product_return_moves': return_lines + }) + bu_out_vals = bu_out_wizard.create_returns() + new_out = self.env['stock.picking'].browse(bu_out_vals['res_id']) + new_out.write({ + 'location_id': BU_OUTPUT_LOCATION_ID, + 'location_dest_id': PARTNER_LOCATION_ID, + 'group_id': bu_out.group_id.id, + 'tukar_guling_id': record.id, + 'sale_order': record.origin + }) + created_returns.append(new_out) + _logger.info(f"✅ BU/OUT Baru dari SRT created: {new_out.name}") + if not created_returns: raise UserError("Tidak ada dokumen retur berhasil dibuat.") |
