Skip to content

Commit 7495cf6

Browse files
committed
Include vendor even if its deactivated in purchase form
1 parent 7ae5db0 commit 7495cf6

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

app/controllers/purchases_controller.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def edit
6565
@purchase.line_items.build
6666
@audit_performed_and_finalized = Audit.finalized_since?(@purchase, @purchase.storage_location_id)
6767

68-
load_form_collections
68+
load_form_collections(@purchase)
6969
end
7070

7171
def show
@@ -82,7 +82,7 @@ def update
8282
flash[:success] = "Purchase updated successfully"
8383
redirect_to purchases_path
8484
rescue => e
85-
load_form_collections
85+
load_form_collections(@purchase)
8686
flash.now[:alert] = "Error updating purchase: #{e.message}"
8787
render "edit"
8888
end
@@ -102,10 +102,13 @@ def destroy
102102

103103
private
104104

105-
def load_form_collections
105+
def load_form_collections(purchase = nil)
106106
@storage_locations = current_organization.storage_locations.active.alphabetized
107107
@items = current_organization.items.active.alphabetized
108-
@vendors = current_organization.vendors.active.alphabetized
108+
109+
@vendors = current_organization.vendors.active
110+
@vendors = @vendors.or(Vendor.where(id: purchase.vendor_id)) if purchase
111+
@vendors = @vendors.alphabetized
109112
end
110113

111114
def purchase_params

spec/system/purchase_system_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,19 @@
254254
expect(page.current_path).to eq(purchases_path)
255255
end
256256
end
257+
258+
context "with a deactivated vendor" do
259+
let(:deactivated_vendor) { create(:vendor, active: false) }
260+
let(:purchase) { create(:purchase, vendor: deactivated_vendor) }
261+
262+
it "can save the purchase" do
263+
visit edit_purchase_path(purchase)
264+
click_button "Save"
265+
266+
expect(page).to have_content("Purchase updated successfully")
267+
expect(page.current_path).to eq(purchases_path)
268+
end
269+
end
257270
end
258271

259272
context "with another organization's purchase" do

0 commit comments

Comments
 (0)