From dda3a8c45f0888e0ce7e21be0592239f88005299 Mon Sep 17 00:00:00 2001 From: Sergei Tsoganov Date: Tue, 3 Oct 2023 09:37:50 +0300 Subject: [PATCH 01/10] Added Balance element to InvoiceSumGroup --- CHANGELOG.md | 3 +++ lib/e_invoice/generator.rb | 13 ++++++++++--- lib/e_invoice/invoice.rb | 7 ++++--- lib/e_invoice/version.rb | 2 +- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc304a4..96a1aeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +03.10.2023 +* Added Balance element to InvoiceSumGroup + 26.09.2023 * Updated wsdl test address [#36](https://github.com/internetee/e_invoice/pull/36) diff --git a/lib/e_invoice/generator.rb b/lib/e_invoice/generator.rb index b2522ec..571fdf3 100644 --- a/lib/e_invoice/generator.rb +++ b/lib/e_invoice/generator.rb @@ -108,10 +108,17 @@ def build_invoice_details(invoice) def build_invoice_totals(invoice) builder.InvoiceSumGroup do + builder.Balance do + builder.BalanceDate invoice.balance_date if invoice.balance_date + builder.BalanceBegin format_decimal(invoice.balance_begin) if invoice.balance_begin + builder.Inbound format_decimal(invoice.inbound) if invoice.inbound + builder.Outbound format_decimal(invoice.outbound) if invoice.outbound + builder.BalanceEnd format_decimal(invoice.balance_end) if invoice.balance_end + end builder.InvoiceSum format_decimal(invoice.subtotal, scale: 4) builder.TotalVATSum format_decimal(invoice.vat_amount) builder.TotalSum format_decimal(invoice.total) - builder.TotalToPay format_decimal(invoice.payable == false ? 0 : invoice.total) + builder.TotalToPay format_decimal(invoice.payable == false ? 0 : invoice.total_to_pay) builder.Currency invoice.currency end end @@ -123,7 +130,7 @@ def build_invoice_payment_details(invoice) builder.PaymentDescription invoice.number builder.Payable invoice.payable == false ? 'NO' : 'YES' builder.PayDueDate invoice.due_date - builder.PaymentTotalSum format_decimal(invoice.payable == false ? 0 : invoice.total) + builder.PaymentTotalSum format_decimal(invoice.payable == false ? 0 : invoice.total_to_pay) builder.PayerName invoice.payer_name builder.PaymentId invoice.number builder.PayToAccount invoice.beneficiary_account_number @@ -206,4 +213,4 @@ def format_decimal(decimal, scale: 2) format("%.#{scale}f", decimal) end end -end \ No newline at end of file +end diff --git a/lib/e_invoice/invoice.rb b/lib/e_invoice/invoice.rb index fd79557..9590f3f 100644 --- a/lib/e_invoice/invoice.rb +++ b/lib/e_invoice/invoice.rb @@ -4,8 +4,9 @@ class Invoice :date, :recipient_id_code, :reference_number, :due_date, :payable, :payer_name, :beneficiary_name, :beneficiary_account_number, - :subtotal, :vat_amount, :total, :currency, - :monthly_invoice + :subtotal, :vat_amount, :total, :total_to_pay, :currency, + :balance_date, :balance_begin, :inbound, :outbound, + :balance_end, :monthly_invoice alias_method :id, :number @@ -35,4 +36,4 @@ def validate_delivery_channels(channels) end end end -end \ No newline at end of file +end diff --git a/lib/e_invoice/version.rb b/lib/e_invoice/version.rb index 10a5716..ce30362 100644 --- a/lib/e_invoice/version.rb +++ b/lib/e_invoice/version.rb @@ -1,3 +1,3 @@ module EInvoice - VERSION = '0.1.4'.freeze + VERSION = '0.1.5'.freeze end From 20dd41e89853bde12a4fd7e755ef629716098580 Mon Sep 17 00:00:00 2001 From: Sergei Tsoganov Date: Tue, 3 Oct 2023 10:00:57 +0300 Subject: [PATCH 02/10] Updated CHANGELOG.md --- CHANGELOG.md | 2 +- lib/e_invoice/generator.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96a1aeb..38d6477 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ 03.10.2023 -* Added Balance element to InvoiceSumGroup +* Added Balance element to InvoiceSumGroup [#41] (https://github.com/internetee/e_invoice/pull/41) 26.09.2023 * Updated wsdl test address [#36](https://github.com/internetee/e_invoice/pull/36) diff --git a/lib/e_invoice/generator.rb b/lib/e_invoice/generator.rb index 571fdf3..8d93929 100644 --- a/lib/e_invoice/generator.rb +++ b/lib/e_invoice/generator.rb @@ -210,7 +210,7 @@ def build_footer(e_invoice) end def format_decimal(decimal, scale: 2) - format("%.#{scale}f", decimal) + format("%.#{scale}f", decimal) if decimal end end end From dd9b534a6676bc06abdadeefb483751348821ab2 Mon Sep 17 00:00:00 2001 From: Sergei Tsoganov Date: Tue, 3 Oct 2023 10:10:45 +0300 Subject: [PATCH 03/10] Fixed codeclimate issues --- lib/e_invoice/generator.rb | 18 +++++++++++------- test/generator_test.rb | 2 ++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/e_invoice/generator.rb b/lib/e_invoice/generator.rb index 8d93929..b038291 100644 --- a/lib/e_invoice/generator.rb +++ b/lib/e_invoice/generator.rb @@ -108,13 +108,7 @@ def build_invoice_details(invoice) def build_invoice_totals(invoice) builder.InvoiceSumGroup do - builder.Balance do - builder.BalanceDate invoice.balance_date if invoice.balance_date - builder.BalanceBegin format_decimal(invoice.balance_begin) if invoice.balance_begin - builder.Inbound format_decimal(invoice.inbound) if invoice.inbound - builder.Outbound format_decimal(invoice.outbound) if invoice.outbound - builder.BalanceEnd format_decimal(invoice.balance_end) if invoice.balance_end - end + build_invoice_balance(invoice) builder.InvoiceSum format_decimal(invoice.subtotal, scale: 4) builder.TotalVATSum format_decimal(invoice.vat_amount) builder.TotalSum format_decimal(invoice.total) @@ -123,6 +117,16 @@ def build_invoice_totals(invoice) end end + def build_invoice_balance(invoice) + builder.Balance do + builder.BalanceDate invoice.balance_date if invoice.balance_date + builder.BalanceBegin format_decimal(invoice.balance_begin) if invoice.balance_begin + builder.Inbound format_decimal(invoice.inbound) if invoice.inbound + builder.Outbound format_decimal(invoice.outbound) if invoice.outbound + builder.BalanceEnd format_decimal(invoice.balance_end) if invoice.balance_end + end + end + def build_invoice_payment_details(invoice) builder.PaymentInfo do builder.Currency invoice.currency diff --git a/test/generator_test.rb b/test/generator_test.rb index 16f5032..d523186 100644 --- a/test/generator_test.rb +++ b/test/generator_test.rb @@ -160,6 +160,7 @@ def test_generates_e_invoice_xml + 100.0000 20.00 120.00 @@ -274,6 +275,7 @@ def test_generates_prepaid_e_invoice_xml + 100.0000 20.00 120.00 From f7eddbf82a467ce3fb72efad1ebaaf0f7d171c04 Mon Sep 17 00:00:00 2001 From: Sergei Tsoganov Date: Tue, 3 Oct 2023 10:24:59 +0300 Subject: [PATCH 04/10] Fixed codeclimate issue --- lib/e_invoice/generator.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/e_invoice/generator.rb b/lib/e_invoice/generator.rb index b038291..8356aef 100644 --- a/lib/e_invoice/generator.rb +++ b/lib/e_invoice/generator.rb @@ -119,14 +119,21 @@ def build_invoice_totals(invoice) def build_invoice_balance(invoice) builder.Balance do - builder.BalanceDate invoice.balance_date if invoice.balance_date - builder.BalanceBegin format_decimal(invoice.balance_begin) if invoice.balance_begin - builder.Inbound format_decimal(invoice.inbound) if invoice.inbound - builder.Outbound format_decimal(invoice.outbound) if invoice.outbound - builder.BalanceEnd format_decimal(invoice.balance_end) if invoice.balance_end + build_element('BalanceDate', invoice.balance_date) + build_element('BalanceBegin', invoice.balance_begin, :format_decimal) + build_element('Inbound', invoice.inbound, :format_decimal) + build_element('Outbound', invoice.outbound, :format_decimal) + build_element('BalanceEnd', invoice.balance_end, :format_decimal) end end + def build_element(name, value, format_method = nil) + return unless value + + formatted_value = format_method ? send(format_method, value) : value + builder.__send__(name, formatted_value) + end + def build_invoice_payment_details(invoice) builder.PaymentInfo do builder.Currency invoice.currency From dd13a3036653cabb6368dfe3c6acebfe2158149e Mon Sep 17 00:00:00 2001 From: Sergei Tsoganov Date: Tue, 3 Oct 2023 10:41:36 +0300 Subject: [PATCH 05/10] Fixed total to pay --- lib/e_invoice/generator.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/e_invoice/generator.rb b/lib/e_invoice/generator.rb index 8356aef..b05ba2c 100644 --- a/lib/e_invoice/generator.rb +++ b/lib/e_invoice/generator.rb @@ -112,6 +112,11 @@ def build_invoice_totals(invoice) builder.InvoiceSum format_decimal(invoice.subtotal, scale: 4) builder.TotalVATSum format_decimal(invoice.vat_amount) builder.TotalSum format_decimal(invoice.total) + if invoice.payable == false + builder.TotalToPay format_decimal(0) + else + builder.TotalToPay format_decimal(invoice.total_to_pay.presence || invoice.total) + end builder.TotalToPay format_decimal(invoice.payable == false ? 0 : invoice.total_to_pay) builder.Currency invoice.currency end @@ -141,7 +146,11 @@ def build_invoice_payment_details(invoice) builder.PaymentDescription invoice.number builder.Payable invoice.payable == false ? 'NO' : 'YES' builder.PayDueDate invoice.due_date - builder.PaymentTotalSum format_decimal(invoice.payable == false ? 0 : invoice.total_to_pay) + if invoice.payable == false + builder.PaymentTotalSum format_decimal(0) + else + builder.PaymentTotalSum format_decimal(invoice.total_to_pay.presence || invoice.total) + end builder.PayerName invoice.payer_name builder.PaymentId invoice.number builder.PayToAccount invoice.beneficiary_account_number From 320c54dd314018f9383ed5b828449176f11734c2 Mon Sep 17 00:00:00 2001 From: Sergei Tsoganov Date: Tue, 3 Oct 2023 10:43:30 +0300 Subject: [PATCH 06/10] Fixed total to pay --- lib/e_invoice/generator.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/e_invoice/generator.rb b/lib/e_invoice/generator.rb index b05ba2c..4c05232 100644 --- a/lib/e_invoice/generator.rb +++ b/lib/e_invoice/generator.rb @@ -117,7 +117,6 @@ def build_invoice_totals(invoice) else builder.TotalToPay format_decimal(invoice.total_to_pay.presence || invoice.total) end - builder.TotalToPay format_decimal(invoice.payable == false ? 0 : invoice.total_to_pay) builder.Currency invoice.currency end end From 736603a9b6feed78e5fb8f770b0189a1e2a05c5b Mon Sep 17 00:00:00 2001 From: Sergei Tsoganov Date: Tue, 3 Oct 2023 10:58:35 +0300 Subject: [PATCH 07/10] Fixed generator.rb --- lib/e_invoice/generator.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/e_invoice/generator.rb b/lib/e_invoice/generator.rb index 4c05232..bb70931 100644 --- a/lib/e_invoice/generator.rb +++ b/lib/e_invoice/generator.rb @@ -115,7 +115,7 @@ def build_invoice_totals(invoice) if invoice.payable == false builder.TotalToPay format_decimal(0) else - builder.TotalToPay format_decimal(invoice.total_to_pay.presence || invoice.total) + builder.TotalToPay format_decimal(invoice.total_to_pay || invoice.total) end builder.Currency invoice.currency end @@ -148,7 +148,7 @@ def build_invoice_payment_details(invoice) if invoice.payable == false builder.PaymentTotalSum format_decimal(0) else - builder.PaymentTotalSum format_decimal(invoice.total_to_pay.presence || invoice.total) + builder.PaymentTotalSum format_decimal(invoice.total_to_pay || invoice.total) end builder.PayerName invoice.payer_name builder.PaymentId invoice.number From 4586d73cbfba2aeea50c245d3387f36f395104c3 Mon Sep 17 00:00:00 2001 From: Sergei Tsoganov Date: Tue, 3 Oct 2023 12:34:58 +0300 Subject: [PATCH 08/10] Covered with test --- estonian_e_invoice.gemspec | 1 + test/generator_test.rb | 130 ++++++++++++++++++++++++++++++++++++- test/test_helper.rb | 3 +- 3 files changed, 132 insertions(+), 2 deletions(-) diff --git a/estonian_e_invoice.gemspec b/estonian_e_invoice.gemspec index 99016c6..d1b94dc 100644 --- a/estonian_e_invoice.gemspec +++ b/estonian_e_invoice.gemspec @@ -35,4 +35,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'rake', '~> 13.0' spec.add_development_dependency 'simplecov' spec.add_development_dependency 'webmock' + spec.add_development_dependency 'mocha' end \ No newline at end of file diff --git a/test/generator_test.rb b/test/generator_test.rb index d523186..c996388 100644 --- a/test/generator_test.rb +++ b/test/generator_test.rb @@ -75,7 +75,13 @@ def invoice(payable: @payable) invoice.subtotal = 100 invoice.vat_amount = 20 invoice.total = 120 + invoice.total_to_pay = nil invoice.delivery_channel = :internet_bank + invoice.balance_date = nil + invoice.balance_begin = nil + invoice.inbound = nil + invoice.outbound = nil + invoice.balance_end = nil end end @@ -331,6 +337,128 @@ def test_generates_prepaid_e_invoice_xml assert_equal expected_xml, actual_xml end + def test_generates_prepaid_e_invoice_xml_with_balance_inbound + expected_xml = <<~XML + + +
+ 2010-07-05 + id1234 + 1.2 +
+ + + + John Doe + john-1234 + US1234 + + + seller address line1 + seller address line2 + seller address city + 12345 + seller address country + + + + + Jane Doe + 1234 + US1234 + + info@buyer.test + + buyer address line1 + buyer address line2 + buyer address city + 123456 + buyer address country + + + + GB33BUKB20201555555555 + + + + + + ARVE + invoice-1234 + 1234 + 2010-07-06 + 2010-07-07 + + INTERNET_BANK + + + SENT + + + + + 60.00 + + 100.0000 + 20.00 + 120.00 + 60.00 + EUR + + + + + acme services + + pc + 1.0000 + 100.0000 + + 100.0000 + + 20.00 + 20.0000 + + 120.0000 + + + + 120.0000 + 100.0000 + 120.0000 + + + + EUR + 1234 + invoice-1234 + YES + 2010-07-07 + 60.00 + John Smith + invoice-1234 + GB33BUKB20201555555556 + Acme Ltd + + +
+ 1 + 120.00 +
+
+ XML + + e_invoice = EInvoiceDouble.new(payable: true) + EInvoice::Invoice.any_instance.stubs(:total_to_pay).returns(60) + EInvoice::Invoice.any_instance.stubs(:inbound).returns(60) + + actual_xml = Nokogiri::XML(@generator.generate(e_invoice)) { |config| config.noblanks } + .to_xml + + expected_xml = Nokogiri::XML(expected_xml) { |config| config.noblanks }.to_xml + assert_equal expected_xml, actual_xml + end + def test_generated_xml_conforms_to_estonian_e_invoice_standard_v1_2 schema = Nokogiri::XML::Schema(File.read('test/xml_schemas/v1.2.xsd')) xml = @generator.generate(EInvoiceDouble.new) @@ -339,4 +467,4 @@ def test_generated_xml_conforms_to_estonian_e_invoice_standard_v1_2 valid = errors.empty? assert valid, proc { errors.each { |error| puts error } } end -end \ No newline at end of file +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 9a1cf15..e6c27d4 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -6,4 +6,5 @@ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) require 'e_invoice' require 'minitest/autorun' -require 'webmock/minitest' \ No newline at end of file +require 'webmock/minitest' +require 'mocha/minitest' \ No newline at end of file From 7d66078d2fac2e0f2a0069f3f6b0d5e4e3b41d5c Mon Sep 17 00:00:00 2001 From: Sergei Tsoganov Date: Tue, 3 Oct 2023 12:36:21 +0300 Subject: [PATCH 09/10] Fixed codeclimate issue --- estonian_e_invoice.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/estonian_e_invoice.gemspec b/estonian_e_invoice.gemspec index d1b94dc..d1e098e 100644 --- a/estonian_e_invoice.gemspec +++ b/estonian_e_invoice.gemspec @@ -32,8 +32,8 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency 'savon' spec.add_development_dependency 'bundler', '>= 2.2.10' spec.add_development_dependency 'minitest', '~> 5.0' + spec.add_development_dependency 'mocha' spec.add_development_dependency 'rake', '~> 13.0' spec.add_development_dependency 'simplecov' spec.add_development_dependency 'webmock' - spec.add_development_dependency 'mocha' -end \ No newline at end of file +end From 5929bc13c22c85c6aa6276e1f4d753336fc5a6b9 Mon Sep 17 00:00:00 2001 From: Sergei Tsoganov Date: Tue, 3 Oct 2023 12:41:59 +0300 Subject: [PATCH 10/10] Updated github workflow --- .github/workflows/ruby.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index a12b36c..fa6a47f 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -58,6 +58,7 @@ jobs: gem install nokogiri -v '~> 1.11.3' gem install savon gem install webmock + gem install mocha gem install minitest -v '~> 5.14' bundle install rake