From 0868cee6d924688d4fd523b96127834b56d6d0bf Mon Sep 17 00:00:00 2001 From: Du Peng Date: Fri, 24 Dec 2021 19:05:03 +0100 Subject: [PATCH] fix bug: multi VAT setting no exsit --- app/services/vat_history_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/vat_history_service.rb b/app/services/vat_history_service.rb index c072d0ac2..1beb048cf 100644 --- a/app/services/vat_history_service.rb +++ b/app/services/vat_history_service.rb @@ -37,7 +37,7 @@ class VatHistoryService vat_rate_history_values = [] if vat_rate_type.present? vat_rate_by_type = Setting.find_by(name: "invoice_VAT-rate_#{vat_rate_type}")&.history_values&.order(created_at: 'ASC') - first_vat_rate_by_type = vat_rate_by_type.select { |v| v.value.present? }.first + first_vat_rate_by_type = vat_rate_by_type&.select { |v| v.value.present? }&.first if first_vat_rate_by_type vat_rate_history_values = Setting.find_by(name: 'invoice_VAT-rate').history_values.where('created_at < ?', first_vat_rate_by_type.created_at).order(created_at: 'ASC').to_a vat_rate_by_type = Setting.find_by(name: "invoice_VAT-rate_#{vat_rate_type}").history_values.where('created_at >= ?', first_vat_rate_by_type.created_at).order(created_at: 'ASC')