Merge branch 'master' into redesign

Conflicts:
	app/assets/javascripts/templates/product_modal.html.haml
This commit is contained in:
Rohan Mitchell
2015-05-13 09:53:20 +10:00
42 changed files with 557 additions and 114 deletions

View File

@@ -144,11 +144,27 @@ class AbilityDecorator
end
can [:admin, :bulk_management], Spree::Order if user.admin? || user.enterprises.any?(&:is_distributor)
can [:admin, :create], Spree::LineItem
can [:destroy], Spree::LineItem do |item|
user.admin? || user.enterprises.include?(order.distributor) || user == order.order_cycle.manager
end
can [:admin, :index, :read, :create, :edit, :update, :fire], Spree::Payment
can [:admin, :index, :read, :create, :edit, :update, :fire], Spree::Shipment
can [:admin, :index, :read, :create, :edit, :update, :fire], Spree::Adjustment
can [:admin, :index, :read, :create, :edit, :update, :fire], Spree::ReturnAuthorization
can [:destroy], Spree::Adjustment do |adjustment|
# Sharing code with destroying a line item. This should be unified and probably applied for other actions as well.
binding.pry
if user.admin?
true
elsif adjustment.adjustable.instance_of? Spree::Order
order = adjustment.adjustable
user.enterprises.include?(order.distributor) || user == order.order_cycle.manager
elsif adjustment.adjustable.instance_of? Spree::LineItem
order = adjustment.adjustable.order
user.enterprises.include?(order.distributor) || user == order.order_cycle.manager
end
end
can [:create], OrderCycle

View File

@@ -198,6 +198,18 @@ Spree::Order.class_eval do
end
end
# Does this order have shipments that can be shipped?
def ready_to_ship?
self.shipments.any?{|s| s.can_ship?}
end
# Ship all pending orders
def ship
self.shipments.each do |s|
s.ship if s.can_ship?
end
end
def available_shipping_methods(display_on = nil)
Spree::ShippingMethod.all_available(self, display_on)
end

View File

@@ -0,0 +1,52 @@
module Spree
Payment.class_eval do
# Pin payments lacks void and credit methods, but it does have refund
# Here we swap credit out for refund and remove void as a possible action
def actions_with_pin_payment_adaptations
actions = actions_without_pin_payment_adaptations
if payment_method.is_a? Gateway::Pin
actions << 'refund' if actions.include? 'credit'
actions.reject! { |a| ['credit', 'void'].include? a }
end
actions
end
alias_method_chain :actions, :pin_payment_adaptations
def refund!(refund_amount=nil)
protect_from_connection_error do
check_environment
refund_amount = calculate_refund_amount(refund_amount)
if payment_method.payment_profiles_supported?
response = payment_method.refund((refund_amount * 100).round, source, response_code, gateway_options)
else
response = payment_method.refund((refund_amount * 100).round, response_code, gateway_options)
end
record_response(response)
if response.success?
self.class.create({ :order => order,
:source => self,
:payment_method => payment_method,
:amount => refund_amount.abs * -1,
:response_code => response.authorization,
:state => 'completed' }, :without_protection => true)
else
gateway_error(response)
end
end
end
private
def calculate_refund_amount(refund_amount=nil)
refund_amount ||= credit_allowed >= order.outstanding_balance.abs ? order.outstanding_balance.abs : credit_allowed.abs
refund_amount.to_f
end
end
end

View File

@@ -74,6 +74,12 @@ Spree::Variant.class_eval do
self.option_values.destroy ovs
end
# Used like "product.name - full_name". If called like this, a product with
# name "Bread" would be displayed as one of these:
# Bread - 1kg # if display_name blank
# Bread - Spelt Sourdough, 1kg # if display_name is "Spelt Sourdough, 1kg"
# Bread - 1kg Spelt Sourdough # if unit_to_display is "1kg Spelt Sourdough"
# Bread - Spelt Sourdough (1kg) # if display_name is "Spelt Sourdough" and unit_to_display is "1kg"
def full_name
return unit_to_display if display_name.blank?
return display_name if display_name.downcase.include? unit_to_display.downcase