Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Simplify Price List code

Damian Legawiec5453b017fa9f
diff --git a/admin/app/views/spree/admin/tables/columns/_price_list_status.html.erb b/admin/app/views/spree/admin/tables/columns/_price_list_status.html.erb
index c5154a1384..c8ffc1ca45 100644
--- a/admin/app/views/spree/admin/tables/columns/_price_list_status.html.erb
+++ b/admin/app/views/spree/admin/tables/columns/_price_list_status.html.erb
@@ -1,9 +1,13 @@
-<% if record.scheduled? && record.currently_active? %>
- <span class="badge badge-success">
- <%= Spree.t('price_list_statuses.scheduled_active') %>
- </span>
-<% else %>
- <span class="badge badge-<%= record.currently_active? ? 'success' : (record.scheduled? ? 'info' : 'light') %>">
- <%= Spree.t("price_list_statuses.#{record.status}") %>
- </span>
-<% end %>
+<%
+ badge_class = if record.currently_active?
+ 'success'
+ elsif record.scheduled?
+ 'info'
+ else
+ 'light'
+ end
+ status_key = record.scheduled? && record.currently_active? ? 'scheduled_active' : record.status
+%>
+<span class="badge badge-<%= badge_class %>">
+ <%= Spree.t("price_list_statuses.#{status_key}") %>
+</span>
diff --git a/core/app/models/spree/price_list.rb b/core/app/models/spree/price_list.rb
index 258d4ca0e0..61259d62ea 100644
--- a/core/app/models/spree/price_list.rb
+++ b/core/app/models/spree/price_list.rb
@@ -100,10 +100,7 @@ module Spree
# Returns true if the price list is currently in effect
# (active, or scheduled and within date range)
def currently_active?
- return true if active? && within_date_range?(Time.current)
- return true if scheduled? && within_date_range?(Time.current)
-
- false
+ active_or_scheduled? && within_date_range?(Time.current)
end
def add_products(product_ids)