mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Report Refactor 1: Xero Invoices
This commit is contained in:
committed by
Jean-Baptiste Bellet
parent
41c11baa3f
commit
4a99a7d1de
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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]
|
||||
@@ -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)
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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 = {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user