Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion app/models/billing/usage/product_catalog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def self.all_products
end

def current_products
products = parent.team.billing_subscriptions.active.map(&:included_prices).flatten.map(&:price).map(&:product)
products = non_zero_included_prices.map(&:price).compact.map(&:product).compact

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added these compacts to prevent breakages in the event of a dev or someone removing a product or price from the products.yml

products.any? ? products : free_products
end

Expand All @@ -29,4 +29,13 @@ def free_products
protected

attr_reader :parent

def non_zero_included_prices
parent
.team
.billing_subscriptions
.active
.flat_map(&:included_prices)
.select { |included_price| included_price.quantity && included_price.quantity > 0 }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have added a scope, but I am worried about repos like CF that have already cloned the starter repo. I.e. if I were to deploy a new scope, and upgrade CF, everything would break because we override the IncludedPrice model, and there would be no scope definition in there.

end
end