# frozen_string_literal: true require_relative '../api_resource' module ErpIntegration module Fulfil module Resources class StockBinTransfer < ApiResource self.model_name = 'stock.bin_transfer' # Allows bulk force assign bin transfers over the API to move assigned # inventory to the new bin location. # @param id [Integer|String] The ID of the stock bin transfer. # @return [boolean] Whether the stock bin transfer was assigned force successfully or not. def assign_force(id) client.put("model/stock.bin_transfer/#{id}/assign_force") true # Fulfil will return an 400 (a.k.a. "Bad Request") status code when a bin trasfer couldn't # be done. If a bit trasfer isn't assignable by design, no exception should be raised. # # See the Fulfil's documentation for more information: # https://developers.fulfil.io/rest_api/model/stock.bin_transfer/#force-allocate-inventory-to-the-transfer rescue ErpIntegration::HttpError::BadRequest false # Workaround: Fulfil api does not return a json when status code is 200 (a.k.a. "Ok") # and faraday is having an error when trying to parse it. Let's skip the parse error # and move on. rescue Faraday::ParsingError true end # Allows bulk mark the bin transfers as done over the API to finish # moving the inventory to the new bin location. # It is better practice for inventory accuracy to mark the bin transfer # as done once the inventory is physically moved to the new location. # @param id [Integer|String] The ID of the stock bin transfer. # @return [boolean] Whether the stock bin transfer was mark as done successfully or not. def done(id) client.put("model/stock.bin_transfer/#{id}/done") true # Fulfil will return an 400 (a.k.a. "Bad Request") status code when a bin trasfer couldn't # be done. If a bit trasfer isn't doneable by design, no exception should be raised. # # See the Fulfil's documentation for more information: # https://developers.fulfil.io/rest_api/model/stock.bin_transfer/#mark-transfer-as-done rescue ErpIntegration::HttpError::BadRequest false # Workaround: Fulfil api does not return a json when status code is 200 (a.k.a. "Ok") # and faraday is having an error when trying to parse it. Let's skip the parse error # and move on. rescue Faraday::ParsingError true end end end end end