-
-
Notifications
You must be signed in to change notification settings - Fork 509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inactivating vendors #4959
base: main
Are you sure you want to change the base?
Inactivating vendors #4959
Changes from all commits
3374e81
98740bc
01f325f
5917181
b4a721e
333668e
fb64c5b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
# Table name: vendors | ||
# | ||
# id :bigint not null, primary key | ||
# active :boolean default(TRUE) | ||
# address :string | ||
# business_name :string | ||
# comment :string | ||
|
@@ -20,16 +21,29 @@ class Vendor < ApplicationRecord | |
has_paper_trail | ||
include Provideable | ||
include Geocodable | ||
include Filterable | ||
|
||
has_many :purchases, inverse_of: :vendor, dependent: :destroy | ||
|
||
validates :business_name, presence: true | ||
|
||
scope :alphabetized, -> { order(:business_name) } | ||
|
||
scope :active, -> { where(active: true) } | ||
scope :with_volumes, -> { | ||
left_joins(purchases: :line_items) | ||
.select("vendors.*, SUM(COALESCE(line_items.quantity, 0)) AS volume") | ||
.group(:id) | ||
} | ||
|
||
def volume | ||
purchases.map { |d| d.line_items.total }.reduce(:+) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is going to be slow - better to do it in the database. Something like LineItem.joins(:itemizable).
where(itemizable_type: 'Purchase', itemizable_id: self.purchase_ids).
sum(:quantity) |
||
end | ||
|
||
def deactivate! | ||
update!(active: false) | ||
end | ||
|
||
def reactivate! | ||
update!(active: true) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Add active column to vendors to make it possible to delete vendors without actually deleting them | ||
class AddActiveToVendors < ActiveRecord::Migration[7.2] | ||
def up | ||
add_column :vendors, :active, :boolean | ||
change_column_default :vendors, :active, true | ||
end | ||
|
||
def down | ||
remove_column :vendors, :active | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Add active column to vendors to make it possible to delete vendors without actually deleting them | ||
class SetExistingVendorsActive < ActiveRecord::Migration[7.2] | ||
def change | ||
Vendor.update_all(active: true) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
# | ||
# It's strongly recommended that you check this file into your version control system. | ||
|
||
ActiveRecord::Schema[7.2].define(version: 2025_01_29_015253) do | ||
ActiveRecord::Schema[7.2].define(version: 2025_02_01_151720) do | ||
# These are extensions that must be enabled in order to support this database | ||
enable_extension "plpgsql" | ||
|
||
|
@@ -230,6 +230,31 @@ | |
t.index ["user_id"], name: "index_deprecated_feedback_messages_on_user_id" | ||
end | ||
|
||
create_table "diaper_drive_participants", id: :serial, force: :cascade do |t| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These all seem unrelated to the PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, seems very strange these tables here, I think I will remove this changes and keep only the ones related with the migration I created |
||
t.string "contact_name" | ||
t.string "email" | ||
t.string "phone" | ||
t.string "comment" | ||
t.integer "organization_id" | ||
t.datetime "created_at", precision: nil, null: false | ||
t.datetime "updated_at", precision: nil, null: false | ||
t.string "address" | ||
t.string "business_name" | ||
t.float "latitude" | ||
t.float "longitude" | ||
t.index ["latitude", "longitude"], name: "index_diaper_drive_participants_on_latitude_and_longitude" | ||
end | ||
|
||
create_table "diaper_drives", force: :cascade do |t| | ||
t.string "name" | ||
t.date "start_date" | ||
t.date "end_date" | ||
t.datetime "created_at", precision: nil, null: false | ||
t.datetime "updated_at", precision: nil, null: false | ||
t.bigint "organization_id" | ||
t.index ["organization_id"], name: "index_diaper_drives_on_organization_id" | ||
end | ||
|
||
create_table "distributions", id: :serial, force: :cascade do |t| | ||
t.text "comment" | ||
t.datetime "created_at", precision: nil, null: false | ||
|
@@ -325,6 +350,16 @@ | |
t.index ["partner_id"], name: "index_families_on_partner_id" | ||
end | ||
|
||
create_table "feedback_messages", force: :cascade do |t| | ||
t.bigint "user_id" | ||
t.text "message" | ||
t.string "path" | ||
t.datetime "created_at", precision: nil, null: false | ||
t.datetime "updated_at", precision: nil, null: false | ||
t.boolean "resolved" | ||
t.index ["user_id"], name: "index_feedback_messages_on_user_id" | ||
end | ||
|
||
create_table "flipper_features", force: :cascade do |t| | ||
t.string "key", null: false | ||
t.datetime "created_at", precision: nil, null: false | ||
|
@@ -513,8 +548,8 @@ | |
t.integer "deadline_day" | ||
t.index ["name", "organization_id"], name: "index_partner_groups_on_name_and_organization_id", unique: true | ||
t.index ["organization_id"], name: "index_partner_groups_on_organization_id" | ||
t.check_constraint "deadline_day <= 28", name: "deadline_day_of_month_check", validate: false | ||
t.check_constraint "reminder_day <= 28", name: "reminder_day_of_month_check", validate: false | ||
t.check_constraint "deadline_day <= 28", name: "deadline_day_of_month_check" | ||
t.check_constraint "reminder_day <= 28", name: "reminder_day_of_month_check" | ||
end | ||
|
||
create_table "partner_profiles", force: :cascade do |t| | ||
|
@@ -728,17 +763,6 @@ | |
t.index ["resource_type", "resource_id"], name: "index_roles_on_resource" | ||
end | ||
|
||
create_table "solid_cache_entries", force: :cascade do |t| | ||
t.binary "key", null: false | ||
t.binary "value", null: false | ||
t.datetime "created_at", null: false | ||
t.bigint "key_hash", null: false | ||
t.integer "byte_size", null: false | ||
t.index ["byte_size"], name: "index_solid_cache_entries_on_byte_size" | ||
t.index ["key_hash", "byte_size"], name: "index_solid_cache_entries_on_key_hash_and_byte_size" | ||
t.index ["key_hash"], name: "index_solid_cache_entries_on_key_hash", unique: true | ||
end | ||
|
||
create_table "storage_locations", id: :serial, force: :cascade do |t| | ||
t.string "name" | ||
t.string "address" | ||
|
@@ -855,6 +879,7 @@ | |
t.float "longitude" | ||
t.datetime "created_at", precision: nil, null: false | ||
t.datetime "updated_at", precision: nil, null: false | ||
t.boolean "active", default: true | ||
t.index ["latitude", "longitude"], name: "index_vendors_on_latitude_and_longitude" | ||
end | ||
|
||
|
@@ -869,7 +894,7 @@ | |
t.index ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id" | ||
end | ||
|
||
add_foreign_key "account_requests", "ndbn_members", primary_key: "ndbn_member_id", validate: false | ||
add_foreign_key "account_requests", "ndbn_members", primary_key: "ndbn_member_id" | ||
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" | ||
add_foreign_key "adjustments", "organizations" | ||
add_foreign_key "adjustments", "storage_locations" | ||
|
@@ -903,7 +928,7 @@ | |
add_foreign_key "partner_requests", "users", column: "partner_user_id" | ||
add_foreign_key "partner_served_areas", "counties" | ||
add_foreign_key "partner_served_areas", "partner_profiles" | ||
add_foreign_key "partners", "storage_locations", column: "default_storage_location_id", validate: false | ||
add_foreign_key "partners", "storage_locations", column: "default_storage_location_id" | ||
add_foreign_key "product_drives", "organizations" | ||
add_foreign_key "requests", "distributions" | ||
add_foreign_key "requests", "organizations" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -181,6 +181,12 @@ | |
expect(Purchase.last.line_items.first.quantity).to eq(16) | ||
end | ||
|
||
it 'does not show inactive vendors in the vendor dropdown' do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be a request spec? System specs are a lot heavier and flakier. |
||
deactivated_vendor = create(:vendor, business_name: 'Deactivated Vendor', organization: organization, active: false) | ||
visit new_purchase_path | ||
expect(page).to have_no_select('purchase_vendor_id', with_options: [deactivated_vendor.business_name]) | ||
end | ||
|
||
context 'when creating a purchase incorrectly' do | ||
# Bug fix -- Issue #71 | ||
# When a user creates a purchase without it passing validation, the items | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can combine redirect and error/notice: