Skip to content

Commit

Permalink
Add line item level allowance charge
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipp committed Dec 17, 2024
1 parent c4467a0 commit 50e2bbd
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/xrechnung/allowance_charge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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

Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions lib/xrechnung/invoice_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class InvoiceLine
# @return [Xrechnung::Price]
member :price, type: Xrechnung::Price

# @!attribute allowance_charges
# @return [Array<Xrechnung::AllowanceCharge>]
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])
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/ruby/invoice_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions spec/fixtures/scraps/invoice_line.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<cbc:ID>0</cbc:ID>
<cbc:InvoicedQuantity unitCode="XPP">1.00</cbc:InvoicedQuantity>
<cbc:LineExtensionAmount currencyID="EUR">1294.30</cbc:LineExtensionAmount>
<cac:AllowanceCharge>
<cbc:ChargeIndicator>false</cbc:ChargeIndicator>
<cbc:Amount currencyID="EUR">1.00</cbc:Amount>
<cbc:BaseAmount currencyID="EUR">1295.30</cbc:BaseAmount>
</cac:AllowanceCharge>
<cac:Item>
<cbc:Description>Leimbinder 2x18m; Birke</cbc:Description>
<cbc:Name>Leimbinder</cbc:Name>
Expand Down
5 changes: 5 additions & 0 deletions spec/fixtures/xrechnung.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@
<cbc:ID>0</cbc:ID>
<cbc:InvoicedQuantity unitCode="XPP">1.00</cbc:InvoicedQuantity>
<cbc:LineExtensionAmount currencyID="EUR">1294.30</cbc:LineExtensionAmount>
<cac:AllowanceCharge>
<cbc:ChargeIndicator>false</cbc:ChargeIndicator>
<cbc:Amount currencyID="EUR">1.00</cbc:Amount>
<cbc:BaseAmount currencyID="EUR">1295.30</cbc:BaseAmount>
</cac:AllowanceCharge>
<cac:Item>
<cbc:Description>Leimbinder 2x18m; Birke</cbc:Description>
<cbc:Name>Leimbinder</cbc:Name>
Expand Down

0 comments on commit 50e2bbd

Please sign in to comment.