Skip to content

Commit

Permalink
Merge pull request #9 from spree-edge/4.6-stable
Browse files Browse the repository at this point in the history
upgraded with spree 4.6 and removed deface dependency
  • Loading branch information
vishal-bluebash authored Oct 14, 2023
2 parents 5666565 + 1eb65ab commit 48644e7
Show file tree
Hide file tree
Showing 17 changed files with 167 additions and 62 deletions.
5 changes: 5 additions & 0 deletions app/controllers/spree/admin/analysis_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class AnalysisController < Spree::Admin::BaseController
before_action :ensure_report_exists, :set_default_pagination, only: [:show, :download]
before_action :set_reporting_period, only: [:index, :show, :download]
before_action :load_reports, only: [:index, :show]
before_action :fetch_current_store, only: [:show, :download]

def index
respond_to do |format|
Expand Down Expand Up @@ -47,6 +48,10 @@ def download
end

private
def fetch_current_store
params[:store] = current_store
end

def ensure_report_exists
@report_name = params[:id].to_sym
unless ReportGenerationService.report_exists?(get_report_category, @report_name)
Expand Down
12 changes: 0 additions & 12 deletions app/overrides/spree/admin/shared/add_analysis_tab_to_main_menu.rb

This file was deleted.

66 changes: 34 additions & 32 deletions app/reports/spree/best_selling_products_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,43 @@ def report_query
end

private def query_with_inventory_unit_quantities
Spree::LineItem
.joins(:order)
.joins(:variant)
.joins(:product)
.joins(:inventory_units)
.where(Spree::Product.arel_table[:name].matches(search_name))
.where(spree_orders: { state: 'complete' })
.where(spree_orders: { completed_at: reporting_period })
.where.not(spree_inventory_units: { state: 'returned' })
.group(:variant_id, :product_name, :product_slug, 'spree_variants.sku')
.select(
'spree_products.name as product_name',
'spree_products.slug as product_slug',
'spree_variants.sku as sku',
'sum(spree_inventory_units.quantity) as sold_count'
)
::Spree::LineItem
.joins(:order)
.joins(:variant)
.joins(:product)
.joins(:inventory_units)
.where(spree_orders: { store_id: @current_store.id })
.where(::Spree::Product.arel_table[:name].matches(search_name))
.where(spree_orders: { state: 'complete' })
.where(spree_orders: { completed_at: reporting_period })
.where.not(spree_inventory_units: { state: 'returned' })
.group(:variant_id, :product_name, :product_slug, 'spree_variants.sku')
.select(
'spree_products.name as product_name',
'spree_products.slug as product_slug',
'spree_variants.sku as sku',
'sum(spree_inventory_units.quantity) as sold_count'
)
end

private def query_without_inventory_unit_quantities
Spree::LineItem
.joins(:order)
.joins(:variant)
.joins(:product)
.joins(:inventory_units)
.where(Spree::Product.arel_table[:name].matches(search_name))
.where(spree_orders: { state: 'complete' })
.where(spree_orders: { completed_at: reporting_period })
.where.not(spree_inventory_units: { state: 'returned' })
.group(:variant_id, :product_name, :product_slug, 'spree_variants.sku')
.select(
'spree_products.name as product_name',
'spree_products.slug as product_slug',
'spree_variants.sku as sku',
'count(spree_line_items.id) as sold_count'
)
::Spree::LineItem
.joins(:order)
.joins(:variant)
.joins(:product)
.joins(:inventory_units)
.where(spree_orders: { store_id: @current_store.id })
.where(::Spree::Product.arel_table[:name].matches(search_name))
.where(spree_orders: { state: 'complete' })
.where(spree_orders: { completed_at: reporting_period })
.where.not(spree_inventory_units: { state: 'returned' })
.group(:variant_id, :product_name, :product_slug, 'spree_variants.sku')
.select(
'spree_products.name as product_name',
'spree_products.slug as product_slug',
'spree_variants.sku as sku',
'count(spree_line_items.id) as sold_count'
)
end
end
end
2 changes: 1 addition & 1 deletion app/reports/spree/cart_additions_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def sku
end

