Skip to content

Instantly share code, notes, and snippets.

@dhonig
Created September 21, 2015 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhonig/1bd76a1735cc9f250628 to your computer and use it in GitHub Desktop.
Save dhonig/1bd76a1735cc9f250628 to your computer and use it in GitHub Desktop.
Spree::Shipment.class_eval do
audited associated_with: :order
has_associated_audits
def transfer_to_shipment(variant, quantity, shipment_to_transfer_to)
quantity_already_shipment_to_transfer_to = shipment_to_transfer_to.manifest.find{|mi| mi.line_item.variant == variant}.try(:quantity) || 0
if (quantity <= 0 || self == shipment_to_transfer_to)
raise ArgumentError
end
transaction do
order.contents.remove(variant, quantity,self)
#making the currrency nil here avoids more drastic changes
order.contents.add(variant, quantity,nil,shipment_to_transfer_to)
refresh_rates
save!
shipment_to_transfer_to.refresh_rates
shipment_to_transfer_to.save!
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment