mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Remove code related to promotions, we dont have promotions in OFN
This commit is contained in:
@@ -67,7 +67,6 @@ module Spree
|
||||
scope :optional, -> { where(mandatory: false) }
|
||||
scope :charge, -> { where('amount >= 0') }
|
||||
scope :credit, -> { where('amount < 0') }
|
||||
scope :promotion, -> { where(originator_type: 'Spree::PromotionAction') }
|
||||
scope :return_authorization, -> { where(source_type: "Spree::ReturnAuthorization") }
|
||||
|
||||
scope :enterprise_fee, -> { where(originator_type: 'EnterpriseFee') }
|
||||
@@ -84,14 +83,10 @@ module Spree
|
||||
|
||||
localize_number :amount
|
||||
|
||||
def promotion?
|
||||
originator_type == 'Spree::PromotionAction'
|
||||
end
|
||||
|
||||
# Update the boolean _eligible_ attribute which determines which adjustments
|
||||
# count towards the order's adjustment_total.
|
||||
def set_eligibility
|
||||
result = mandatory || ((amount != 0 || promotion?) && eligible_for_originator?)
|
||||
result = mandatory || (amount != 0 && eligible_for_originator?)
|
||||
update_column(:eligible, result)
|
||||
end
|
||||
|
||||
|
||||
@@ -182,7 +182,7 @@ module Spree
|
||||
options.merge!({ shipping: order.ship_total * 100,
|
||||
tax: order.tax_total * 100,
|
||||
subtotal: order.item_total * 100,
|
||||
discount: order.promo_total * 100,
|
||||
discount: 0,
|
||||
currency: currency })
|
||||
|
||||
options.merge!({ billing_address: order.bill_address.try(:active_merchant_hash),
|
||||
|
||||
@@ -21,25 +21,30 @@ module Spree
|
||||
allow(originator).to receive_messages update_amount: true
|
||||
allow(adjustment).to receive_messages originator: originator, label: 'adjustment', amount: 0
|
||||
end
|
||||
|
||||
it "should do nothing when closed" do
|
||||
adjustment.close
|
||||
expect(originator).not_to receive(:update_adjustment)
|
||||
adjustment.update!
|
||||
end
|
||||
|
||||
it "should do nothing when finalized" do
|
||||
adjustment.finalize
|
||||
expect(originator).not_to receive(:update_adjustment)
|
||||
adjustment.update!
|
||||
end
|
||||
|
||||
it "should set the eligibility" do
|
||||
expect(adjustment).to receive(:set_eligibility)
|
||||
adjustment.update!
|
||||
end
|
||||
|
||||
it "should ask the originator to update_adjustment" do
|
||||
expect(originator).to receive(:update_adjustment)
|
||||
adjustment.update!
|
||||
end
|
||||
end
|
||||
|
||||
it "should do nothing when originator is nil" do
|
||||
allow(adjustment).to receive_messages originator: nil
|
||||
expect(adjustment).not_to receive(:amount=)
|
||||
@@ -47,17 +52,6 @@ module Spree
|
||||
end
|
||||
end
|
||||
|
||||
context "#promotion?" do
|
||||
it "returns false if not promotion adjustment" do
|
||||
expect(adjustment.promotion?).to eq false
|
||||
end
|
||||
|
||||
it "returns true if promotion adjustment" do
|
||||
adjustment.originator_type = "Spree::PromotionAction"
|
||||
expect(adjustment.promotion?).to eq true
|
||||
end
|
||||
end
|
||||
|
||||
context "#eligible? after #set_eligibility" do
|
||||
context "when amount is 0" do
|
||||
before { adjustment.amount = 0 }
|
||||
@@ -66,12 +60,7 @@ module Spree
|
||||
adjustment.set_eligibility
|
||||
expect(adjustment).to be_eligible
|
||||
end
|
||||
it "should be eligible if `promotion?` even if not `mandatory?`" do
|
||||
expect(adjustment).to receive(:promotion?).and_return(true)
|
||||
adjustment.mandatory = false
|
||||
adjustment.set_eligibility
|
||||
expect(adjustment).to be_eligible
|
||||
end
|
||||
|
||||
it "should not be eligible unless mandatory?" do
|
||||
adjustment.mandatory = false
|
||||
adjustment.set_eligibility
|
||||
@@ -81,17 +70,20 @@ module Spree
|
||||
|
||||
context "when amount is greater than 0" do
|
||||
before { adjustment.amount = 25.00 }
|
||||
|
||||
it "should be eligible if mandatory?" do
|
||||
adjustment.mandatory = true
|
||||
adjustment.set_eligibility
|
||||
expect(adjustment).to be_eligible
|
||||
end
|
||||
|
||||
it "should be eligible if not mandatory and eligible for the originator" do
|
||||
adjustment.mandatory = false
|
||||
allow(adjustment).to receive_messages(eligible_for_originator?: true)
|
||||
adjustment.set_eligibility
|
||||
expect(adjustment).to be_eligible
|
||||
end
|
||||
|
||||
it "should not be eligible if not mandatory not eligible for the originator" do
|
||||
adjustment.mandatory = false
|
||||
allow(adjustment).to receive_messages(eligible_for_originator?: false)
|
||||
@@ -149,17 +141,21 @@ module Spree
|
||||
context "with no originator" do
|
||||
specify { expect(adjustment).to be_eligible_for_originator }
|
||||
end
|
||||
|
||||
context "with originator that doesn't have 'eligible?'" do
|
||||
before { adjustment.originator = build(:tax_rate) }
|
||||
specify { expect(adjustment).to be_eligible_for_originator }
|
||||
end
|
||||
|
||||
context "with originator that has 'eligible?'" do
|
||||
let(:originator) { Spree::TaxRate.new }
|
||||
before { adjustment.originator = originator }
|
||||
|
||||
context "and originator is eligible for order" do
|
||||
before { allow(originator).to receive_messages(eligible?: true) }
|
||||
specify { expect(adjustment).to be_eligible_for_originator }
|
||||
end
|
||||
|
||||
context "and originator is not eligible for order" do
|
||||
before { allow(originator).to receive_messages(eligible?: false) }
|
||||
specify { expect(adjustment).to_not be_eligible_for_originator }
|
||||
|
||||
Reference in New Issue
Block a user