Update fees on single line item and then order fees in LineItemsController#delete

Fees on other line items are left alone (not recreated), and whatever fees on the order are updated.
This commit is contained in:
Matt-Yorkley
2021-01-29 19:20:31 +00:00
parent ce5f9a9a94
commit 793baca44f
4 changed files with 14 additions and 3 deletions

View File

@@ -33,7 +33,9 @@ module Admin
# and https://www.postgresql.org/docs/current/static/sql-select.html#SQL-FOR-UPDATE-SHARE
order.with_lock do
if @line_item.update(line_item_params)
order.recreate_all_fees!
order.update_line_item_fees! @line_item
order.update_order_fees!
order.update!
render nothing: true, status: :no_content # No Content, does not trigger ng resource auto-update
else
render json: { errors: @line_item.errors }, status: :precondition_failed

View File

@@ -68,7 +68,8 @@ module Spree
delegate :admin_and_handling_total, :payment_fee, :ship_total, to: :adjustments_fetcher
delegate :update_totals, to: :updater
delegate :create_line_item_fees!, :create_order_fees!, :update_order_fees!, to: :fee_handler
delegate :create_line_item_fees!, :create_order_fees!, :update_order_fees!,
:update_line_item_fees!, to: :fee_handler
# Needs to happen before save_permalink is called
before_validation :set_currency

View File

@@ -23,6 +23,12 @@ class OrderFeesHandler
calculator.create_order_adjustments_for order
end
def update_line_item_fees!(line_item)
line_item.adjustments.enterprise_fee.each do |fee|
fee.update!(line_item, force: true)
end
end
def update_order_fees!
order.adjustments.enterprise_fee.where(source_type: 'Spree::Order').each do |fee|
fee.update!(order, force: true)

View File

@@ -210,7 +210,9 @@ describe Admin::BulkLineItemsController, type: :controller do
.to receive(:find).with(line_item1.id.to_s).and_return(line_item1)
expect(line_item1.order).to receive(:reload).with(lock: true)
expect(line_item1.order).to receive(:recreate_all_fees!)
expect(line_item1.order).to receive(:update_line_item_fees!)
expect(line_item1.order).to receive(:update_order_fees!)
expect(line_item1.order).to receive(:update!).twice
spree_put :update, params
end