Rename Shipment #adjustment to #fee_adjustment for clarity

This commit is contained in:
Matt-Yorkley
2021-02-15 14:31:28 +00:00
parent a5929b489a
commit 945605e3a8
8 changed files with 48 additions and 48 deletions

View File

@@ -27,13 +27,13 @@ module Api
unlock = params[:shipment].delete(:unlock)
if unlock == 'yes'
@shipment.adjustment.open
@shipment.fee_adjustment.open
end
@shipment.update(shipment_params[:shipment])
if unlock == 'yes'
@shipment.adjustment.close
@shipment.fee_adjustment.close
end
render json: @shipment.reload, serializer: Api::ShipmentSerializer, status: :ok

View File

@@ -617,7 +617,7 @@ module Spree
shipments.each do |shipment|
next if shipment.shipped?
update_adjustment! shipment.adjustment if shipment.adjustment
update_adjustment! shipment.fee_adjustment if shipment.fee_adjustment
save_or_rescue_shipment(shipment)
end
end

View File

@@ -162,7 +162,7 @@ module Spree
def update_amounts
update_columns(
cost: adjustment&.amount || 0.0,
cost: fee_adjustment&.amount || 0.0,
updated_at: Time.zone.now
)
end
@@ -256,17 +256,17 @@ module Spree
inventory_units.create(variant_id: variant.id, state: state, order_id: order.id)
end
def adjustment
@adjustment ||= adjustments.shipping.first
def fee_adjustment
@fee_adjustment ||= adjustments.shipping.first
end
def ensure_correct_adjustment
if adjustment
adjustment.originator = shipping_method
adjustment.label = adjustment_label
adjustment.amount = selected_shipping_rate.cost if adjustment.open?
adjustment.save!
adjustment.reload
if fee_adjustment
fee_adjustment.originator = shipping_method
fee_adjustment.label = adjustment_label
fee_adjustment.amount = selected_shipping_rate.cost if fee_adjustment.open?
fee_adjustment.save!
fee_adjustment.reload
elsif selected_shipping_rate_id
shipping_method.create_adjustment(adjustment_label,
self,
@@ -276,8 +276,8 @@ module Spree
reload # ensure adjustment is present on later saves
end
update_amounts if adjustment&.amount != cost
update_adjustment_included_tax if adjustment
update_amounts if fee_adjustment&.amount != cost
update_adjustment_included_tax if fee_adjustment
end
def adjustment_label
@@ -319,7 +319,7 @@ module Spree
def after_ship
inventory_units.each(&:ship!)
adjustment.finalize!
fee_adjustment.finalize!
send_shipped_email
touch :shipped_at
end
@@ -330,9 +330,9 @@ module Spree
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
fee_adjustment.set_included_tax! Config.shipping_tax_rate
else
adjustment.set_included_tax! 0
fee_adjustment.set_included_tax! 0
end
end

View File

@@ -40,7 +40,7 @@
= label_tag 'selected_shipping_rate_id', Spree.t(:shipping_method)
= select_tag :selected_shipping_rate_id, options_for_select(shipment.shipping_rates.backend.map { |sr| ["#{sr.name} #{sr.display_price}", sr.id] }, shipment.selected_shipping_rate_id), { :class => 'select2 fullwidth', :data => { 'shipment-number' => shipment.number } }
- if shipment.adjustment && shipment.adjustment.closed?
- if shipment.fee_adjustment&.closed?
%div.field.omega.four.columns
%label
= Spree.t(:associated_adjustment_closed)
@@ -58,18 +58,18 @@
= link_to '', '', :class => 'cancel-method icon_link icon-cancel no-text with-tip', :data => { :action => 'cancel' }, :title => I18n.t('actions.cancel')
%tr.show-method.total
%td{ :colspan => "4" }
- if shipment.adjustment.present?
- if shipment.fee_adjustment.present?
%strong
= "#{shipment.adjustment.label}: #{shipment.shipping_method.name}"
= "#{shipment.fee_adjustment.label}: #{shipment.shipping_method.name}"
- else
= Spree.t(:cannot_set_shipping_method_without_address)
%td.total{ :align => "center" }
- if shipment.adjustment.present?
- if shipment.fee_adjustment.present?
%span
= shipment.adjustment.display_amount
= shipment.fee_adjustment.display_amount
- if shipment.adjustment.present? && !shipment.shipped?
- if shipment.fee_adjustment.present? && !shipment.shipped?
%td.actions
- if can? :update, shipment
= link_to '', '', :class => 'edit-method icon_link icon-edit no-text with-tip', :data => { :action => 'edit' }, :title => Spree.t('edit')

View File

@@ -106,7 +106,7 @@ describe LineItemsController, type: :controller do
item_num = order.line_items.length
initial_fees = item_num * (shipping_fee + payment_fee)
expect(order.adjustment_total).to eq initial_fees
expect(order.shipments.last.adjustment.included_tax).to eq 1.2
expect(order.shipments.last.fee_adjustment.included_tax).to eq 1.2
# Delete the item
item = order.line_items.first
@@ -119,9 +119,9 @@ describe LineItemsController, type: :controller do
order.reload
order.shipment.reload
expect(order.adjustment_total).to eq initial_fees - shipping_fee - payment_fee
expect(order.shipments.last.adjustment.amount).to eq shipping_fee
expect(order.shipments.last.fee_adjustment.amount).to eq shipping_fee
expect(order.payments.first.adjustment.amount).to eq payment_fee
expect(order.shipments.last.adjustment.included_tax).to eq 0.6
expect(order.shipments.last.fee_adjustment.included_tax).to eq 0.6
end
end

View File

@@ -280,7 +280,7 @@ describe Spree::OrdersController, type: :controller do
expect(order.all_adjustments.length).to eq 2
expect(item_num).to eq 2
expect(order.adjustment_total).to eq expected_fees
expect(order.shipment.adjustment.included_tax).to eq 1.2
expect(order.shipment.fee_adjustment.included_tax).to eq 1.2
allow(subject).to receive(:spree_current_user) { order.user }
allow(subject).to receive(:order_to_update) { order }
@@ -295,7 +295,7 @@ describe Spree::OrdersController, type: :controller do
expect(order.reload.line_items.count).to eq 1
expect(order.adjustment_total).to eq(1 * (shipping_fee + payment_fee))
expect(order.shipment.adjustment.included_tax).to eq 0.6
expect(order.shipment.fee_adjustment.included_tax).to eq 0.6
end
end

View File

@@ -1092,7 +1092,7 @@ describe Spree::Order do
expect(order.shipment_adjustments.length).to eq 1
expect(item_num).to eq 2
expect(order.adjustment_total).to eq expected_fees
expect(order.shipment.adjustment.included_tax).to eq 1.2
expect(order.shipment.fee_adjustment.included_tax).to eq 1.2
end
context "removing line_items" do
@@ -1101,7 +1101,7 @@ describe Spree::Order do
order.save
expect(order.adjustment_total).to eq expected_fees - shipping_fee - payment_fee
expect(order.shipment.adjustment.included_tax).to eq 0.6
expect(order.shipment.fee_adjustment.included_tax).to eq 0.6
end
context "when finalized fee adjustments exist on the order" do
@@ -1120,7 +1120,7 @@ describe Spree::Order do
# Check if fees got updated
order.reload
expect(order.adjustment_total).to eq expected_fees
expect(order.shipment.adjustment.included_tax).to eq 1.2
expect(order.shipment.fee_adjustment.included_tax).to eq 1.2
end
end
end
@@ -1133,7 +1133,7 @@ describe Spree::Order do
order.save
expect(order.adjustment_total).to eq expected_fees - (item_num * shipping_fee)
expect(order.shipment.adjustment.included_tax).to eq 0
expect(order.shipment.fee_adjustment.included_tax).to eq 0
end
end

View File

@@ -339,7 +339,7 @@ describe Spree::Shipment do
before do
allow(order).to receive(:update!)
allow(shipment).to receive_messages(update_order: true, state: 'ready')
allow(shipment).to receive_messages(adjustment: charge)
allow(shipment).to receive_messages(fee_adjustment: charge)
allow(shipping_method).to receive(:create_adjustment)
allow(shipment).to receive(:ensure_correct_adjustment)
end
@@ -368,8 +368,8 @@ describe Spree::Shipment do
it "should finalize the shipment's adjustment" do
allow(shipment).to receive(:send_shipped_email)
shipment.ship!
expect(shipment.adjustment.state).to eq 'finalized'
expect(shipment.adjustment).to be_immutable
expect(shipment.fee_adjustment.state).to eq 'finalized'
expect(shipment.fee_adjustment).to be_immutable
end
end
@@ -398,13 +398,13 @@ describe Spree::Shipment do
allow(shipment).
to receive_messages(selected_shipping_rate: Spree::ShippingRate.new(cost: 10.00))
adjustment = build(:adjustment)
allow(shipment).to receive_messages(adjustment: adjustment, update_columns: true)
allow(shipment).to receive_messages(fee_adjustment: adjustment, update_columns: true)
allow(adjustment).to receive(:open?) { true }
expect(shipment.adjustment).to receive(:originator=).with(shipping_method)
expect(shipment.adjustment).to receive(:label=).with(shipment.adjustment_label)
expect(shipment.adjustment).to receive(:amount=).with(10.00)
allow(shipment.adjustment).to receive(:save!)
expect(shipment.adjustment).to receive(:reload)
expect(shipment.fee_adjustment).to receive(:originator=).with(shipping_method)
expect(shipment.fee_adjustment).to receive(:label=).with(shipment.adjustment_label)
expect(shipment.fee_adjustment).to receive(:amount=).with(10.00)
allow(shipment.fee_adjustment).to receive(:save!)
expect(shipment.fee_adjustment).to receive(:reload)
shipment.__send__(:ensure_correct_adjustment)
end
@@ -412,13 +412,13 @@ describe Spree::Shipment do
allow(shipment).
to receive_messages(selected_shipping_rate: Spree::ShippingRate.new(cost: 10.00))
adjustment = build(:adjustment)
allow(shipment).to receive_messages(adjustment: adjustment, update_columns: true)
allow(shipment).to receive_messages(fee_adjustment: adjustment, update_columns: true)
allow(adjustment).to receive(:open?) { false }
expect(shipment.adjustment).to receive(:originator=).with(shipping_method)
expect(shipment.adjustment).to receive(:label=).with(shipment.adjustment_label)
expect(shipment.adjustment).not_to receive(:amount=).with(10.00)
allow(shipment.adjustment).to receive(:save!)
expect(shipment.adjustment).to receive(:reload)
expect(shipment.fee_adjustment).to receive(:originator=).with(shipping_method)
expect(shipment.fee_adjustment).to receive(:label=).with(shipment.adjustment_label)
expect(shipment.fee_adjustment).not_to receive(:amount=).with(10.00)
allow(shipment.fee_adjustment).to receive(:save!)
expect(shipment.fee_adjustment).to receive(:reload)
shipment.__send__(:ensure_correct_adjustment)
end
end
@@ -432,7 +432,7 @@ describe Spree::Shipment do
describe "#update_amounts" do
it "persists the shipping cost from the shipping fee adjustment" do
allow(shipment).to receive(:adjustment) { double(:adjustment, amount: 10) }
allow(shipment).to receive(:fee_adjustment) { double(:adjustment, amount: 10) }
expect(shipment).to receive(:update_columns).with(cost: 10, updated_at: kind_of(Time))
shipment.update_amounts