mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Merge pull request #4030 from Matt-Yorkley/line_item_errors
LineItems can always access soft-deleted variants
This commit is contained in:
@@ -20,7 +20,7 @@ Spree::LineItem.class_eval do
|
||||
|
||||
before_destroy :update_inventory_before_destroy
|
||||
|
||||
delegate :unit_description, to: :variant
|
||||
delegate :product, :unit_description, to: :variant
|
||||
|
||||
# -- Scopes
|
||||
scope :managed_by, lambda { |user|
|
||||
@@ -74,6 +74,11 @@ Spree::LineItem.class_eval do
|
||||
where('spree_adjustments.id IS NULL')
|
||||
}
|
||||
|
||||
def variant
|
||||
# Overridden so that LineItems always have access to soft-deleted Variant attributes
|
||||
Spree::Variant.unscoped { super }
|
||||
end
|
||||
|
||||
def cap_quantity_at_stock!
|
||||
scoper.scope(variant)
|
||||
return if variant.on_demand
|
||||
|
||||
42
spec/features/admin/reports/packing_report_spec.rb
Normal file
42
spec/features/admin/reports/packing_report_spec.rb
Normal file
@@ -0,0 +1,42 @@
|
||||
require "spec_helper"
|
||||
|
||||
feature "Packing Reports", js: true do
|
||||
include AuthenticationWorkflow
|
||||
include WebHelper
|
||||
|
||||
let(:distributor) { create(:distributor_enterprise) }
|
||||
let(:oc) { create(:simple_order_cycle) }
|
||||
let(:order) { create(:order, completed_at: 1.day.ago, order_cycle: oc, distributor: distributor) }
|
||||
let(:li1) { build(:line_item_with_shipment) }
|
||||
let(:li2) { build(:line_item_with_shipment) }
|
||||
|
||||
before do
|
||||
order.line_items << li1
|
||||
order.line_items << li2
|
||||
quick_login_as_admin
|
||||
end
|
||||
|
||||
describe "viewing a report" do
|
||||
context "when an associated variant has been soft-deleted" do
|
||||
it "shows line items" do
|
||||
li1.variant.delete
|
||||
|
||||
visit spree.admin_reports_path
|
||||
|
||||
click_on I18n.t("admin.reports.packing.name")
|
||||
select oc.name, from: "q_order_cycle_id_in"
|
||||
|
||||
find('#q_completed_at_gt').click
|
||||
select_date(Time.zone.today - 1.days)
|
||||
|
||||
find('#q_completed_at_lt').click
|
||||
select_date(Time.zone.today)
|
||||
|
||||
find("button[type='submit']").click
|
||||
|
||||
expect(page).to have_content li1.product.name
|
||||
expect(page).to have_content li2.product.name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -585,5 +585,17 @@ module Spree
|
||||
}.to change(Spree::OptionValue, :count).by(0)
|
||||
end
|
||||
end
|
||||
|
||||
describe "when the associated variant is soft-deleted" do
|
||||
let!(:variant) { create(:variant) }
|
||||
let!(:line_item) { create(:line_item, variant: variant) }
|
||||
|
||||
it "returns the associated variant or product" do
|
||||
line_item.variant.delete
|
||||
|
||||
expect(line_item.variant).to eq variant
|
||||
expect(line_item.product).to eq variant.product
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user