diff options
| -rw-r--r-- | indoteknik_custom/models/tukar_guling.py | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/indoteknik_custom/models/tukar_guling.py b/indoteknik_custom/models/tukar_guling.py index 456a2111..dfa62dc8 100644 --- a/indoteknik_custom/models/tukar_guling.py +++ b/indoteknik_custom/models/tukar_guling.py @@ -202,7 +202,7 @@ class TukarGuling(models.Model): if sequence: default['name'] = sequence.next_by_id() else: - default['name'] = self.env['ir.sequence'].next_by_code('tukar.guling') or 'PTG-COPY' + default['name'] = self.env['ir.sequence'].next_by_code('tukar.guling') or 'copy' default.update({ 'state': 'draft', @@ -312,6 +312,7 @@ class TukarGuling(models.Model): created_returns = [] + # Lokasi default untuk retur srt_type = self.env['stock.picking.type'].browse(73) ort_type = self.env['stock.picking.type'].browse(74) @@ -329,12 +330,6 @@ class TukarGuling(models.Model): if not ort_src or not ort_dest or not srt_src or not srt_dest: raise UserError("salahwoi") - partner_location = self.env['stock.location'].search( - [('complete_name', 'ilike', 'Partner Locations/Customers'), - ('id', '=', '5')]) - if not partner_location: - raise UserError("Lokasi partner salah atau tidak ditemukan pada BU/OUT.") - # Fungsi membuat retur dari picking tertentu def _create_return_from_picking(picking): grup = self.operations.group_id @@ -348,19 +343,28 @@ class TukarGuling(models.Model): return_type = ort_type default_location_id = BU_OUTPUT_LOCATION_ID default_location_dest_id = BU_STOCK_LOCATION_ID + if not default_location_id or not default_location_dest_id: + raise UserError("Lokasi Origin atau Destination salah.") elif picking.picking_type_id.id == 29: # -> ngeretur bu out return_type = srt_type default_location_id = PARTNER_LOCATION_ID default_location_dest_id = BU_OUTPUT_LOCATION_ID + if not default_location_id or not default_location_dest_id: + raise UserError("Lokasi Origin atau Destination salah.") elif picking.picking_type_id.id == 74: # -> ngeretur srt return_type = bu_pick_type default_location_id = BU_STOCK_LOCATION_ID default_location_dest_id = BU_OUTPUT_LOCATION_ID + if not default_location_id or not default_location_dest_id: + raise UserError("Lokasi Origin atau Destination salah.") elif picking.picking_type_id.id == 73: # -> ngeretur ort return_type = bu_out_type default_location_id = BU_OUTPUT_LOCATION_ID default_location_dest_id = PARTNER_LOCATION_ID + if not default_location_id or not default_location_dest_id: + raise UserError("Lokasi Origin atau Destination salah.") else: + raise UserError("Hayo") return None return_context = dict(self.env.context) @@ -379,12 +383,12 @@ class TukarGuling(models.Model): # Create return lines return_lines = [] - for move in picking.move_lines: - qty = move.quantity_done or move.product_uom_qty - if qty > 0: + for line in record.line_ids: + move = picking.move_lines.filtered(lambda wkwk: wkwk.product_id == line.product_id) + if move: return_lines.append((0, 0, { - 'product_id': move.product_id.id, - 'quantity': qty, + 'product_id': line.product_id.id, + 'quantity': line.product_uom_qty, 'move_id': move.id, })) if not return_lines: |
