diff --git a/app/models/billable_period.rb b/app/models/billable_period.rb index d3a58e3745..d2ca41b0a9 100644 --- a/app/models/billable_period.rb +++ b/app/models/billable_period.rb @@ -71,7 +71,7 @@ class BillablePeriod < ActiveRecord::Base source: self, originator: nil, # enterprise.package mandatory: true, - locked: false + state: 'closed' } end end diff --git a/app/models/enterprise_fee.rb b/app/models/enterprise_fee.rb index ff118cf0aa..e7e8ee0513 100644 --- a/app/models/enterprise_fee.rb +++ b/app/models/enterprise_fee.rb @@ -54,19 +54,6 @@ class EnterpriseFee < ActiveRecord::Base order.adjustments.where(originator_type: 'EnterpriseFee').destroy_all end - # Create an adjustment that starts as locked. Preferable to making an adjustment and locking it since - # the unlocked adjustment tends to get hit by callbacks before we have a chance to lock it. - def create_locked_adjustment(label, target, calculable, mandatory=false) - amount = compute_amount(calculable) - return if amount == 0 && !mandatory - target.adjustments.create({ :amount => amount, - :source => calculable, - :originator => self, - :label => label, - :mandatory => mandatory, - :locked => true}, :without_protection => true) - end - private diff --git a/app/models/product_distribution.rb b/app/models/product_distribution.rb index e866d3860b..a18d9d638c 100644 --- a/app/models/product_distribution.rb +++ b/app/models/product_distribution.rb @@ -17,7 +17,7 @@ class ProductDistribution < ActiveRecord::Base end def create_adjustment_for(line_item) - a = enterprise_fee.create_locked_adjustment(adjustment_label_for(line_item), line_item.order, line_item, true) + a = enterprise_fee.create_adjustment(adjustment_label_for(line_item), 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: 'distributor' end diff --git a/app/models/spree/line_item_decorator.rb b/app/models/spree/line_item_decorator.rb index 9c80df8bb4..4985d059b0 100644 --- a/app/models/spree/line_item_decorator.rb +++ b/app/models/spree/line_item_decorator.rb @@ -60,7 +60,7 @@ Spree::LineItem.class_eval do end def price_with_adjustments - # EnterpriseFee#create_locked_adjustment applies adjustments on line items to their parent order, + # EnterpriseFee#create_adjustment applies adjustments on line items to their parent order, # so line_item.adjustments returns an empty array return 0 if quantity == 0 (price + order.adjustments.where(source_id: id).sum(&:amount) / quantity).round(2) diff --git a/lib/open_food_network/enterprise_fee_applicator.rb b/lib/open_food_network/enterprise_fee_applicator.rb index e6d52e1749..e213204047 100644 --- a/lib/open_food_network/enterprise_fee_applicator.rb +++ b/lib/open_food_network/enterprise_fee_applicator.rb @@ -1,7 +1,7 @@ module OpenFoodNetwork class EnterpriseFeeApplicator < Struct.new(:enterprise_fee, :variant, :role) def create_line_item_adjustment(line_item) - a = enterprise_fee.create_locked_adjustment(line_item_adjustment_label, line_item.order, line_item, true) + 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 @@ -9,7 +9,7 @@ module OpenFoodNetwork end def create_order_adjustment(order) - a = enterprise_fee.create_locked_adjustment(order_adjustment_label, order, order, true) + 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 diff --git a/spec/models/enterprise_fee_spec.rb b/spec/models/enterprise_fee_spec.rb index e0df4ce5d0..6c4245c875 100644 --- a/spec/models/enterprise_fee_spec.rb +++ b/spec/models/enterprise_fee_spec.rb @@ -170,7 +170,7 @@ describe EnterpriseFee do order.adjustments.create({:amount => 12.34, :source => order, :originator => tax_rate, - :locked => true, + :state => 'closed', :label => 'hello' }, :without_protection => true) expect do diff --git a/spec/models/product_distribution_spec.rb b/spec/models/product_distribution_spec.rb index 7e1a6933bc..2fa2bab427 100644 --- a/spec/models/product_distribution_spec.rb +++ b/spec/models/product_distribution_spec.rb @@ -78,7 +78,7 @@ describe ProductDistribution do it "returns the adjustment when present" do pd = create(:product_distribution) line_item = create(:line_item) - adjustment = pd.enterprise_fee.create_locked_adjustment('foo', line_item.order, line_item, true) + adjustment = pd.enterprise_fee.create_adjustment('foo', line_item.order, line_item, true) pd.send(:adjustment_for, line_item).should == adjustment end @@ -86,8 +86,8 @@ describe ProductDistribution do it "raises an error when there are multiple adjustments for this enterprise fee" do pd = create(:product_distribution) line_item = create(:line_item) - pd.enterprise_fee.create_locked_adjustment('one', line_item.order, line_item, true) - pd.enterprise_fee.create_locked_adjustment('two', line_item.order, line_item, true) + pd.enterprise_fee.create_adjustment('one', line_item.order, line_item, true) + pd.enterprise_fee.create_adjustment('two', line_item.order, line_item, true) expect do pd.send(:adjustment_for, line_item) diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index e7c46c27cb..392d9664fa 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -140,7 +140,7 @@ describe Spree::Order do it "returns the sum of eligible enterprise fee adjustments" do ef = create(:enterprise_fee, calculator: Spree::Calculator::FlatRate.new ) ef.calculator.set_preference :amount, 123.45 - a = ef.create_locked_adjustment("adjustment", o, o, true) + a = ef.create_adjustment("adjustment", o, o, true) o.admin_and_handling_total.should == 123.45 end @@ -148,7 +148,7 @@ describe Spree::Order do it "does not include ineligible adjustments" do ef = create(:enterprise_fee, calculator: Spree::Calculator::FlatRate.new ) ef.calculator.set_preference :amount, 123.45 - a = ef.create_locked_adjustment("adjustment", o, o, true) + a = ef.create_adjustment("adjustment", o, o, true) a.update_column :eligible, false