mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-12 03:50:22 +00:00
Revert "Merge pull request #2856 from luisramos0/2-0-adjust-clean-up"
This reverts commitfa689b6607, reversing changes made to2aeed9763c.
This commit is contained in:
@@ -1,33 +1,24 @@
|
||||
module OpenFoodNetwork
|
||||
class EnterpriseFeeApplicator < Struct.new(:enterprise_fee, :variant, :role)
|
||||
def create_line_item_adjustment(line_item)
|
||||
create_adjustment(line_item_adjustment_label, line_item.order, line_item)
|
||||
a = enterprise_fee.create_adjustment(line_item_adjustment_label, line_item.order, line_item, true)
|
||||
|
||||
AdjustmentMetadata.create! adjustment: a, enterprise: enterprise_fee.enterprise, fee_name: enterprise_fee.name, fee_type: enterprise_fee.fee_type, enterprise_role: role
|
||||
|
||||
a.set_absolute_included_tax! adjustment_tax(line_item, a)
|
||||
end
|
||||
|
||||
def create_order_adjustment(order)
|
||||
create_adjustment(order_adjustment_label, order, order)
|
||||
a = enterprise_fee.create_adjustment(order_adjustment_label, order, order, true)
|
||||
|
||||
AdjustmentMetadata.create! adjustment: a, enterprise: enterprise_fee.enterprise, fee_name: enterprise_fee.name, fee_type: enterprise_fee.fee_type, enterprise_role: role
|
||||
|
||||
a.set_absolute_included_tax! adjustment_tax(order, a)
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def create_adjustment(label, target, calculable)
|
||||
adjustment = create_enterprise_fee_adjustment(label, target, calculable)
|
||||
|
||||
AdjustmentMetadata.create! adjustment: adjustment, enterprise: enterprise_fee.enterprise, fee_name: enterprise_fee.name, fee_type: enterprise_fee.fee_type, enterprise_role: role
|
||||
|
||||
adjustment.set_absolute_included_tax! adjustment_tax(adjustment)
|
||||
end
|
||||
|
||||
def create_enterprise_fee_adjustment(label, target, calculable)
|
||||
adjustment = enterprise_fee.create_adjustment(label, target, calculable, true)
|
||||
|
||||
# This is necessary when source is a line_item
|
||||
# probably because the association order.adjustments contains "inverse_of :source"
|
||||
# which overrides the value (the line item) set in calculated_adjustment.create_adjustment
|
||||
adjustment.source = calculable
|
||||
adjustment
|
||||
end
|
||||
|
||||
def line_item_adjustment_label
|
||||
"#{variant.product.name} - #{base_adjustment_label}"
|
||||
end
|
||||
@@ -40,7 +31,7 @@ module OpenFoodNetwork
|
||||
I18n.t(:enterprise_fee_by, type: enterprise_fee.fee_type, role: role, enterprise_name: enterprise_fee.enterprise.name)
|
||||
end
|
||||
|
||||
def adjustment_tax(adjustment)
|
||||
def adjustment_tax(adjustable, adjustment)
|
||||
tax_rates = adjustment.tax_rates
|
||||
|
||||
tax_rates.select(&:included_in_price).sum do |rate|
|
||||
|
||||
16
lib/spree/core/calculated_adjustments_decorator.rb
Normal file
16
lib/spree/core/calculated_adjustments_decorator.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
module Spree
|
||||
module Core
|
||||
module CalculatedAdjustments
|
||||
class << self
|
||||
def included_with_explicit_class_name(klass)
|
||||
included_without_explicit_class_name(klass)
|
||||
|
||||
klass.class_eval do
|
||||
has_one :calculator, as: :calculable, dependent: :destroy, class_name: 'Spree::Calculator'
|
||||
end
|
||||
end
|
||||
alias_method_chain :included, :explicit_class_name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user