Skip to content

Commit

Permalink
TaxCategory: added exempt attributes.
Browse files Browse the repository at this point in the history
  • Loading branch information
stas authored and corny committed Jun 26, 2024
1 parent d56bf5f commit f768860
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
13 changes: 13 additions & 0 deletions lib/xrechnung/tax_category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ class TaxCategory
# @return [String]
member :tax_scheme_id, type: String, default: "VAT"

# @!attribute tax_exemption_reason_code
# @return [String]
member :tax_exemption_reason_code, type: String

# @!attribute tax_exemption_reason
# @return [String]
member :tax_exemption_reason, type: String

# noinspection RubyResolve
def to_xml(xml, root_tag_name: :TaxCategory)
xml.cac root_tag_name do
Expand All @@ -37,6 +45,11 @@ def to_xml(xml, root_tag_name: :TaxCategory)
xml.cac :TaxScheme do
xml.cbc :ID, tax_scheme_id
end

unless tax_exemption_reason_code.nil?
xml.cbc :TaxExemptionReasonCode, tax_exemption_reason_code
xml.cbc :TaxExemptionReason, tax_exemption_reason
end
end
end
end
Expand Down
11 changes: 9 additions & 2 deletions spec/fixtures/ruby/tax_category.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
def build_tax_category
Xrechnung::TaxCategory.new(
def build_tax_category(exempt: false)
category = Xrechnung::TaxCategory.new(
id: "S",
percent: 16,
tax_scheme_id: "VAT",
)

return category unless exempt

category.tax_exemption_reason_code = "VATEX-EU-S"
category.tax_exemption_reason = "Exempt"

category
end
2 changes: 2 additions & 0 deletions spec/fixtures/scraps/tax_category.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
<cac:TaxScheme>
<cbc:ID>VAT</cbc:ID>
</cac:TaxScheme>
<cbc:TaxExemptionReasonCode>VATEX-EU-S</cbc:TaxExemptionReasonCode>
<cbc:TaxExemptionReason>Exempt</cbc:TaxExemptionReason>
</cac:TaxCategory>
2 changes: 1 addition & 1 deletion spec/xrechnung/tax_category_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

RSpec.describe Xrechnung::TaxCategory do
it "generates xml" do
expect_xml_eq_fixture(build_tax_category, "tax_category")
expect_xml_eq_fixture(build_tax_category(exempt: true), "tax_category")
end
end

0 comments on commit f768860

Please sign in to comment.