From 50e2bbd80678168668e080003d235506d9d10db9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Phillipp=20R=C3=B6ll?= Date: Tue, 17 Dec 2024 10:41:49 +0100 Subject: [PATCH] Add line item level allowance charge --- lib/xrechnung/allowance_charge.rb | 9 ++++++--- lib/xrechnung/invoice_line.rb | 7 +++++++ spec/fixtures/ruby/invoice_line.rb | 1 + spec/fixtures/scraps/invoice_line.xml | 5 +++++ spec/fixtures/xrechnung.xml | 5 +++++ 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/xrechnung/allowance_charge.rb b/lib/xrechnung/allowance_charge.rb index 8094482..de1b8e1 100644 --- a/lib/xrechnung/allowance_charge.rb +++ b/lib/xrechnung/allowance_charge.rb @@ -24,7 +24,7 @@ class AllowanceCharge # @!attribute base_amount # @return [Xrechnung::Currency] - member :base_amount, type: Xrechnung::Currency + member :base_amount, type: Xrechnung::Currency, optional: true # @!attribute tax_category # @return [Xrechnung::TaxCategory] @@ -35,7 +35,7 @@ def initialize(**kwargs) kwargs[:amount] = Currency::EUR(kwargs[:amount]) end - unless kwargs[:base_amount].is_a?(Currency) + unless kwargs[:base_amount].is_a?(Currency) || kwargs[:base_amount].nil? kwargs[:base_amount] = Currency::EUR(kwargs[:base_amount]) end @@ -60,7 +60,10 @@ def to_xml(xml) end xml.cbc :Amount, *amount.xml_args - xml.cbc :BaseAmount, *base_amount.xml_args + + if base_amount + xml.cbc :BaseAmount, *base_amount.xml_args + end tax_category&.to_xml(xml) end diff --git a/lib/xrechnung/invoice_line.rb b/lib/xrechnung/invoice_line.rb index ea62296..9833690 100644 --- a/lib/xrechnung/invoice_line.rb +++ b/lib/xrechnung/invoice_line.rb @@ -28,6 +28,10 @@ class InvoiceLine # @return [Xrechnung::Price] member :price, type: Xrechnung::Price + # @!attribute allowance_charges + # @return [Array] + member :allowance_charges, type: Array, default: [] + def initialize(**kwargs) unless kwargs[:line_extension_amount].is_a?(Currency) kwargs[:line_extension_amount] = Currency::EUR(kwargs[:line_extension_amount]) @@ -43,6 +47,9 @@ def to_xml(xml) xml.cbc :LineExtensionAmount, *line_extension_amount.xml_args invoice_period&.to_xml(xml) unless self.class.members[:invoice_period].optional && invoice_period.nil? + allowance_charges.each do |allowance_charge| + allowance_charge.to_xml(xml) + end item&.to_xml(xml) price&.to_xml(xml) end diff --git a/spec/fixtures/ruby/invoice_line.rb b/spec/fixtures/ruby/invoice_line.rb index fd9a8f3..b3bc34f 100644 --- a/spec/fixtures/ruby/invoice_line.rb +++ b/spec/fixtures/ruby/invoice_line.rb @@ -8,5 +8,6 @@ def build_invoice_line line_extension_amount: 1294.30, item: build_item, price: build_price, + allowance_charges: [build_allowance_charge], ) end diff --git a/spec/fixtures/scraps/invoice_line.xml b/spec/fixtures/scraps/invoice_line.xml index 93f41f4..eb8d70b 100644 --- a/spec/fixtures/scraps/invoice_line.xml +++ b/spec/fixtures/scraps/invoice_line.xml @@ -2,6 +2,11 @@ 0 1.00 1294.30 + + false + 1.00 + 1295.30 + Leimbinder 2x18m; Birke Leimbinder diff --git a/spec/fixtures/xrechnung.xml b/spec/fixtures/xrechnung.xml index 305782f..9eb5ad8 100644 --- a/spec/fixtures/xrechnung.xml +++ b/spec/fixtures/xrechnung.xml @@ -159,6 +159,11 @@ 0 1.00 1294.30 + + false + 1.00 + 1295.30 + Leimbinder 2x18m; Birke Leimbinder