Skip to content

Ksef bypass#55

Draft
mrdanwa wants to merge 3 commits into
mainfrom
ksef-bypass
Draft

Ksef bypass#55
mrdanwa wants to merge 3 commits into
mainfrom
ksef-bypass

Conversation

@mrdanwa
Copy link
Copy Markdown
Contributor

@mrdanwa mrdanwa commented Apr 13, 2026

No description provided.

@mrdanwa mrdanwa force-pushed the ksef-bypass branch 2 times, most recently from 4ff73eb to 4b701c7 Compare April 22, 2026 20:11
@mrdanwa mrdanwa marked this pull request as ready for review April 27, 2026 08:27
@mrdanwa mrdanwa marked this pull request as draft April 28, 2026 16:58
@mrdanwa
Copy link
Copy Markdown
Contributor Author

mrdanwa commented Apr 28, 2026

Check gross-price, settlement-invoice-1, settlement-invoice-1

@mrdanwa mrdanwa marked this pull request as ready for review May 1, 2026 16:20
Copilot AI review requested due to automatic review settings May 1, 2026 16:20
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a “bypass” conversion mode for KSeF → GOBL parsing, where totals are taken directly from KSeF invoice-level fields instead of relying on Calculate()/rounding adjustments, and updates the golden test fixtures accordingly.

Changes:

  • Always tag parsed invoices with tax.TagBypass and set totals from KSeF invoice-level tax summary fields (P_13_x, P_14_x, P_15).
  • Set line Sum/Total directly from KSeF line totals (P_11 / P_11A) where present, and stop deriving settlement advances/rounding adjustments.
  • Update/extend KSeF fixture inputs and expected GOBL outputs; relax round-trip validation for bypass-tagged invoices; remove legacy rounding tests/helpers.

Reviewed changes

