From f1a8011e1334d27ae917576ee1ae60c352c2604f Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 23 Apr 2015 10:02:32 +1000 Subject: [PATCH 01/14] Documentation of Variant.full_name The code was confusing for all developers here. Maybe a bit of doco helps. --- app/models/spree/variant_decorator.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/models/spree/variant_decorator.rb b/app/models/spree/variant_decorator.rb index 86a0b5fd69..03543793b2 100644 --- a/app/models/spree/variant_decorator.rb +++ b/app/models/spree/variant_decorator.rb @@ -74,6 +74,12 @@ Spree::Variant.class_eval do self.option_values.destroy ovs end + # Used like "product.name - full_name". If called like this, a product with + # name "Bread" would be displayed as one of these: + # Bread - 1kg # if display_name blank + # Bread - Spelt Sourdough, 1kg # if display_name is "Spelt Sourdough, 1kg" + # Bread - 1kg Spelt Sourdough # if unit_to_display is "1kg Spelt Sourdough" + # Bread - Spelt Sourdough (1kg) # if display_name is "Spelt Sourdough" and unit_to_display is "1kg" def full_name return unit_to_display if display_name.blank? return display_name if display_name.downcase.include? unit_to_display.downcase From 3412bc25bf06f522bec22ba57802f3fe25a77164 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 23 Apr 2015 10:17:01 +1000 Subject: [PATCH 02/14] Edit Orders: more variant info in variant search Displaying variant's full name and the producer's name. --- .../spree/admin/variants/_autocomplete.js.erb | 33 ++++++++++++++++++ app/views/spree/admin/variants/search.rabl | 34 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 app/views/spree/admin/variants/_autocomplete.js.erb create mode 100644 app/views/spree/admin/variants/search.rabl diff --git a/app/views/spree/admin/variants/_autocomplete.js.erb b/app/views/spree/admin/variants/_autocomplete.js.erb new file mode 100644 index 0000000000..7b52c0a716 --- /dev/null +++ b/app/views/spree/admin/variants/_autocomplete.js.erb @@ -0,0 +1,33 @@ + diff --git a/app/views/spree/admin/variants/search.rabl b/app/views/spree/admin/variants/search.rabl new file mode 100644 index 0000000000..afd3f39ce6 --- /dev/null +++ b/app/views/spree/admin/variants/search.rabl @@ -0,0 +1,34 @@ +# +# overriding spree/core/app/views/spree/admin/variants/search.rabl +# +collection @variants +attributes :sku, :options_text, :count_on_hand, :id, :cost_price + +node(:name) do |v| + # TODO: when products must have a unit, full_name will always be present + variant_specific = v.full_name + if variant_specific.present? + "#{v.name} - #{v.full_name}" + else + v.name + end +end + +node(:full_name) do |v| + v.full_name +end + +node(:producer_name) do |v| + v.product.supplier.name +end + +child(:images => :images) do + attributes :mini_url +end + +child(:option_values => :option_values) do + child(:option_type => :option_type) do + attributes :name, :presentation + end + attributes :name, :presentation +end From a937fd3c614a7e547976ab732192ca8cfe91b9c0 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 23 Apr 2015 11:37:10 +1000 Subject: [PATCH 03/14] Using variant overrides in variant seach on order edit page --- .../spree/admin/variants_controller_decorator.rb | 13 ++++++++----- .../spree/admin/variants_controller_spec.rb | 7 +++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/controllers/spree/admin/variants_controller_decorator.rb b/app/controllers/spree/admin/variants_controller_decorator.rb index acb55327ae..539ce83183 100644 --- a/app/controllers/spree/admin/variants_controller_decorator.rb +++ b/app/controllers/spree/admin/variants_controller_decorator.rb @@ -6,15 +6,18 @@ Spree::Admin::VariantsController.class_eval do @variants = Spree::Variant.ransack(search_params.merge(:m => 'or')).result - if params[:distributor_id].present? - distributor = Enterprise.find params[:distributor_id] - @variants = @variants.in_distributor(distributor) - end - if params[:order_cycle_id].present? order_cycle = OrderCycle.find params[:order_cycle_id] @variants = @variants.in_order_cycle(order_cycle) end + + if params[:distributor_id].present? + distributor = Enterprise.find params[:distributor_id] + @variants = @variants.in_distributor(distributor) + # Perform scoping after all filtering is done. + # Filtering could be a problem on scoped variants. + @variants.each { |v| v.scope_to_hub(distributor) } + end end def destroy diff --git a/spec/controllers/spree/admin/variants_controller_spec.rb b/spec/controllers/spree/admin/variants_controller_spec.rb index 9c6d77194d..22972a7301 100644 --- a/spec/controllers/spree/admin/variants_controller_spec.rb +++ b/spec/controllers/spree/admin/variants_controller_spec.rb @@ -8,6 +8,7 @@ module Spree describe "search action" do let!(:p1) { create(:simple_product, name: 'Product 1') } let!(:p2) { create(:simple_product, name: 'Product 2') } + let!(:vo) { create(:variant_override, variant: p1.master, hub: d, count_on_hand: 44) } let!(:d) { create(:distributor_enterprise) } let!(:oc) { create(:simple_order_cycle, distributors: [d], variants: [p1.master]) } @@ -16,6 +17,12 @@ module Spree assigns(:variants).should == [p1.master] end + it "applies variant overrides" do + spree_get :search, q: 'Prod', distributor_id: d.id.to_s + assigns(:variants).should == [p1.master] + assigns(:variants).first.count_on_hand.should == 44 + end + it "filters by order cycle" do spree_get :search, q: 'Prod', order_cycle_id: oc.id.to_s assigns(:variants).should == [p1.master] From 355221a2739abf4395969c4bead043809d91e4f4 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 24 Apr 2015 12:32:45 +1000 Subject: [PATCH 04/14] Adding customer name to order edit page heading --- .../shared/_order_tabs/add_customer_name.html.haml.deface | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 app/overrides/spree/admin/shared/_order_tabs/add_customer_name.html.haml.deface diff --git a/app/overrides/spree/admin/shared/_order_tabs/add_customer_name.html.haml.deface b/app/overrides/spree/admin/shared/_order_tabs/add_customer_name.html.haml.deface new file mode 100644 index 0000000000..f8ce05079c --- /dev/null +++ b/app/overrides/spree/admin/shared/_order_tabs/add_customer_name.html.haml.deface @@ -0,0 +1,5 @@ +/ insert_after "code[erb-silent]:contains('content_for :page_title')" + += @order.bill_address.firstname += @order.bill_address.lastname +\- From f94a5a975a4a8e489adc6a84a7ed07743fca622b Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 24 Apr 2015 15:31:45 +1000 Subject: [PATCH 05/14] Edit Order: resend button uses new pretty template. --- .../spree/admin/orders_controller_decorator.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/controllers/spree/admin/orders_controller_decorator.rb b/app/controllers/spree/admin/orders_controller_decorator.rb index 3e3c255ab3..ceba6d9bde 100644 --- a/app/controllers/spree/admin/orders_controller_decorator.rb +++ b/app/controllers/spree/admin/orders_controller_decorator.rb @@ -17,4 +17,13 @@ Spree::Admin::OrdersController.class_eval do page(params[:page]). per(params[:per_page] || Spree::Config[:orders_per_page]) } } } + + # Overwrite to use confirm_email_for_customer instead of confirm_email. + # This uses a new template. See mailers/spree/order_mailer_decorator.rb. + def resend + Spree::OrderMailer.confirm_email_for_customer(@order.id, true).deliver + flash[:success] = t(:order_email_resent) + + respond_with(@order) { |format| format.html { redirect_to :back } } + end end From 2b0f867ed831e83d6155d0e730b4c8b2df17731d Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 29 Apr 2015 11:42:35 +1000 Subject: [PATCH 06/14] new order method ready_to_ship? --- app/models/spree/order_decorator.rb | 5 +++ spec/models/spree/order_spec.rb | 53 +++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index d5e18c3d9b..f109f730d8 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -198,6 +198,11 @@ Spree::Order.class_eval do end end + # Does this order have shipments that can be shipped? + def ready_to_ship? + self.shipments.any?{|s| s.can_ship?} + end + def available_shipping_methods(display_on = nil) Spree::ShippingMethod.all_available(self, display_on) end diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index 3c70c2243c..ecc19f5493 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -186,6 +186,59 @@ describe Spree::Order do end end + describe "an order without shipping method" do + let(:order) { create(:order) } + + it "cannot be shipped" do + order.ready_to_ship?.should == false + end + end + + describe "an unpaid order with a shipment" do + let(:order) { create(:order, shipping_method: shipping_method) } + let(:shipping_method) { create(:shipping_method) } + + before do + order.create_shipment! + order.reload + order.state = 'complete' + order.shipment.update!(order) + end + + it "cannot be shipped" do + order.ready_to_ship?.should == false + end + end + + describe "a paid order without a shipment" do + let(:order) { create(:order) } + + before do + order.payment_state = 'paid' + order.state = 'complete' + end + + it "cannot be shipped" do + order.ready_to_ship?.should == false + end + end + + describe "a paid order with a shipment" do + let(:order) { create(:order, shipping_method: shipping_method) } + let(:shipping_method) { create(:shipping_method) } + + before do + order.create_shipment! + order.payment_state = 'paid' + order.state = 'complete' + order.shipment.update!(order) + end + + it "can be shipped" do + order.ready_to_ship?.should == true + end + end + describe "getting the shipping tax" do let(:order) { create(:order, shipping_method: shipping_method) } let(:shipping_method) { create(:shipping_method, calculator: Spree::Calculator::FlatRate.new(preferred_amount: 50.0)) } From 1268108877f8169af117edbb36723de87d8e8f3d Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 29 Apr 2015 12:03:11 +1000 Subject: [PATCH 07/14] handle ship event on order --- app/models/spree/order_decorator.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index f109f730d8..0dc6977965 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -203,6 +203,13 @@ Spree::Order.class_eval do self.shipments.any?{|s| s.can_ship?} end + # Ship all pending orders + def ship + self.shipments.each do |s| + s.ship if s.can_ship? + end + end + def available_shipping_methods(display_on = nil) Spree::ShippingMethod.all_available(self, display_on) end From 8511bd19ced2b2d6f02ae574e8893cf2ac732728 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 29 Apr 2015 12:03:49 +1000 Subject: [PATCH 08/14] add ship button to order edit page --- .../spree/admin/orders/edit/add_ship_button.html.haml.deface | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 app/overrides/spree/admin/orders/edit/add_ship_button.html.haml.deface diff --git a/app/overrides/spree/admin/orders/edit/add_ship_button.html.haml.deface b/app/overrides/spree/admin/orders/edit/add_ship_button.html.haml.deface new file mode 100644 index 0000000000..47fbdea70a --- /dev/null +++ b/app/overrides/spree/admin/orders/edit/add_ship_button.html.haml.deface @@ -0,0 +1,3 @@ +/ insert_before "code[erb-loud]:contains('button_link_to t(:resend)')" +- if @order.ready_to_ship? + %li= button_link_to t(:ship), fire_admin_order_url(@order, :e => 'ship'), :method => :put, :data => { :confirm => t(:are_you_sure) } From e82a3a9d82057151273e5890c74a0b4bf11d0f78 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 29 Apr 2015 12:30:05 +1000 Subject: [PATCH 09/14] add ship button to admin order index page --- .../admin/orders/index/add_ship_shortcut.html.haml.deface | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 app/overrides/spree/admin/orders/index/add_ship_shortcut.html.haml.deface diff --git a/app/overrides/spree/admin/orders/index/add_ship_shortcut.html.haml.deface b/app/overrides/spree/admin/orders/index/add_ship_shortcut.html.haml.deface new file mode 100644 index 0000000000..cf0b2b0abb --- /dev/null +++ b/app/overrides/spree/admin/orders/index/add_ship_shortcut.html.haml.deface @@ -0,0 +1,6 @@ +/ insert_bottom "[data-hook='admin_orders_index_row_actions']" +-# See also: app/overrides/add_capture_order_shortcut.rb + +- if order.ready_to_ship? + - # copied from backend/app/views/spree/admin/payments/_list.html.erb + = link_to_with_icon "icon-road", t(:ship), fire_admin_order_url(order, :e => 'ship'), :method => :put, :no_text => true, :data => {:action => 'ship', :confirm => t(:are_you_sure)} From 2e66a082eb84d0f8111bff465dab5db08993bc07 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 29 Apr 2015 14:14:18 +1000 Subject: [PATCH 10/14] add customer notes to admin order index page --- .../orders/index/add_special_instructions.html.haml.deface | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 app/overrides/spree/admin/orders/index/add_special_instructions.html.haml.deface diff --git a/app/overrides/spree/admin/orders/index/add_special_instructions.html.haml.deface b/app/overrides/spree/admin/orders/index/add_special_instructions.html.haml.deface new file mode 100644 index 0000000000..75a2bc4689 --- /dev/null +++ b/app/overrides/spree/admin/orders/index/add_special_instructions.html.haml.deface @@ -0,0 +1,6 @@ +/ insert_bottom "[data-hook='admin_orders_index_rows'] td:nth-child(3)" + +- if order.special_instructions.present? + %br + %span{class: "icon-warning-sign with-tip", title: order.special_instructions} + notes From ecf635e080e475ad617c969211ce03574d5d404c Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 29 Apr 2015 14:28:20 +1000 Subject: [PATCH 11/14] handle missing bill_address on admin order page --- .../shared/_order_tabs/add_customer_name.html.haml.deface | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/overrides/spree/admin/shared/_order_tabs/add_customer_name.html.haml.deface b/app/overrides/spree/admin/shared/_order_tabs/add_customer_name.html.haml.deface index f8ce05079c..2e3780460e 100644 --- a/app/overrides/spree/admin/shared/_order_tabs/add_customer_name.html.haml.deface +++ b/app/overrides/spree/admin/shared/_order_tabs/add_customer_name.html.haml.deface @@ -1,5 +1,6 @@ / insert_after "code[erb-silent]:contains('content_for :page_title')" -= @order.bill_address.firstname -= @order.bill_address.lastname -\- +- if @order.bill_address.present? + = @order.bill_address.firstname + = @order.bill_address.lastname + \- From 5efc0a511063384abd362ac4dd8120ae5fffd05a Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 30 Apr 2015 16:29:51 +1000 Subject: [PATCH 12/14] quick fix: update fees after updating order --- .../admin/orders_controller_decorator.rb | 11 +++++++ .../spree/admin/orders_controller_spec.rb | 30 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 spec/controllers/spree/admin/orders_controller_spec.rb diff --git a/app/controllers/spree/admin/orders_controller_decorator.rb b/app/controllers/spree/admin/orders_controller_decorator.rb index ceba6d9bde..42e7068afc 100644 --- a/app/controllers/spree/admin/orders_controller_decorator.rb +++ b/app/controllers/spree/admin/orders_controller_decorator.rb @@ -9,6 +9,13 @@ Spree::Admin::OrdersController.class_eval do # in an auth failure as the @order object is nil for collection actions before_filter :check_authorization, :except => :bulk_management + # After updating an order, the fees should be updated as well + # Currently, adding or deleting line items does not trigger updating the + # fees! This is a quick fix for that. + # TODO: update fees when adding/removing line items + # instead of the update_distribution_charge method. + after_filter :update_distribution_charge, :only => :update + respond_override :index => { :html => { :success => lambda { # Filter orders to only show those distributed by current user (or all for admin user) @@ -26,4 +33,8 @@ Spree::Admin::OrdersController.class_eval do respond_with(@order) { |format| format.html { redirect_to :back } } end + + def update_distribution_charge + @order.update_distribution_charge! + end end diff --git a/spec/controllers/spree/admin/orders_controller_spec.rb b/spec/controllers/spree/admin/orders_controller_spec.rb new file mode 100644 index 0000000000..5724732c50 --- /dev/null +++ b/spec/controllers/spree/admin/orders_controller_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper' + +describe Spree::Admin::OrdersController do + let!(:order) { create(:order) } + + context "updating an order with line items" do + let(:line_item) { create(:line_item) } + before { login_as_admin } + + it "updates distribution charges" do + order.line_items << line_item + order.save + Spree::Order.any_instance.should_receive(:update_distribution_charge!) + spree_put :update, { + id: order, + order: { + number: order.number, + distributor_id: order.distributor_id, + order_cycle_id: order.order_cycle_id, + line_items_attributes: [ + { + id: line_item.id, + quantity: line_item.quantity + } + ] + } + } + end + end +end From a6cecdcc25af036f5d0645341cddfac67e376054 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 1 May 2015 11:59:52 +1000 Subject: [PATCH 13/14] Display header for Xero invoices report --- .../admin/reports_controller_decorator.rb | 26 ++++++++++++++----- .../admin/reports/xero_invoices.html.haml | 13 ++++++++++ config/routes.rb | 1 + lib/open_food_network/xero_invoices_report.rb | 15 +++++++++++ spec/features/admin/reports_spec.rb | 25 ++++++++++++++++++ 5 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 app/views/spree/admin/reports/xero_invoices.html.haml create mode 100644 lib/open_food_network/xero_invoices_report.rb diff --git a/app/controllers/spree/admin/reports_controller_decorator.rb b/app/controllers/spree/admin/reports_controller_decorator.rb index f148456813..aed798827e 100644 --- a/app/controllers/spree/admin/reports_controller_decorator.rb +++ b/app/controllers/spree/admin/reports_controller_decorator.rb @@ -7,6 +7,7 @@ require 'open_food_network/customers_report' require 'open_food_network/users_and_enterprises_report' require 'open_food_network/order_cycle_management_report' require 'open_food_network/sales_tax_report' +require 'open_food_network/xero_invoices_report' Spree::Admin::ReportsController.class_eval do @@ -14,10 +15,10 @@ Spree::Admin::ReportsController.class_eval do REPORT_TYPES = { orders_and_fulfillment: [ - ['Order Cycle Supplier Totals',:order_cycle_supplier_totals], - ['Order Cycle Supplier Totals by Distributor',:order_cycle_supplier_totals_by_distributor], - ['Order Cycle Distributor Totals by Supplier',:order_cycle_distributor_totals_by_supplier], - ['Order Cycle Customer Totals',:order_cycle_customer_totals] + ['Order Cycle Supplier Totals', :order_cycle_supplier_totals], + ['Order Cycle Supplier Totals by Distributor', :order_cycle_supplier_totals_by_distributor], + ['Order Cycle Distributor Totals by Supplier', :order_cycle_distributor_totals_by_supplier], + ['Order Cycle Customer Totals', :order_cycle_customer_totals] ], products_and_inventory: [ ['All products', :all_products], @@ -30,13 +31,16 @@ Spree::Admin::ReportsController.class_eval do order_cycle_management: [ ["Payment Methods Report", :payment_methods], ["Delivery Report", :delivery] + ], + xero_invoices: [ + ["Xero Invoices Report", :xero_invoices] ] } # Fetches user's distributors, suppliers and order_cycles before_filter :load_data, only: [:customers, :products_and_inventory, :order_cycle_management] - # Render a partial for orders and fulfillment description + # Render a partial for various section descriptions respond_override :index => { :html => { :success => lambda { @reports[:orders_and_fulfillment][:description] = render_to_string(partial: 'orders_and_fulfillment_description', layout: false, locals: {report_types: REPORT_TYPES[:orders_and_fulfillment]}).html_safe @@ -672,7 +676,13 @@ Spree::Admin::ReportsController.class_eval do render_report(@report.header, @report.table, params[:csv], "users_and_enterprises_#{timestamp}.csv") end - def render_report (header, table, create_csv, csv_file_name) + def xero_invoices + @report = OpenFoodNetwork::XeroInvoicesReport.new params + render_report(@report.header, @report.table, params[:csv], "xero_invoices_#{timestamp}.csv") + end + + + def render_report(header, table, create_csv, csv_file_name) unless create_csv render :html => table else @@ -709,7 +719,9 @@ Spree::Admin::ReportsController.class_eval do :sales_total => { :name => "Sales Total", :description => "Sales Total For All Orders" }, :users_and_enterprises => { :name => "Users & Enterprises", :description => "Enterprise Ownership & Status" }, :order_cycle_management => {:name => "Order Cycle Management", :description => ''}, - :sales_tax => { :name => "Sales Tax", :description => "Sales Tax For Orders" } + :sales_tax => { :name => "Sales Tax", :description => "Sales Tax For Orders" }, + :xero_invoices => { :name => "Xero invoices", :description => 'Invoices for import into Xero' } + } # Return only reports the user is authorized to view. reports.select { |action| can? action, :report } diff --git a/app/views/spree/admin/reports/xero_invoices.html.haml b/app/views/spree/admin/reports/xero_invoices.html.haml new file mode 100644 index 0000000000..0e9598125a --- /dev/null +++ b/app/views/spree/admin/reports/xero_invoices.html.haml @@ -0,0 +1,13 @@ +%table#listing_invoices.index + %thead + %tr + - @report.header.each do |header| + %th= header + %tbody + - @report.table.each do |row| + %tr + - row.each do |column| + %td= column + - if @report.table.empty? + %tr + %td{:colspan => "2"}= t(:none) diff --git a/config/routes.rb b/config/routes.rb index 4621ee4a35..66805807ce 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -134,6 +134,7 @@ Spree::Core::Engine.routes.prepend do match '/admin/orders/bulk_management' => 'admin/orders#bulk_management', :as => "admin_bulk_order_management" match '/admin/reports/products_and_inventory' => 'admin/reports#products_and_inventory', :as => "products_and_inventory_admin_reports", :via => [:get, :post] match '/admin/reports/customers' => 'admin/reports#customers', :as => "customers_admin_reports", :via => [:get, :post] + match '/admin/reports/xero_invoices' => 'admin/reports#xero_invoices', :as => "xero_invoices_admin_reports", :via => [:get, :post] match '/admin', :to => 'admin/overview#index', :as => :admin match '/admin/payment_methods/show_provider_preferences' => 'admin/payment_methods#show_provider_preferences', :via => :get diff --git a/lib/open_food_network/xero_invoices_report.rb b/lib/open_food_network/xero_invoices_report.rb new file mode 100644 index 0000000000..35c3dac73d --- /dev/null +++ b/lib/open_food_network/xero_invoices_report.rb @@ -0,0 +1,15 @@ +module OpenFoodNetwork + class XeroInvoicesReport + def initialize(params={}) + @params = params + end + + def header + %w(*ContactName EmailAddress POAddressLine1 POAddressLine2 POAddressLine3 POAddressLine4 POCity PORegion POPostalCode POCountry *InvoiceNumber Reference *InvoiceDate *DueDate InventoryItemCode *Description *Quantity *UnitAmount Discount *AccountCode *TaxType TrackingName1 TrackingOption1 TrackingName2 TrackingOption2 Currency BrandingTheme) + end + + def table + [[]] + end + end +end diff --git a/spec/features/admin/reports_spec.rb b/spec/features/admin/reports_spec.rb index b1685be6db..260c1885ce 100644 --- a/spec/features/admin/reports_spec.rb +++ b/spec/features/admin/reports_spec.rb @@ -297,4 +297,29 @@ feature %q{ ].sort end end + + describe "Xero invoices report" do + let!(:enterprise1) { create( :enterprise, owner: create_enterprise_user ) } + let!(:enterprise2) { create( :enterprise, owner: create_enterprise_user ) } + let!(:enterprise3) { create( :enterprise, owner: create_enterprise_user ) } + + before do + enterprise3.enterprise_roles.build( user: enterprise1.owner ).save + + login_to_admin_section + click_link 'Reports' + + click_link 'Xero invoices' + end + + it "shows Xero invoices report" do + rows = find("table#listing_invoices").all("tr") + table = rows.map { |r| r.all("th,td").map { |c| c.text.strip } } + + table.should == [ + %w(*ContactName EmailAddress POAddressLine1 POAddressLine2 POAddressLine3 POAddressLine4 POCity PORegion POPostalCode POCountry *InvoiceNumber Reference *InvoiceDate *DueDate InventoryItemCode *Description *Quantity *UnitAmount Discount *AccountCode *TaxType TrackingName1 TrackingOption1 TrackingName2 TrackingOption2 Currency BrandingTheme), + [] + ] + end + end end From 03ae740cd6cafe05d9a74bbeaef931e0d3576269 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 1 May 2015 14:55:26 +1000 Subject: [PATCH 14/14] Revert "Display header for Xero invoices report" This reverts commit a6cecdcc25af036f5d0645341cddfac67e376054. --- .../admin/reports_controller_decorator.rb | 26 +++++-------------- .../admin/reports/xero_invoices.html.haml | 13 ---------- config/routes.rb | 1 - lib/open_food_network/xero_invoices_report.rb | 15 ----------- spec/features/admin/reports_spec.rb | 25 ------------------ 5 files changed, 7 insertions(+), 73 deletions(-) delete mode 100644 app/views/spree/admin/reports/xero_invoices.html.haml delete mode 100644 lib/open_food_network/xero_invoices_report.rb diff --git a/app/controllers/spree/admin/reports_controller_decorator.rb b/app/controllers/spree/admin/reports_controller_decorator.rb index aed798827e..f148456813 100644 --- a/app/controllers/spree/admin/reports_controller_decorator.rb +++ b/app/controllers/spree/admin/reports_controller_decorator.rb @@ -7,7 +7,6 @@ require 'open_food_network/customers_report' require 'open_food_network/users_and_enterprises_report' require 'open_food_network/order_cycle_management_report' require 'open_food_network/sales_tax_report' -require 'open_food_network/xero_invoices_report' Spree::Admin::ReportsController.class_eval do @@ -15,10 +14,10 @@ Spree::Admin::ReportsController.class_eval do REPORT_TYPES = { orders_and_fulfillment: [ - ['Order Cycle Supplier Totals', :order_cycle_supplier_totals], - ['Order Cycle Supplier Totals by Distributor', :order_cycle_supplier_totals_by_distributor], - ['Order Cycle Distributor Totals by Supplier', :order_cycle_distributor_totals_by_supplier], - ['Order Cycle Customer Totals', :order_cycle_customer_totals] + ['Order Cycle Supplier Totals',:order_cycle_supplier_totals], + ['Order Cycle Supplier Totals by Distributor',:order_cycle_supplier_totals_by_distributor], + ['Order Cycle Distributor Totals by Supplier',:order_cycle_distributor_totals_by_supplier], + ['Order Cycle Customer Totals',:order_cycle_customer_totals] ], products_and_inventory: [ ['All products', :all_products], @@ -31,16 +30,13 @@ Spree::Admin::ReportsController.class_eval do order_cycle_management: [ ["Payment Methods Report", :payment_methods], ["Delivery Report", :delivery] - ], - xero_invoices: [ - ["Xero Invoices Report", :xero_invoices] ] } # Fetches user's distributors, suppliers and order_cycles before_filter :load_data, only: [:customers, :products_and_inventory, :order_cycle_management] - # Render a partial for various section descriptions + # Render a partial for orders and fulfillment description respond_override :index => { :html => { :success => lambda { @reports[:orders_and_fulfillment][:description] = render_to_string(partial: 'orders_and_fulfillment_description', layout: false, locals: {report_types: REPORT_TYPES[:orders_and_fulfillment]}).html_safe @@ -676,13 +672,7 @@ Spree::Admin::ReportsController.class_eval do render_report(@report.header, @report.table, params[:csv], "users_and_enterprises_#{timestamp}.csv") end - def xero_invoices - @report = OpenFoodNetwork::XeroInvoicesReport.new params - render_report(@report.header, @report.table, params[:csv], "xero_invoices_#{timestamp}.csv") - end - - - def render_report(header, table, create_csv, csv_file_name) + def render_report (header, table, create_csv, csv_file_name) unless create_csv render :html => table else @@ -719,9 +709,7 @@ Spree::Admin::ReportsController.class_eval do :sales_total => { :name => "Sales Total", :description => "Sales Total For All Orders" }, :users_and_enterprises => { :name => "Users & Enterprises", :description => "Enterprise Ownership & Status" }, :order_cycle_management => {:name => "Order Cycle Management", :description => ''}, - :sales_tax => { :name => "Sales Tax", :description => "Sales Tax For Orders" }, - :xero_invoices => { :name => "Xero invoices", :description => 'Invoices for import into Xero' } - + :sales_tax => { :name => "Sales Tax", :description => "Sales Tax For Orders" } } # Return only reports the user is authorized to view. reports.select { |action| can? action, :report } diff --git a/app/views/spree/admin/reports/xero_invoices.html.haml b/app/views/spree/admin/reports/xero_invoices.html.haml deleted file mode 100644 index 0e9598125a..0000000000 --- a/app/views/spree/admin/reports/xero_invoices.html.haml +++ /dev/null @@ -1,13 +0,0 @@ -%table#listing_invoices.index - %thead - %tr - - @report.header.each do |header| - %th= header - %tbody - - @report.table.each do |row| - %tr - - row.each do |column| - %td= column - - if @report.table.empty? - %tr - %td{:colspan => "2"}= t(:none) diff --git a/config/routes.rb b/config/routes.rb index 66805807ce..4621ee4a35 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -134,7 +134,6 @@ Spree::Core::Engine.routes.prepend do match '/admin/orders/bulk_management' => 'admin/orders#bulk_management', :as => "admin_bulk_order_management" match '/admin/reports/products_and_inventory' => 'admin/reports#products_and_inventory', :as => "products_and_inventory_admin_reports", :via => [:get, :post] match '/admin/reports/customers' => 'admin/reports#customers', :as => "customers_admin_reports", :via => [:get, :post] - match '/admin/reports/xero_invoices' => 'admin/reports#xero_invoices', :as => "xero_invoices_admin_reports", :via => [:get, :post] match '/admin', :to => 'admin/overview#index', :as => :admin match '/admin/payment_methods/show_provider_preferences' => 'admin/payment_methods#show_provider_preferences', :via => :get diff --git a/lib/open_food_network/xero_invoices_report.rb b/lib/open_food_network/xero_invoices_report.rb deleted file mode 100644 index 35c3dac73d..0000000000 --- a/lib/open_food_network/xero_invoices_report.rb +++ /dev/null @@ -1,15 +0,0 @@ -module OpenFoodNetwork - class XeroInvoicesReport - def initialize(params={}) - @params = params - end - - def header - %w(*ContactName EmailAddress POAddressLine1 POAddressLine2 POAddressLine3 POAddressLine4 POCity PORegion POPostalCode POCountry *InvoiceNumber Reference *InvoiceDate *DueDate InventoryItemCode *Description *Quantity *UnitAmount Discount *AccountCode *TaxType TrackingName1 TrackingOption1 TrackingName2 TrackingOption2 Currency BrandingTheme) - end - - def table - [[]] - end - end -end diff --git a/spec/features/admin/reports_spec.rb b/spec/features/admin/reports_spec.rb index 260c1885ce..b1685be6db 100644 --- a/spec/features/admin/reports_spec.rb +++ b/spec/features/admin/reports_spec.rb @@ -297,29 +297,4 @@ feature %q{ ].sort end end - - describe "Xero invoices report" do - let!(:enterprise1) { create( :enterprise, owner: create_enterprise_user ) } - let!(:enterprise2) { create( :enterprise, owner: create_enterprise_user ) } - let!(:enterprise3) { create( :enterprise, owner: create_enterprise_user ) } - - before do - enterprise3.enterprise_roles.build( user: enterprise1.owner ).save - - login_to_admin_section - click_link 'Reports' - - click_link 'Xero invoices' - end - - it "shows Xero invoices report" do - rows = find("table#listing_invoices").all("tr") - table = rows.map { |r| r.all("th,td").map { |c| c.text.strip } } - - table.should == [ - %w(*ContactName EmailAddress POAddressLine1 POAddressLine2 POAddressLine3 POAddressLine4 POCity PORegion POPostalCode POCountry *InvoiceNumber Reference *InvoiceDate *DueDate InventoryItemCode *Description *Quantity *UnitAmount Discount *AccountCode *TaxType TrackingName1 TrackingOption1 TrackingName2 TrackingOption2 Currency BrandingTheme), - [] - ] - end - end end