diff --git a/app/controllers/spree/admin/reports_controller.rb b/app/controllers/spree/admin/reports_controller.rb index 159dd390c9..dea9c5c45d 100644 --- a/app/controllers/spree/admin/reports_controller.rb +++ b/app/controllers/spree/admin/reports_controller.rb @@ -94,15 +94,10 @@ module Spree end def xero_invoices - raw_params[:q] ||= {} - @distributors = my_distributors @order_cycles = my_order_cycles - @report = OpenFoodNetwork::XeroInvoicesReport.new(spree_current_user, - raw_params, - render_content?) - render_report(@report.header, @report.table, params[:csv], "xero_invoices_#{timestamp}.csv") + render_report2 end private diff --git a/app/helpers/spree/reports_helper.rb b/app/helpers/spree/reports_helper.rb index 80bafa4c5a..05b3fa7af6 100644 --- a/app/helpers/spree/reports_helper.rb +++ b/app/helpers/spree/reports_helper.rb @@ -21,11 +21,6 @@ module Spree end.uniq end - def xero_report_types - [[I18n.t(:summary), 'summary'], - [I18n.t(:detailed), 'detailed']] - end - def currency_symbol Spree::Money.currency_symbol end diff --git a/app/views/spree/admin/reports/filters/_xero_invoices.html.haml b/app/views/spree/admin/reports/filters/_xero_invoices.html.haml new file mode 100644 index 0000000000..d6425ed0bd --- /dev/null +++ b/app/views/spree/admin/reports/filters/_xero_invoices.html.haml @@ -0,0 +1,23 @@ += render 'spree/admin/reports/date_range_form', f: f + +.row + .two.columns.alpha= label_tag nil, t(:report_hubs) + .fourteen.columns.omega= f.collection_select(:distributor_id_eq, @distributors, :id, :name, {:include_blank => 'All'}, {:class => "select2 fullwidth light"}) +.row + .two.columns.alpha= label_tag nil, t(:report_order_cycle) + .fourteen.columns.omega= f.select(:order_cycle_id_eq, + options_for_select(report_order_cycle_options(@order_cycles), params.dig(:q, :order_cycle_id_eq)), + {:include_blank => true}, {:class => "select2 fullwidth light"}) + +.row + .two.columns.alpha= label_tag :initial_invoice_number, t(:initial_invoice_number) + .fourteen.columns.omega= text_field_tag :initial_invoice_number, params[:initial_invoice_number] +.row + .two.columns.alpha= label_tag :invoice_date, t(:invoice_date) + .fourteen.columns.omega= text_field_tag :invoice_date, params[:invoice_date], class: 'datetimepicker' +.row + .two.columns.alpha= label_tag :due_date, t(:due_date) + .fourteen.columns.omega= text_field_tag :due_date, params[:due_date], class: 'datetimepicker' +.row + .two.columns.alpha= label_tag :account_code, t(:account_code) + .fourteen.columns.omega= text_field_tag :account_code, params[:account_code] 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 b445e1b230..0000000000 --- a/app/views/spree/admin/reports/xero_invoices.html.haml +++ /dev/null @@ -1,35 +0,0 @@ -= form_for @report.search, url: spree.xero_invoices_admin_reports_path do |f| - = render 'date_range_form', f: f - - .row - .four.columns.alpha= label_tag :report_type, t(:report_type) - .four.columns.omega= select_tag :report_type, options_for_select(xero_report_types, params[:report_type]), {include_blank: false, class: "select2 fullwidth"} - .row - .four.columns.alpha= label_tag nil, t(:report_hubs) - .four.columns.omega= f.collection_select(:distributor_id_eq, @distributors, :id, :name, {:include_blank => 'All'}, {:class => "select2 fullwidth"}) - .row - .four.columns.alpha= label_tag nil, t(:report_order_cycle) - .four.columns.omega= f.select(:order_cycle_id_eq, - options_for_select(report_order_cycle_options(@order_cycles), params.dig(:q, :order_cycle_id_eq)), - {:include_blank => true}, {:class => "select2 fullwidth"}) - - .row - .four.columns.alpha= label_tag :initial_invoice_number, t(:initial_invoice_number) - .twelve.columns.omega= text_field_tag :initial_invoice_number, params[:initial_invoice_number] - .row - .four.columns.alpha= label_tag :invoice_date, t(:invoice_date) - .twelve.columns.omega= text_field_tag :invoice_date, params[:invoice_date], class: 'datetimepicker' - .row - .four.columns.alpha= label_tag :due_date, t(:due_date) - .twelve.columns.omega= text_field_tag :due_date, params[:due_date], class: 'datetimepicker' - .row - .four.columns.alpha= label_tag :account_code, t(:account_code) - .twelve.columns.omega= text_field_tag :account_code, params[:account_code] - .row - .four.columns.alpha= label_tag :csv, t(:report_customers_csv) - .twelve.columns.omega= check_box_tag :csv - .row - .four.columns.alpha= button t(:search) - - -= render "table", id: "listing_invoices", msg_option: t(:search) diff --git a/lib/open_food_network/reports/list.rb b/lib/open_food_network/reports/list.rb index bfbc625488..96bae561fc 100644 --- a/lib/open_food_network/reports/list.rb +++ b/lib/open_food_network/reports/list.rb @@ -15,7 +15,8 @@ module OpenFoodNetwork enterprise_fee_summary: enterprise_fee_summary_report_types, order_cycle_management: order_cycle_management_report_types, sales_tax: sales_tax_report_types, - packing: packing_report_types + packing: packing_report_types, + xero_invoices: xero_report_types } end @@ -73,6 +74,11 @@ module OpenFoodNetwork ] end + def xero_report_types + [[I18n.t(:summary), 'summary'], + [I18n.t(:detailed), 'detailed']] + end + def i18n_translate(key) I18n.t(key, scope: "admin.reports") end diff --git a/lib/open_food_network/xero_invoices_report.rb b/lib/open_food_network/xero_invoices_report.rb index a874bd6047..da36a04860 100644 --- a/lib/open_food_network/xero_invoices_report.rb +++ b/lib/open_food_network/xero_invoices_report.rb @@ -8,14 +8,14 @@ module OpenFoodNetwork @opts = opts. symbolize_keys. reject { |_k, v| v.blank? }. - reverse_merge( report_type: 'summary', + reverse_merge( report_subtype: 'summary', invoice_date: Time.zone.today, due_date: Time.zone.today + 1.month, account_code: 'food sales' ) @compile_table = compile_table end - def header + def table_headers # NOTE: These are NOT to be translated, they need to be in this exact format to work with Xero %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 Paid?) @@ -30,7 +30,7 @@ module OpenFoodNetwork search.result.reorder('id DESC') end - def table + def table_rows return [] unless @compile_table rows = [] @@ -225,7 +225,7 @@ module OpenFoodNetwork end def detail? - @opts[:report_type] == 'detailed' + @opts[:report_subtype] == 'detailed' end def tax_type(taxable) diff --git a/spec/lib/open_food_network/xero_invoices_report_spec.rb b/spec/lib/open_food_network/xero_invoices_report_spec.rb index bcc77347c2..5235edd972 100644 --- a/spec/lib/open_food_network/xero_invoices_report_spec.rb +++ b/spec/lib/open_food_network/xero_invoices_report_spec.rb @@ -21,7 +21,7 @@ module OpenFoodNetwork expect(report.instance_variable_get(:@opts)).to eq( invoice_date: Date.civil(2015, 5, 5), due_date: Date.civil(2015, 6, 5), account_code: 'food sales', - report_type: 'summary' ) + report_subtype: 'summary' ) end end diff --git a/spec/system/admin/reports_spec.rb b/spec/system/admin/reports_spec.rb index 98c777ef7f..3bd13bc8fe 100644 --- a/spec/system/admin/reports_spec.rb +++ b/spec/system/admin/reports_spec.rb @@ -480,7 +480,7 @@ describe ' end it "shows Xero invoices report" do - click_button "Search" + click_button "Go" expect(xero_invoice_table).to match_table [ xero_invoice_header, xero_invoice_summary_row('Total untaxable produce (no tax)', 12.54, @@ -506,7 +506,7 @@ describe ' pick_datetime '#due_date', Date.new(2021, 3, 12) fill_in 'account_code', with: 'abc123' - click_button 'Search' + click_button 'Go' opts = { invoice_number: '5', invoice_date: '2021-02-12 00:00', due_date: '2021-03-12 00:00', account_code: 'abc123' } @@ -531,8 +531,8 @@ describe ' end it "generates a detailed report" do - select 'Detailed', from: 'report_type' - click_button 'Search' + select 'Detailed', from: 'report_subtype' + click_button 'Go' opts = {}