1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-26 20:54:21 +01:00

fix bug: accounting period export

This commit is contained in:
Du Peng 2021-12-24 19:37:43 +01:00 committed by Sylvain
parent 0868cee6d9
commit d52b8bde06
3 changed files with 10 additions and 5 deletions

View File

@ -34,7 +34,12 @@ class AccountingPeriod < ApplicationRecord
def invoices_with_vat(invoices)
vat_service = VatHistoryService.new
invoices.map do |i|
{ invoice: i, vat_rate: vat_service.invoice_vat(i) / 100.0 }
vat_rate_group = {}
i.invoice_items.each do |item|
vat_type = item.invoice_item_type
vat_rate_group[vat_type] = vat_service.invoice_vat(item) / 100.0 unless vat_rate_group[vat_type]
end
{ invoice: i, vat_rate: vat_rate_group }
end
end
@ -70,7 +75,7 @@ class AccountingPeriod < ApplicationRecord
end
def price_without_taxe(invoice)
invoice[:invoice].total - (invoice[:invoice].total * invoice[:vat_rate])
invoice[:invoice].invoice_items.map(&:net_amount).sum
end
def compute_totals

View File

@ -134,9 +134,9 @@ class AccountingExportService
# Generate the "VAT" row, which contains the credit to the VAT account, with VAT amount only
def vat_row(invoice)
rate = VatHistoryService.new.invoice_vat(invoice)
total = invoice.invoice_items.map(&:net_amount).sum
# we do not render the VAT row if it was disabled for this invoice
return nil if rate.zero?
return nil if total == invoice.total
row(
invoice,

View File

@ -34,7 +34,7 @@ json.invoices do
json.id item.object_id
json.main item.main
end
json.partial! 'archive/vat', price: item.amount, vat_rate: invoice[:vat_rate]
json.partial! 'archive/vat', price: item.amount, vat_rate: invoice[:vat_rate][item.invoice_item_type]
end
end
end