mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-13 04:00:21 +00:00
Variant calculates fees and its price inclusive of fees
This commit is contained in:
@@ -143,18 +143,27 @@ class OrderCycle < ActiveRecord::Base
|
||||
|
||||
|
||||
# -- Fees
|
||||
def fees_for(variant, distributor)
|
||||
enterprise_fees_for(variant, distributor).sum do |fee|
|
||||
# Spree's Calculator interface accepts Orders or LineItems,
|
||||
# so we meet that interface with a struct.
|
||||
line_item = OpenStruct.new variant: variant, quantity: 1
|
||||
fee[:enterprise_fee].compute_amount(line_item)
|
||||
end
|
||||
end
|
||||
|
||||
def create_adjustments_for(line_item)
|
||||
variant = line_item.variant
|
||||
distributor = line_item.order.distributor
|
||||
|
||||
fees_for(variant, distributor).each { |fee| create_adjustment_for_fee line_item, fee[:enterprise_fee], fee[:label], fee[:role] }
|
||||
enterprise_fees_for(variant, distributor).each { |fee| create_adjustment_for_fee line_item, fee[:enterprise_fee], fee[:label], fee[:role] }
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
# -- Fees
|
||||
def fees_for(variant, distributor)
|
||||
def enterprise_fees_for(variant, distributor)
|
||||
fees = []
|
||||
|
||||
exchanges_carrying(variant, distributor).each do |exchange|
|
||||
|
||||
@@ -12,6 +12,18 @@ Spree::Variant.class_eval do
|
||||
after_save :update_units
|
||||
|
||||
|
||||
def price_with_fees(distributor, order_cycle)
|
||||
price + fees_for(distributor, order_cycle)
|
||||
end
|
||||
|
||||
# TODO: This method seems a little redundant. Though perhaps a useful interface.
|
||||
# Consider removing.
|
||||
def fees_for(distributor, order_cycle)
|
||||
order_cycle.fees_for(self, distributor)
|
||||
end
|
||||
|
||||
|
||||
|
||||
# Copied and modified from Spree::Variant
|
||||
def options_text
|
||||
values = self.option_values.joins(:option_type).order("#{Spree::OptionType.table_name}.position asc")
|
||||
|
||||
Reference in New Issue
Block a user