LineItems can always access soft-deleted variants

This commit is contained in:
Matt-Yorkley
2019-07-11 00:42:20 +01:00
parent 1a61357be8
commit b2c6e6271c
2 changed files with 48 additions and 1 deletions

View File

@@ -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

View 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