Untitled

mail@pastecode.io avatar
unknown
ruby
24 days ago
2.6 kB
6
Indexable
Never
tl_display_id_inputs = ["TL134121597"]
warehouse_id = "blr_wfld"

def get_outbound_requests_for_transfer_list(transfer_list_display_id, warehouse_id)
  data_service = DataServiceFactory.get_transfer_list_data_service(warehouse_id)

  transfer_list = data_service.get_vo_by_display_id(transfer_list_display_id)
  movement_request_item_ids = transfer_list.transfer_list_items.collect(&:movement_request_item_id)
  movement_request_service = BusinessServiceFactory.get_movement_request_service(warehouse_id)
  movement_request_items = movement_request_service.get_movement_request_item_vo_by_ids(movement_request_item_ids)
  movement_request_ids = movement_request_items.collect(&:movement_request_id).compact.uniq
  outbound_requests = []
  movement_request_ids.each do |mr_id|
    outbound_requests << movement_request_service.get_outbound_request_for_movement_request_id(mr_id)
  end
  outbound_requests
end

def create_cosignment_for_tl_id(tl_display_id_inputs, warehouse_id)
  transfer_list_service = BusinessServiceFactory.get_transfer_list_service(warehouse_id)
  outbound_request_service = BusinessServiceFactory.get_outbound_request_service(warehouse_id)
  movement_request_service = BusinessServiceFactory.get_movement_request_service(warehouse_id)
  ShardManager.new.using_shard_for_warehouse_id(@warehouse_id) do
    tl_display_id_inputs.each do |tl_id|
      transfer_list_vo = transfer_list_service.get_vo_by_display_id(tl_id)
      if transfer_list_vo.status != "picked"
        next
      end
      movement_request = movement_request_service.get_vos_by_ids([transfer_list_vo.movement_request_id]).first
      outbound_request = outbound_request_service.get_vos_by_ids([movement_request.group_id]).first

      if outbound_request && outbound_request.consignment_id.nil?
        all_outbound_requests_in_transfer_list = get_outbound_requests_for_transfer_list(tl_id, warehouse_id)

        all_outbound_requests_in_transfer_list.each do |oreq|

          consignment = outbound_request_service.get_consignment_vo_for_request_id(oreq.id)

          if consignment && !consignment.consignment_items.nil?
            ob_req_id = oreq.id
            movement_request_data_service = DataServiceFactory.get_movement_request_data_service(warehouse_id)
            movement_request_vo = movement_request_data_service.get_vos_by_group_id_and_group_type(ob_req_id, "OutboundRequest")
            mreq_id = movement_request_vo.id
            transfer_list_vo.movement_request_id = mreq_id
            break # break from this iteration and move to next iteration of tl id in initial for loop
          end

        end
      end
    end
  end
end
Leave a Comment