Skip to content

Commit 1af68f6

Browse files
committed
PC-24: Remove item_pricing association from QuoteItem and related files
1 parent 69c0cff commit 1af68f6

7 files changed

Lines changed: 5 additions & 31 deletions

File tree

app/admin/quotes.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
:_destroy,
55
:quote_id,
66
:item_id,
7-
:item_pricing_id,
87
:open_parameters,
98
:price,
109
:discount,
@@ -40,7 +39,6 @@
4039
f.inputs "Quote Items" do
4140
f.has_many :quote_items, allow_destroy: true, new_record: true do |qi|
4241
qi.input :item, as: :select, collection: Item.pluck(:name, :id)
43-
qi.input :item_pricing, as: :select, collection: ItemPricing.pluck(:default_fixed_price, :id)
4442
qi.input :open_parameters
4543
qi.input :price
4644
qi.input :discount
@@ -63,7 +61,6 @@
6361
panel 'Quote Items' do
6462
table_for quote.quote_items do
6563
column :item
66-
column :item_pricing
6764
column :open_parameters
6865
column :price
6966
column :discount

app/models/quote_item.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
class QuoteItem < ApplicationRecord
22
belongs_to :quote
33
belongs_to :item
4-
belongs_to :item_pricing
54

65
validates :price, presence: true, numericality: { greater_than_or_equal_to: 0 }
76
validates :discount, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 100 }
@@ -23,7 +22,6 @@ def should_recalculate_final_price?
2322
end
2423

2524
def recalculate_quote_total_price
26-
# quote.update(total_price: quote.quote_items.sum(:final_price))
2725
quote.recalculate_total_price
2826
end
2927
end

db/migrate/20250320050959_create_quote_items.rb renamed to db/migrate/20250401050959_create_quote_items.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ def change
33
create_table :quote_items do |t|
44
t.references :quote, null: false, foreign_key: true
55
t.references :item, null: false, foreign_key: true
6-
t.references :item_pricing, null: false, foreign_key: true
76
t.jsonb :open_parameters, default: {}
87
t.decimal :price, precision: 10, scale: 2, null: false
98
t.decimal :discount, precision: 5, scale: 2, default: 0.00, null: false

db/schema.rb

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/factories/item_pricings.rb

Lines changed: 0 additions & 13 deletions
This file was deleted.

spec/factories/quote_items.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
factory :quote_item do
33
association :quote, factory: :quote
44
association :item, factory: :item
5-
association :item_pricing, factory: :item_pricing
65
price { 100.00 }
76
discount { 10 }
87
open_parameters { {} }

spec/models/quote_item_spec.rb

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
describe 'associations' do
55
it { is_expected.to belong_to(:quote).required }
66
it { is_expected.to belong_to(:item).required }
7-
it { is_expected.to belong_to(:item_pricing).required }
87
end
98

109
describe 'validations' do
@@ -21,14 +20,13 @@
2120

2221
describe 'before_save callbacks' do
2322
let(:quote) { create(:quote) }
24-
let(:item) { create(:item, pricing_type: :open) }
25-
let(:item_pricing) { create(:item_pricing, item: item) }
23+
let(:item) { create(:item) }
2624
let(:price) { 1000 }
2725
let(:discount) { 10 }
2826

2927
context 'when quote_item is created' do
3028
let(:quote_item) do
31-
QuoteItem.new(quote: quote, item_pricing: item_pricing, item: item, price: price, discount: discount)
29+
QuoteItem.new(quote: quote, item: item, price: price, discount: discount)
3230
end
3331

3432
it 'calculates final_price before saving' do
@@ -39,7 +37,7 @@
3937

4038
context 'when quote_item is updated' do
4139
let(:quote_item) do
42-
create(:quote_item, quote: quote, item_pricing: item_pricing, item: item, price: price, discount: discount)
40+
create(:quote_item, quote: quote, item: item, price: price, discount: discount)
4341
end
4442

4543
context 'when price changes' do
@@ -90,9 +88,8 @@
9088

9189
describe 'after_save callbacks' do
9290
let(:quote) { create(:quote) }
93-
let(:item) { create(:item, pricing_type: :open) }
94-
let(:item_pricing) { create(:item_pricing, item: item) }
95-
let(:quote_item) { build(:quote_item, quote: quote, item_pricing: item_pricing, item: item) }
91+
let(:item) { create(:item, :with_pricing_options) }
92+
let(:quote_item) { build(:quote_item, quote: quote, item: item) }
9693

9794
it 'recalculates quote total_price after saving' do
9895
expect(quote).to receive(:recalculate_total_price)

0 commit comments

Comments
 (0)