Skip to content

Commit

Permalink
Merge pull request #4 from pludoni/optionalValidation
Browse files Browse the repository at this point in the history
Feat: make validation optional to allow other VAT calculations
  • Loading branch information
halfbyte authored Nov 27, 2024
2 parents 9accafe + 74b3749 commit fe0c1c6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/secretariat/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ def namespaces(version: 1)
)
end

def to_xml(version: 1)
def to_xml(version: 1, validate: true)
if version < 1 || version > 2
raise 'Unsupported Document Version'
end

unless valid?
if validate && !valid?
raise ValidationError.new("Invoice is invalid", errors)
end

Expand Down Expand Up @@ -167,7 +167,7 @@ def to_xml(version: 1)

if version == 2
line_items.each_with_index do |item, i|
item.to_xml(xml, i + 1, version: version) # one indexed
item.to_xml(xml, i + 1, version: version, validate: validate) # one indexed
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/secretariat/line_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def tax_category_code(version: 2)
TAX_CATEGORY_CODES[tax_category] || 'S'
end

def to_xml(xml, line_item_index, version: 2)
if !valid?
def to_xml(xml, line_item_index, version: 2, validate: true)
if validate && !valid?
pp errors
raise ValidationError.new("LineItem #{line_item_index} is invalid", errors)
end
Expand Down

0 comments on commit fe0c1c6

Please sign in to comment.