Created
September 21, 2015 20:14
-
-
Save dhonig/1bd76a1735cc9f250628 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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