diff --git a/lib/secretariat/invoice.rb b/lib/secretariat/invoice.rb index b388ac2..76052da 100644 --- a/lib/secretariat/invoice.rb +++ b/lib/secretariat/invoice.rb @@ -104,12 +104,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 @@ -147,7 +147,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 diff --git a/lib/secretariat/line_item.rb b/lib/secretariat/line_item.rb index 8158ca3..e456581 100644 --- a/lib/secretariat/line_item.rb +++ b/lib/secretariat/line_item.rb @@ -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