Merge pull request #2823 from luisramos0/2-0-order-spec-fees

[Spree Upgrade] Fix fees tests in models/spree/order_spec
This commit is contained in:
Pau Pérez Fabregat
2018-10-18 13:30:15 +02:00
committed by GitHub
5 changed files with 20 additions and 25 deletions

View File

@@ -17,6 +17,14 @@ Spree::Order.class_eval do
has_one :proxy_order
has_one :subscription, through: :proxy_order
# This removes "inverse_of: source" which breaks shipment adjustment calculations
# This change is done in Spree 2.1 (see https://github.com/spree/spree/commit/3fa44165c7825f79a2fa4eb79b99dc29944c5d55)
# When OFN gets to Spree 2.1, this can be removed
has_many :adjustments,
as: :adjustable,
dependent: :destroy,
order: "#{Spree::Adjustment.table_name}.created_at ASC"
validates :customer, presence: true, if: :require_customer?
validate :products_available_from_new_distribution, :if => lambda { distributor_id_changed? || order_cycle_id_changed? }
validate :disallow_guest_order

View File

@@ -32,11 +32,7 @@ module Spree
# This is called by the calculator of a payment method
def line_items
if order.complete? && Spree::Config[:track_inventory_levels]
order.line_items.select { |li| inventory_units.pluck(:variant_id).include?(li.variant_id) }
else
order.line_items
end
order.line_items
end
# Pin payments lacks void and credit methods, but it does have refund

View File

@@ -2,8 +2,12 @@ module Spree
Shipment.class_eval do
def ensure_correct_adjustment_with_included_tax
ensure_correct_adjustment_without_included_tax
return unless adjustment
update_adjustment_included_tax if adjustment
end
alias_method_chain :ensure_correct_adjustment, :included_tax
def update_adjustment_included_tax
if Config.shipment_inc_vat && (order.distributor.nil? || order.distributor.charges_sales_tax)
adjustment.set_included_tax! Config.shipping_tax_rate
else
@@ -11,8 +15,6 @@ module Spree
end
end
alias_method_chain :ensure_correct_adjustment, :included_tax
private
# NOTE: This is an override of spree's method, needed to allow orders

View File

@@ -382,18 +382,6 @@ FactoryBot.define do
shipment.add_shipping_method(evaluator.shipping_method, true)
end
end
trait :shipping_fee do
transient do
shipping_fee 3
end
after(:create) do |shipment, evaluator|
shipping_method = create(:shipping_method_with, :shipping_fee, shipping_fee: evaluator.shipping_fee)
shipment.shipping_rates.destroy_all
shipment.add_shipping_method(shipping_method, true)
end
end
end
factory :distributor_enterprise_with_tax, parent: :distributor_enterprise do
@@ -407,16 +395,16 @@ FactoryBot.define do
payment_fee 5
end
shipments { [ create(:shipment_with, :shipping_fee, shipping_fee: shipping_fee) ] }
ship_address { create(:address) }
after(:create) do |order, evaluator|
create(:shipping_method_with, :shipping_fee, shipping_fee: evaluator.shipping_fee)
create(:line_item, order: order)
payment_calculator = build(:calculator_per_item, preferred_amount: evaluator.payment_fee)
payment_method = create(:payment_method, calculator: payment_calculator)
create(:payment, order: order, amount: order.total, payment_method: payment_method, state: 'checkout')
# skip the rebuilding of order.shipments from line_items and stock locations (this is enforced in checkout step :address to :delivery)
order.stub(:create_proposed_shipments)
while !order.completed? do break unless order.next! end
end
end

View File

@@ -655,7 +655,8 @@ describe Spree::Order do
end
describe "a completed order with shipping and transaction fees" do
let(:order) { create(:completed_order_with_fees, shipping_fee: shipping_fee, payment_fee: payment_fee) }
let(:distributor) { create(:distributor_enterprise_with_tax) }
let(:order) { create(:completed_order_with_fees, distributor: distributor, shipping_fee: shipping_fee, payment_fee: payment_fee) }
let(:shipping_fee) { 3 }
let(:payment_fee) { 5 }
let(:item_num) { order.line_items.length }
@@ -760,7 +761,7 @@ describe Spree::Order do
it "returns previous items" do
prev_order.add_variant(product.master, 1, 3)
prev_order2.reload # to get the right response from line_items
expect(order.finalised_line_items.length).to eq 3
expect(order.finalised_line_items.length).to eq 11
expect(order.finalised_line_items).to match_array(prev_order.line_items + prev_order2.line_items)
end
end