def report_query
Spree::Order
Spree::Order.where(store_id: @current_store.id)
.incomplete
.joins(line_items: { variant: :product })
.where(created_at: reporting_period)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,16 @@ def report_query
end

private def payment_methods
Spree::PaymentMethod
.joins(:payments)
.where(spree_payments: { created_at: reporting_period })
.select(
'spree_payment_methods.id as payment_method_id',
'name as payment_method_name',
'state as payment_state',
*time_scale_selects('spree_payments')
)
::Spree::PaymentMethod
.joins(:stores, payments: [:order])
.where('spree_payment_methods_stores.store_id = ? AND spree_orders.store_id = ?', @current_store.id.to_s, @current_store.id.to_s)
.where(spree_payments: { created_at: reporting_period })
.select(
'spree_payment_methods.id as payment_method_id',
'spree_payment_methods.name as payment_method_name',
'spree_payments.state as payment_state',
*time_scale_selects('spree_payments')
)
end
end
end
3 changes: 2 additions & 1 deletion app/reports/spree/payment_method_transactions_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ def report_query

private def payments
Spree::PaymentMethod
.joins(:payments)
.joins(:stores, payments: [:order])
.where('spree_payment_methods_stores.store_id = ? AND spree_orders.store_id = ?', @current_store.id.to_s, @current_store.id.to_s)
.where(spree_payments: { created_at: reporting_period })
.select(
*time_scale_selects('spree_payments'),
Expand Down
3 changes: 2 additions & 1 deletion app/reports/spree/promotional_cost_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ def report_query

private def eligible_promotions
Spree::PromotionAction
.joins(:promotion)
.joins(promotion: [order_promotions: :order])
.joins(:adjustment)
.where(spree_orders: { store_id: @current_store.id })
.where(spree_adjustments: { created_at: reporting_period })
.select(
'spree_promotions.starts_at as promotion_start_date',
Expand Down
3 changes: 2 additions & 1 deletion app/reports/spree/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Spree
class Report

attr_accessor :sortable_attribute, :sortable_type, :total_records,
:records_per_page, :current_page, :paginate, :search, :reporting_period
:records_per_page, :current_page, :paginate, :search, :reporting_period, :current_store
alias_method :sort_direction, :sortable_type
alias_method :paginate?, :paginate

Expand Down Expand Up @@ -44,6 +44,7 @@ def initialize(options)
self.records_per_page = options[:records_per_page]
self.current_page = options[:offset]
self.paginate = options[:paginate]
self.current_store = options[:store] #current_store params in report instance
extract_reporting_period
determine_report_time_scale
if self.class::SORTABLE_ATTRIBUTES.present?
Expand Down
6 changes: 4 additions & 2 deletions app/reports/spree/returned_products_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def report_query
end

private def query_with_inventory_unit_quantities
Spree::ReturnAuthorization.joins(return_items: { inventory_unit: { variant: :product } })
Spree::ReturnAuthorization.joins(:order).joins(return_items: { inventory_unit: { variant: :product } })
.where(spree_orders: { store_id: @current_store.id })
.where(spree_return_items: { created_at: reporting_period })
.group('spree_variants.id', 'spree_products.name', 'spree_products.slug', 'spree_variants.sku')
.select(
Expand All @@ -38,7 +39,8 @@ def report_query
end

private def query_without_inventory_unit_quantities
Spree::ReturnAuthorization.joins(return_items: { inventory_unit: { variant: :product } })
Spree::ReturnAuthorization.joins(:order).joins(return_items: { inventory_unit: { variant: :product } })
.where(spree_orders: { store_id: @current_store.id })
.where(spree_return_items: { created_at: reporting_period })
.group('spree_variants.id', 'spree_products.name', 'spree_products.slug', 'spree_variants.sku')
.select(
Expand Down
1 change: 1 addition & 0 deletions app/reports/spree/sales_performance_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def promotion_discount
private def order_with_line_items
line_item_ar = Spree::LineItem.arel_table
Spree::Order
.where(store_id: @current_store.id)
.where.not(completed_at: nil)
.where(created_at: reporting_period)
.joins(:line_items)
Expand Down
1 change: 1 addition & 0 deletions app/reports/spree/sales_tax_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def report_query
Spree::TaxRate
.joins(adjustments: :order)
.joins(:zone)
.where(spree_orders: { store_id: @current_store.id })
.where(spree_adjustments: { adjustable_type: 'Spree::LineItem' })
.where(spree_orders: { completed_at: reporting_period })
.select(
Expand Down
1 change: 1 addition & 0 deletions app/reports/spree/shipping_cost_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def report_query

private def order_with_shipments
Spree::Order
.where(store_id: @current_store.id)
.where.not(completed_at: nil)
.where(completed_at: reporting_period)
.joins(:shipments)
Expand Down
2 changes: 1 addition & 1 deletion app/reports/spree/unique_purchases_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def report_query
.joins(:order)
.joins(:variant)
.joins(:product)
.where(spree_orders: { state: 'complete', completed_at: reporting_period })
.where(spree_orders: { state: 'complete', completed_at: reporting_period, store_id: @current_store.id })
.group('variant_id', 'spree_variants.sku', 'spree_products.slug', 'spree_products.name')
.select(
'spree_variants.sku as sku',
Expand Down
2 changes: 2 additions & 0 deletions app/reports/spree/users_not_converted_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def report_query
orders = Spree::Order.arel_table

Spree::User
.joins(orders: :store)
.where(spree_stores: { id: @current_store.id })
.where(created_at: reporting_period)
.where(Spree::User.arel_table[:email].matches(email_search))
.select(
Expand Down
1 change: 1 addition & 0 deletions app/reports/spree/users_who_recently_purchased_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def paginated_report_query

private def all_orders_with_users
Spree::Order
.where(store_id: @current_store.id)
.where(Spree::Order.arel_table[:email].matches(email_search))
.where(spree_orders: { completed_at: reporting_period })
.select(
Expand Down
99 changes: 99 additions & 0 deletions app/views/spree/admin/shared/_main_menu.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<nav class="pb-3 pt-lg-3 px-1">
<div class="text-right d-lg-none pl-3 py-2 border-bottom d-flex align-items-center">
<div class="d-flex flex-grow-1 text-primary"></div>
<button
id="sidebar-close"
class="btn btn-link d-flex"
type="button"
aria-expanded="false"
aria-label="Toggle navigation">
<%= svg_icon name: "cancel.svg", width: '20', height: '20', classes: 'p-0 m-0' %>
</button>
</div>

<ul class="nav nav-sidebar" id="sidebarDashboard">
<%= tab Spree.t('admin.home'), url: spree.admin_dashboard_path, match_path: '/dashboard', icon: 'house-door-fill.svg' %>
</ul>

<% if can? :admin, Spree::Order %>
<ul class="nav nav-sidebar" id="sidebarOrder">
<%= main_menu_tree Spree.t(:orders), icon: "inbox-fill.svg", sub_menu: "orders", url: "#sidebar-orders" %>
</ul>
<% end %>
<% if can?(:admin, Spree::ReturnAuthorization) || can?(:admin, Spree::CustomerReturn) %>
<ul class="nav nav-sidebar" id="sidebarReturn">
<%= main_menu_tree Spree.t(:returns), icon: "reply-fill.svg", sub_menu: "returns", url: "#sidebar-returns" %>
</ul>
<% end %>
<% if can? :admin, Spree::Product %>
<ul class="nav nav-sidebar" id="sidebarProduct">
<%= main_menu_tree Spree.t(:products), icon: "tags-fill.svg", sub_menu: "product", url: "#sidebar-product" %>
</ul>
<% end %>
<% if can?(:admin, Spree::StockLocation) || can?(:admin, Spree::StockTransfer) %>
<ul class="nav nav-sidebar" id="sidebarStock">
<%= main_menu_tree Spree.t(:stock), icon: "box-seam.svg", sub_menu: "stock", url: "#sidebar-stock" %>
</ul>
<% end %>
<% if can? :admin, Spree::Admin::ReportsController %>
<ul class="nav nav-sidebar" id="sidebarReport">
<%= tab *Spree::Backend::Configuration::REPORT_TABS, icon: 'pie-chart-fill.svg' %>
</ul>
<% end %>
<% if can? :admin, Spree::Promotion %>
<ul class="nav nav-sidebar" id="sidebarPromotion">
<%= main_menu_tree Spree.t(:promotions), icon: "percent.svg", sub_menu: "promotion", url: "#sidebar-promotions" %>
</ul>
<% end %>
<% if defined?(Spree::Vendor) && can?(:manage, Spree::Vendor) && can?(:index, Spree::Vendor) %>
<ul class="nav nav-sidebar" id="sidebarOrganizations">
<%= main_menu_tree Spree.t(:organizations), icon: "building.svg", sub_menu: "organizations", url: "#sidebar-organizations" %>
</ul>
<% end %>
<% if Spree.user_class && can?(:admin, Spree.user_class) %>
<ul class="nav nav-sidebar" id="sidebarUser">
<%= tab *Spree::Backend::Configuration::USER_TABS, url: spree.admin_users_path, icon: 'people-fill.svg' %>
</ul>
<% end %>
<% if can? :admin, Spree::Menu %>
<ul class="nav nav-sidebar" id="sidebarMenu">
<%= main_menu_tree Spree.t('admin.tab.content'), icon: "card-heading.svg", sub_menu: "content", url: "#sidebar-content" %>
</ul>
<% end %>
<% if can?(:admin, Spree::Webhooks::Subscriber) || can?(:admin, Spree::PaymentMethod) %>
<ul class="nav nav-sidebar" id="sidebarIntegrations">
<%= main_menu_tree Spree.t('admin.tab.integrations'), icon: "stack.svg", sub_menu: "integrations", url: "#sidebar-integrations" %>
</ul>
<% end %>
<% if can? :admin, Spree::OauthApplication %>
<ul class="nav nav-sidebar" id="sidebarApps">
<%= main_menu_tree Spree.t('admin.tab.apps'), icon: "terminal-fill.svg", sub_menu: "apps", url: "#sidebar-apps" %>
</ul>
<% end %>
<% if can? :admin, current_store %>
<ul class="nav nav-sidebar border-bottom" id="sidebarAnalysis">
<%= main_menu_tree Spree.t(:tab_heading, scope: [:analysis]), icon: "report.svg", sub_menu: "analysis", url: "#sidebar-analysis" %>
</ul>
<% end %>
<% if can? :admin, current_store %>
<ul class="nav nav-sidebar" id="sidebarConfiguration">
<%= main_menu_tree Spree.t('admin.settings'), icon: "gear-fill.svg", sub_menu: "configuration", url: "#sidebar-configuration" %>
</ul>
<% elsif defined?(current_spree_vendor) && current_spree_vendor.present? %>
<ul class="nav nav-sidebar" id="sidebarConfiguration">
<%= main_menu_tree Spree.t('admin.settings'), icon: "gear-fill.svg", sub_menu: "vendor_configuration", url: "#sidebar-configuration" %>
</ul>
<% end %>
</nav>
3 changes: 1 addition & 2 deletions spree_analysis.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ Gem::Specification.new do |s|
s.require_path = 'lib'
s.requirements << 'none'

spree_version = '>=4.4.0'
spree_version = '>=4.6.0'
s.add_dependency 'spree', spree_version
s.add_dependency 'spree_extension'
s.add_dependency 'wicked_pdf'
s.add_dependency 'wkhtmltopdf-binary'

s.add_development_dependency 'deface'
s.add_development_dependency 'spree_dev_tools'
end

0 comments on commit 48644e7

Please sign in to comment.