module Returnly module Builders class CustomerReturn class << self def build_by_return_items(return_items) Spree::CustomerReturn.create( return_items: return_items, stock_location_id: stock_location_id(return_items.first) ) end def build_by_stock_location(stock_location) Spree::CustomerReturn.new(stock_location: stock_location) end private def stock_location_id(return_item) return_item_order(return_item).shipments.last.stock_location_id end def return_item_order(return_item) return_item.inventory_unit.order end end end end end