Sha256: b4c3401a18378c56a29a9dd8d6e948c0949cd801890c6198c5c97a0cea07ac1a

Contents?: true

Size: 1.97 KB

Versions: 2

Compression:

Stored size: 1.97 KB

Contents

module Comee
  module Core
    class SalesOrderItemsController < ApplicationController
      include Common

      def index
        super do
          SalesOrderItem.includes(
            :sales_order,
            :customer_order_item,
            :source,
            :product,
            :unit
          ).where(sales_order_id: params[:id])
        end
      end

      def suggest_values
        service = CustomerOrderService.new
        result = service.suggest_values(params[:id], suggest_params[:unit_id])
        render json: {success: true, data: result}
      end

      def cancel
        item = set_object
        item.update(canceled: true)
        render_content(item)
      end

      def cancel_quantity
        item = set_object
        to_cancel = cancel_quantity_params[:quantity]
        raise(StandardError, "Quantity to cancel is greater than available quantity.") if to_cancel > item.quantity_remaining

        item.quantity_canceled += to_cancel
        item.save!
        render_content(item)
      rescue StandardError => e
        render_error(e)
      end

      def activate
        item = set_object
        item.update(canceled: false)
        render_content(item)
      end

      def destroy
        Comee::Core::SalesOrderItem.destroy(params[:id])
        render json: {success: true}
      end

      private

      def suggest_params
        params.permit(:unit_id, :quantity)
      end

      def model_params
        params.require(:payload)
              .permit(:sales_order_id, :customer_order_item_id, :product_id, :unit_id, :quantity, :quantity_delivered,
                      :quantity_canceled, :customer_item_no, :customer_item_description, :price, :handover_date,
                      :delivery_date, :eb_number, :lead_time, :comment, :action_note, :purchase_order_item_id, :pallet_no,
                      :source_id, :processing_status)
      end

      def cancel_quantity_params
        params.require(:payload).permit(:quantity)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
comee_core-0.2.52 app/controllers/comee/core/sales_order_items_controller.rb
comee_core-0.2.51 app/controllers/comee/core/sales_order_items_controller.rb