From cbd0ace0981db928f16d3bd474842e266f0ed35a Mon Sep 17 00:00:00 2001 From: Lynne Davis Date: Thu, 24 Mar 2016 16:57:56 +0000 Subject: [PATCH] Code tidying and currency symbol internationalisation --- .../edit.html.haml | 6 ++++-- lib/open_food_network/bill_calculator.rb | 21 +++++++++++-------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/app/views/admin/business_model_configuration/edit.html.haml b/app/views/admin/business_model_configuration/edit.html.haml index 8a5c368444..a38e22eb17 100644 --- a/app/views/admin/business_model_configuration/edit.html.haml +++ b/app/views/admin/business_model_configuration/edit.html.haml @@ -92,10 +92,12 @@ = label_tag :included_tax, t(:included_tax) %span.icon-question-sign{'ofn-with-tip' => "The total tax included in the example monthly bill, given the settings and the turnover provided."} .two.columns.omega - %input.fullwidth{ id: 'included_tax', type: "text", readonly: true, ng: { value: 'includedTax() | currency' } } + %span= Spree::Money.currency_symbol + %input.fullwidth{ id: 'included_tax', type: "text", readonly: true, ng: { value: 'includedTax()' } } .row .three.columns.alpha = label_tag :total_incl_tax, t(:total_monthly_bill_incl_tax) %span.icon-question-sign{'ofn-with-tip' => "The example total monthly bill with tax included, given the settings and the turnover provided."} .two.columns.omega - %input.fullwidth{ id: 'total_incl_tax', type: "text", readonly: true, ng: { value: 'total() | currency' } } + %span= Spree::Money.currency_symbol + %input.fullwidth{ id: 'total_incl_tax', type: "text", readonly: true, ng: { value: 'total()' } } diff --git a/lib/open_food_network/bill_calculator.rb b/lib/open_food_network/bill_calculator.rb index d5302c0996..207a799bda 100644 --- a/lib/open_food_network/bill_calculator.rb +++ b/lib/open_food_network/bill_calculator.rb @@ -1,21 +1,24 @@ -module OpenFoodNetwork + module OpenFoodNetwork class BillCalculator attr_accessor :turnover, :fixed, :rate, :cap, :tax_rate, :min_bill_to def initialize(opts={}) - @turnover = opts[:turnover] || 0 - @fixed = opts[:fixed] || Spree::Config[:account_invoices_monthly_fixed] - @rate = opts[:rate] || Spree::Config[:account_invoices_monthly_rate] - @cap = opts[:cap] || Spree::Config[:account_invoices_monthly_cap] - @tax_rate = opts[:tax_rate] || Spree::Config[:account_invoices_tax_rate] - @min_bill_to = opts[:min_bill_to] || Spree::Config[:minimum_billable_turnover] + defaults = { + fixed: :account_invoices_monthly_fixed + rate: :account_invoices_monthly_rate + cap: :account_invoices_monthly_cap + tax_rate: :account_invoices_tax_rate + min_bill_to: :minimum_billable_turnover + } + defaults.each do |key, config| + this[key] = opts[key] || Spree::Config[config] + end end def bill bill = fixed + (turnover * rate) - bill = cap > 0 ? [bill, cap].min : bill + bill = [bill, cap].min if cap > 0 bill = turnover > min_bill_to ? bill : 0 bill * (1 + tax_rate) end - end end