From 2c0860266432b8fa4fb2b5ac57e1bcac36002e02 Mon Sep 17 00:00:00 2001 From: bouaik Date: Thu, 3 Aug 2023 11:25:31 +0100 Subject: [PATCH 1/3] fix display invoice tab --- app/models/spree/order.rb | 4 ++++ app/views/spree/admin/shared/_order_tabs.html.haml | 9 +++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/models/spree/order.rb b/app/models/spree/order.rb index 6ba226f222..f9007012a5 100644 --- a/app/models/spree/order.rb +++ b/app/models/spree/order.rb @@ -357,6 +357,10 @@ module Spree complete? || resumed? || awaiting_return? || returned? end + def can_show_invoice? + complete? || resumed? || canceled? + end + # Finalizes an in progress order after checkout is complete. # Called after transition to complete state when payments will have been processed def finalize! diff --git a/app/views/spree/admin/shared/_order_tabs.html.haml b/app/views/spree/admin/shared/_order_tabs.html.haml index 78d6b18c95..5a630cc72d 100644 --- a/app/views/spree/admin/shared/_order_tabs.html.haml +++ b/app/views/spree/admin/shared/_order_tabs.html.haml @@ -61,10 +61,11 @@ %li{ class: adjustments_classes } = link_to_with_icon 'icon-cogs', t(:adjustments), spree.admin_order_adjustments_url(@order) - - if feature?(:invoices) - - invoices_classes = "active" if current == 'Invoices' - %li{ class: invoices_classes } - = link_to_with_icon 'icon-cogs', t(:invoices), spree.admin_order_invoices_url(@order) + - if feature?(:invoices, spree_current_user) + - if @order.can_show_invoice? + - invoices_classes = "active" if current == 'Invoices' + %li{ class: invoices_classes } + = link_to_with_icon 'icon-cogs', t(:invoices), spree.admin_order_invoices_url(@order) - if @order.completed? - authorizations_classes = "active" if current == "Return Authorizations" From 0c849f08fdf7b0312816917d2e635b9731b6a9e2 Mon Sep 17 00:00:00 2001 From: bouaik Date: Thu, 3 Aug 2023 13:04:16 +0100 Subject: [PATCH 2/3] fix tests --- spec/system/admin/order_spec.rb | 47 +++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/spec/system/admin/order_spec.rb b/spec/system/admin/order_spec.rb index 37b0043c00..f6e2c139a8 100644 --- a/spec/system/admin/order_spec.rb +++ b/spec/system/admin/order_spec.rb @@ -1005,9 +1005,9 @@ describe ' end end - describe "Legal Invoices" do + describe "Legal Invoices - Invoices feature enabled" do before do - Flipper.enable(:invoices) + Flipper.enable(:invoices, user) login_as user end @@ -1123,8 +1123,7 @@ describe ' visit spree.edit_admin_order_path(order_empty) end - it "displays the invoice tab" do - pending "issue #11240" + it "not displays the invoice tab" do expect(page).to have_content "Cart".upcase expect(page).not_to have_content "Invoices".upcase end @@ -1140,8 +1139,46 @@ describe ' visit spree.edit_admin_order_path(order4) end + it "not displays the invoice tab" do + expect(page).to have_content "Payment".upcase + expect(page).not_to have_content "Invoices".upcase + end + end + end + end + + describe "Legal Invoices - Invoices feature not enabled" do + before do + login_as user + end + describe "for order states" do + context "resumed" do + let!(:order2) { + create(:order_with_totals_and_distribution, user: user, distributor:, + order_cycle: order_cycle, state: 'resumed', + payment_state: 'balance_due') + } + before do + visit spree.edit_admin_order_path(order2) + end + it "displays the invoice tab" do - pending "issue #11240" + expect(page).to have_content "Resumed".upcase + expect(page).not_to have_content "Invoices".upcase + end + end + + context "payment" do + let!(:order4) do + create(:order_ready_for_payment, user: user, distributor: distributor, + order_cycle: order_cycle, + payment_state: 'balance_due') + end + before do + visit spree.edit_admin_order_path(order4) + end + + it "not displays the invoice tab" do expect(page).to have_content "Payment".upcase expect(page).not_to have_content "Invoices".upcase end From 41d649404fb58107e1028ed369a9fdedc8b3b91d Mon Sep 17 00:00:00 2001 From: bouaik Date: Fri, 4 Aug 2023 00:55:35 +0100 Subject: [PATCH 3/3] make suggested changes --- .../spree/admin/shared/_order_tabs.html.haml | 9 ++-- spec/system/admin/order_spec.rb | 47 ++----------------- 2 files changed, 8 insertions(+), 48 deletions(-) diff --git a/app/views/spree/admin/shared/_order_tabs.html.haml b/app/views/spree/admin/shared/_order_tabs.html.haml index 5a630cc72d..1c89c24f1f 100644 --- a/app/views/spree/admin/shared/_order_tabs.html.haml +++ b/app/views/spree/admin/shared/_order_tabs.html.haml @@ -61,11 +61,10 @@ %li{ class: adjustments_classes } = link_to_with_icon 'icon-cogs', t(:adjustments), spree.admin_order_adjustments_url(@order) - - if feature?(:invoices, spree_current_user) - - if @order.can_show_invoice? - - invoices_classes = "active" if current == 'Invoices' - %li{ class: invoices_classes } - = link_to_with_icon 'icon-cogs', t(:invoices), spree.admin_order_invoices_url(@order) + - if feature?(:invoices) && @order.can_show_invoice? + - invoices_classes = "active" if current == 'Invoices' + %li{ class: invoices_classes } + = link_to_with_icon 'icon-cogs', t(:invoices), spree.admin_order_invoices_url(@order) - if @order.completed? - authorizations_classes = "active" if current == "Return Authorizations" diff --git a/spec/system/admin/order_spec.rb b/spec/system/admin/order_spec.rb index f6e2c139a8..f884746273 100644 --- a/spec/system/admin/order_spec.rb +++ b/spec/system/admin/order_spec.rb @@ -1005,9 +1005,9 @@ describe ' end end - describe "Legal Invoices - Invoices feature enabled" do + describe "Legal Invoices" do before do - Flipper.enable(:invoices, user) + Flipper.enable(:invoices) login_as user end @@ -1123,7 +1123,7 @@ describe ' visit spree.edit_admin_order_path(order_empty) end - it "not displays the invoice tab" do + it "should not display the invoice tab" do expect(page).to have_content "Cart".upcase expect(page).not_to have_content "Invoices".upcase end @@ -1139,46 +1139,7 @@ describe ' visit spree.edit_admin_order_path(order4) end - it "not displays the invoice tab" do - expect(page).to have_content "Payment".upcase - expect(page).not_to have_content "Invoices".upcase - end - end - end - end - - describe "Legal Invoices - Invoices feature not enabled" do - before do - login_as user - end - describe "for order states" do - context "resumed" do - let!(:order2) { - create(:order_with_totals_and_distribution, user: user, distributor:, - order_cycle: order_cycle, state: 'resumed', - payment_state: 'balance_due') - } - before do - visit spree.edit_admin_order_path(order2) - end - - it "displays the invoice tab" do - expect(page).to have_content "Resumed".upcase - expect(page).not_to have_content "Invoices".upcase - end - end - - context "payment" do - let!(:order4) do - create(:order_ready_for_payment, user: user, distributor: distributor, - order_cycle: order_cycle, - payment_state: 'balance_due') - end - before do - visit spree.edit_admin_order_path(order4) - end - - it "not displays the invoice tab" do + it "should not display the invoice tab" do expect(page).to have_content "Payment".upcase expect(page).not_to have_content "Invoices".upcase end