Copilot reviewed 12 out of 43 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
test/data/ksef.gobl/out/settlement-invoice-2.json Golden output updated to include bypass tag and new totals formatting/values.
test/data/ksef.gobl/out/settlement-invoice-1.json Golden output updated to include bypass tag and revised settlement totals.
test/data/ksef.gobl/out/prepayment.json Golden output updated (due date amount now populated).
test/data/ksef.gobl/out/no-unit-price.json Golden output updated to include bypass tag and numeric formatting changes.
test/data/ksef.gobl/out/long-invoice.json Golden output updated to include bypass tag and revised totals/tax category mapping.
test/data/ksef.gobl/out/invoice-with-spaces.json Golden output updated to include bypass tag.
test/data/ksef.gobl/out/invoice-standard.json Golden output updated to include bypass tag.
test/data/ksef.gobl/out/invoice-simplified.json Golden output updated to include bypass tag.
test/data/ksef.gobl/out/invoice-settlement.json Golden output updated to include bypass tag and changed payable/due fields.
test/data/ksef.gobl/out/invoice-self-billed.json Golden output updated to include bypass tag.
test/data/ksef.gobl/out/invoice-reverse-charge.json Golden output updated to include bypass tag and numeric formatting changes.
test/data/ksef.gobl/out/invoice-prepayment.json Golden output updated to include bypass tag and changed payable/due fields.
test/data/ksef.gobl/out/invoice-payment-card.json Golden output updated to include bypass tag.
test/data/ksef.gobl/out/invoice-jst-customer.json Golden output updated to include bypass tag.
test/data/ksef.gobl/out/invoice-group-vat.json Golden output updated to include bypass tag.
test/data/ksef.gobl/out/invoice-foreign-currency.json Golden output updated to include bypass tag.
test/data/ksef.gobl/out/invoice-exempt.json Golden output updated to include bypass tag and numeric formatting changes.
test/data/ksef.gobl/out/gross-price.json Golden output updated for gross-pricing fixture under bypass totals handling.
test/data/ksef.gobl/out/discount-invoice4.json New golden output fixture for discount scenario (bypass-tagged).
test/data/ksef.gobl/out/discount-invoice3.json New golden output fixture for discount scenario (bypass-tagged).
test/data/ksef.gobl/out/discount-invoice2.json New golden output fixture for discount scenario (bypass-tagged).
test/data/ksef.gobl/out/discount-invoice.json Golden output updated to include bypass tag and revised totals/taxes.
test/data/ksef.gobl/out/credit-note-wrong-sign.json New golden output fixture for credit note sign edge case (bypass-tagged).
test/data/ksef.gobl/out/credit-note-standard.json Golden output updated to include bypass tag.
test/data/ksef.gobl/out/credit-note-settlement.json Golden output updated to include bypass tag.
test/data/ksef.gobl/out/credit-note-prepayment.json Golden output updated to include bypass tag.
test/data/ksef.gobl/out/credit-note-payed.json Golden output updated to include bypass tag and revised line/totals values.
test/data/ksef.gobl/out/credit-note-no-lines.json Golden output updated: totals now present (zeroed) instead of null, plus bypass tag.
test/data/ksef.gobl/out/credit-note-no-line.json Golden output updated: totals now present (zeroed) instead of null, plus bypass tag.
test/data/ksef.gobl/out/credit-note-before-after.json Golden output updated to include bypass tag.
test/data/ksef.gobl/discount-invoice4.xml New KSeF XML input fixture for discount scenario.
test/data/ksef.gobl/discount-invoice3.xml New KSeF XML input fixture for discount scenario.
test/data/ksef.gobl/discount-invoice2.xml New KSeF XML input fixture for discount scenario.
test/data/ksef.gobl/credit-note-wrong-sign.xml New KSeF XML input fixture for credit note sign edge case.
test/convert_test.go Round-trip validation relaxed for bypass-tagged invoices.
rounding_test.go Removed legacy rounding adjustment tests.
rounding.go Removed legacy rounding adjustment implementation.
payments.go Removed settlement-advance derivation helper.
lines.go Populate Line.Sum/Line.Total directly from KSeF line totals.
ksef.go Always set totals from KSeF invoice-level fields via parseTotals.
invoice_test.go Updated expectations: bypass is now set broadly; removed settlement-advance derivation tests.
invoice.go Always apply bypass mode in parseLines; implement invoice-level parseTotals and due-date amount fill.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/convert_test.go
Comment thread invoice.go
Comment on lines +687 to 693
// parseTotals builds bill.Totals directly from the invoice-level
// tax summary fields (P_13_X / P_14_X / P_15). The invoice must have the
// bypass tag set so that Calculate() does not overwrite these totals.
// The resulting invoice will not pass GOBL validation (no lines), which
// is acceptable for this edge case.
func (inv *Inv) parsePrepaymentTotals(goblInv *bill.Invoice) error {
func (inv *Inv) parseTotals(goblInv *bill.Invoice) error {
// Each entry maps a P_13_X / P_14_X pair to a tax category.
// Well-known percentages are set when the rate is unambiguous;
// otherwise only the amounts are included.
Comment thread invoice.go
Comment on lines +687 to 693
// parseTotals builds bill.Totals directly from the invoice-level
// tax summary fields (P_13_X / P_14_X / P_15). The invoice must have the
// bypass tag set so that Calculate() does not overwrite these totals.
// The resulting invoice will not pass GOBL validation (no lines), which
// is acceptable for this edge case.
func (inv *Inv) parsePrepaymentTotals(goblInv *bill.Invoice) error {
func (inv *Inv) parseTotals(goblInv *bill.Invoice) error {
// Each entry maps a P_13_X / P_14_X pair to a tax category.
// Well-known percentages are set when the rate is unambiguous;
// otherwise only the amounts are included.
Comment thread invoice.go
Comment on lines 650 to +660
})
} else {
line.Quantity = line.Quantity.Invert()
if line.Sum != nil {
s := line.Sum.Invert()
line.Sum = &s
}
if line.Total != nil {
t := line.Total.Invert()
line.Total = &t
}
@mrdanwa mrdanwa marked this pull request as draft May 1, 2026 17:12
# Conflicts:
#	invoice_test.go
#	rounding_test.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants