Summary
Secretariat::LineItem#to_xml currently changes tax_percent to 0 when net_amount is zero:
if net_price&.zero?
self.tax_percent = 0
end
This makes zero-value standard-rated invoice lines serialize as 0% VAT even when the supplied tax category/rate is standard VAT, for example 19%.
Why this matters
A fully discounted or zero-consideration line can still be a standard-rated taxable item. In that case the taxable base and tax amount are 0.00, but the VAT category/rate should remain the applicable rate, for example S / 19.00, not 0.00.
Changing the rate to zero conflates standard-rated zero-value lines with zero-rated or non-taxable lines.
Expected behavior
If a caller supplies:
tax_category: :STANDARDRATE
tax_percent: 19
net_amount: 0
tax_amount: 0
the XML should preserve RateApplicablePercent as 19.00.
Actual behavior
LineItem#to_xml mutates tax_percent to 0, so the generated XML contains RateApplicablePercent as 0.00.
Suggested fix
Avoid mutating tax_percent for zero-net lines. If some profiles need zero-rate normalization, make it opt-in or tied to an explicit zero-rated/untaxed tax category rather than inferred from net_amount == 0.
Environment
Observed with secretariat 3.9.0.
Relevant commit: 321657a80a71c08c0fb82b3865622a92e2cd49e1.
Summary
Secretariat::LineItem#to_xmlcurrently changestax_percentto0whennet_amountis zero:This makes zero-value standard-rated invoice lines serialize as
0%VAT even when the supplied tax category/rate is standard VAT, for example19%.Why this matters
A fully discounted or zero-consideration line can still be a standard-rated taxable item. In that case the taxable base and tax amount are
0.00, but the VAT category/rate should remain the applicable rate, for exampleS/19.00, not0.00.Changing the rate to zero conflates standard-rated zero-value lines with zero-rated or non-taxable lines.
Expected behavior
If a caller supplies:
tax_category: :STANDARDRATEtax_percent: 19net_amount: 0tax_amount: 0the XML should preserve
RateApplicablePercentas19.00.Actual behavior
LineItem#to_xmlmutatestax_percentto0, so the generated XML containsRateApplicablePercentas0.00.Suggested fix
Avoid mutating
tax_percentfor zero-net lines. If some profiles need zero-rate normalization, make it opt-in or tied to an explicit zero-rated/untaxed tax category rather than inferred fromnet_amount == 0.Environment
Observed with
secretariat3.9.0.Relevant commit:
321657a80a71c08c0fb82b3865622a92e2cd49e1.