Rename attributes

#623
This commit is contained in:
Artur Beljajev 2018-03-13 11:32:15 +02:00
parent 3d107bd198
commit b68fe6e312
16 changed files with 110 additions and 92 deletions

View file

@ -24,7 +24,7 @@ module Admin
@invoice = Invoice.find_by(id: params[:invoice_id])
@bank_transaction = @bank_statement.bank_transactions.build(
description: @invoice.to_s,
sum: @invoice.sum,
sum: @invoice.amount,
reference_no: @invoice.reference_no,
paid_at: Time.zone.now.to_date,
currency: 'EUR'

View file

@ -55,8 +55,8 @@ class Registrar
end
def normalize_search_parameters
params[:q][:sum_cache_gteq].gsub!(',', '.') if params[:q][:sum_cache_gteq]
params[:q][:sum_cache_lteq].gsub!(',', '.') if params[:q][:sum_cache_lteq]
params[:q][:total_gteq].gsub!(',', '.') if params[:q][:total_gteq]
params[:q][:total_lteq].gsub!(',', '.') if params[:q][:total_lteq]
ca_cache = params[:q][:due_date_lteq]
begin

View file

@ -29,7 +29,7 @@ class BankLink
hash["VK_VERSION"] = "008"
hash["VK_SND_ID"] = ENV["payments_#{type}_seller_account"]
hash["VK_STAMP"] = invoice.number
hash["VK_AMOUNT"] = number_with_precision(invoice.sum_cache, :precision => 2, :separator => ".")
hash["VK_AMOUNT"] = number_with_precision(invoice.total, :precision => 2, :separator => ".")
hash["VK_CURR"] = invoice.currency
hash["VK_REF"] = ""
hash["VK_MSG"] = invoice.order
@ -140,7 +140,7 @@ class BankLink
def validate_amount
source = number_with_precision(BigDecimal.new(params["VK_AMOUNT"].to_s), precision: 2, separator: ".")
target = number_with_precision(invoice.sum_cache, precision: 2, separator: ".")
target = number_with_precision(invoice.total, precision: 2, separator: ".")
source == target
end

View file

@ -47,7 +47,7 @@ class BankTransaction < ActiveRecord::Base
return if invoice.binded?
return if invoice.cancelled?
return if invoice.sum != sum
return if invoice.total != sum
create_activity(registrar, invoice)
end
# rubocop: enable Metrics/PerceivedComplexity
@ -76,7 +76,7 @@ class BankTransaction < ActiveRecord::Base
return
end
if invoice.sum != sum
if invoice.total != sum
errors.add(:base, I18n.t('invoice_and_transaction_sums_do_not_match'))
return
end
@ -88,7 +88,7 @@ class BankTransaction < ActiveRecord::Base
create_account_activity(
account: registrar.cash_account,
invoice: invoice,
sum: invoice.sum_without_vat,
sum: invoice.subtotal,
currency: currency,
description: description,
activity_type: AccountActivity::ADD_CREDIT

View file

@ -15,7 +15,7 @@ class Directo < ActiveRecord::Base
group.each do |invoice|
if invoice.account_activity.nil? || invoice.account_activity.bank_transaction.nil? ||
invoice.account_activity.bank_transaction.sum.nil? || invoice.account_activity.bank_transaction.sum != invoice.sum_cache
invoice.account_activity.bank_transaction.sum.nil? || invoice.account_activity.bank_transaction.sum != invoice.total
Rails.logger.info("[DIRECTO] Invoice #{invoice.number} has been skipped")
next
end
@ -34,7 +34,7 @@ class Directo < ActiveRecord::Base
xml.line(
"ProductID" => Setting.directo_receipt_product_name,
"Quantity" => 1,
"UnitPriceWoVAT" => ActionController::Base.helpers.number_with_precision(invoice.sum_cache/(1+invoice.vat_rate), precision: 2, separator: "."),
"UnitPriceWoVAT" => ActionController::Base.helpers.number_with_precision(invoice.total/(1+invoice.vat_rate), precision: 2, separator: "."),
"ProductName" => invoice.order
)
}

View file

@ -34,6 +34,7 @@ class Invoice < ActiveRecord::Base
before_create :set_invoice_number
before_create :apply_default_vat_rate, unless: :vat_rate?
before_create :save_total
attribute :vat_rate, ::Type::VATRate.new
attr_readonly :vat_rate
@ -54,8 +55,6 @@ class Invoice < ActiveRecord::Base
false
end
before_save -> { self.sum_cache = sum }
class << self
def cancel_overdue_invoices
STDOUT << "#{Time.zone.now.utc} - Cancelling overdue invoices\n" unless Rails.env.test?
@ -150,17 +149,13 @@ class Invoice < ActiveRecord::Base
invoice_items
end
def sum_without_vat
def subtotal
(items.map(&:item_sum_without_vat).sum).round(2)
end
def vat
return 0 unless vat_rate
sum_without_vat * vat_rate / 100
end
def sum
(sum_without_vat + vat).round(2)
subtotal * vat_rate / 100
end
private
@ -168,4 +163,8 @@ class Invoice < ActiveRecord::Base
def apply_default_vat_rate
self.vat_rate = buyer.effective_vat_rate
end
def calculate_total
# (sum_without_vat + vat).round(2)
end
end

View file

@ -33,11 +33,11 @@
.col-md-3
.form-group
= f.label t(:minimum_total)
= f.search_field :sum_cache_gteq, class: 'form-control', placeholder: t(:minimum_total), autocomplete: 'off'
= f.search_field :total_gteq, class: 'form-control', placeholder: t(:minimum_total), autocomplete: 'off'
.col-md-3
.form-group
= f.label t(:maximum_total)
= f.search_field :sum_cache_lteq, class: 'form-control', placeholder: t(:maximum_total), autocomplete: 'off'
= f.search_field :total_lteq, class: 'form-control', placeholder: t(:maximum_total), autocomplete: 'off'
.col-md-3{style: 'padding-top: 25px;'}
%button.btn.btn-default
&nbsp;
@ -67,7 +67,7 @@
%td{class: 'text-danger'}= t(:unpaid)
%td= l(x.due_date, format: :date_long)
%td= currency(x.sum)
%td= currency(x.total)
.row
.col-md-12
= paginate @invoices

View file

@ -21,7 +21,7 @@
%tr
%th{colspan: 3}
%th= t(:total_without_vat)
%td= currency(@invoice.sum_without_vat)
%td= currency(@invoice.subtotal)
%tr
%th.no-border{colspan: 3}
%th= t('vat', rate: number_to_percentage(@invoice.vat_rate, precision: 1))
@ -29,4 +29,4 @@
%tr
%th.no-border{colspan: 3}
%th= t(:total)
%td= currency(@invoice.sum)
%td= currency(@invoice.total)

View file

@ -239,7 +239,7 @@
%tr
%th{colspan: 3}
%th= t(:total_without_vat)
%td= "#{currency(@invoice.sum_without_vat)} #{@invoice.currency}"
%td= "#{currency(@invoice.subtotal)} #{@invoice.currency}"
%tr
%th.no-border{colspan: 3}
%th= t('vat', rate: number_to_percentage(@invoice.vat_rate, precision: 1))
@ -247,7 +247,7 @@
%tr
%th.no-border{colspan: 3}
%th= t(:total)
%td= "#{currency(@invoice.sum)} #{@invoice.currency}"
%td= "#{currency(@invoice.total)} #{@invoice.currency}"
#footer
%hr