Skip to content

Require key or code in notes for Poland#795

Open
mrdanwa wants to merge 1 commit intomainfrom
plnotes
Open

Require key or code in notes for Poland#795
mrdanwa wants to merge 1 commit intomainfrom
plnotes

Conversation

@mrdanwa
Copy link
Copy Markdown

@mrdanwa mrdanwa commented Apr 9, 2026

Require key or code in notes for Poland to avoid issues in KSeF

Pre-Review Checklist

  • Opened this PR as a draft
  • Read the CONTRIBUTING.md guide.
  • Performed a self-review of my code.
  • Added thorough tests with at least 90% code coverage.
  • Modified or created example GOBL documents to show my changes in use, if appropriate.
  • Added links to the source of the changes in tax regimes or addons, either structured or in the comments.
  • Run go generate . to ensure that the Schemas and Regime data are up to date.
  • Reviewed and fixed all linter warnings.
  • Been obsessive with pointer nil checks to avoid panics.
  • Updated the CHANGELOG.md with an overview of my changes.
  • Marked this PR as ready for review.

And if you are part of the org:

  • Requested a review from Copilot and fixed or dismissed (with a reason) all the feedback raised.
  • Requested a review from @samlown.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.08%. Comparing base (70940f8) to head (b79a343).

Additional details and impacted files
@@           Coverage Diff           @@
##            rules     #795   +/-   ##
=======================================
  Coverage   93.08%   93.08%           
=======================================
  Files         368      368           
  Lines       19592    19604   +12     
=======================================
+ Hits        18237    18249   +12     
  Misses        919      919           
  Partials      436      436           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mrdanwa mrdanwa requested a review from pmenendz April 9, 2026 14:15
Copy link
Copy Markdown
Contributor

@pmenendz pmenendz left a comment

Choose a reason for hiding this comment

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

Looks good, but you need to get that test coverage up

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 tightens validation for the Polish FA_VAT (KSeF) addon by requiring invoice notes to include an identifying key or code, preventing submission issues caused by “anonymous” notes.

Changes:

  • Added per-note validation on bill.Invoice.Notes to require key or code.
  • Introduced a helper validator (noteHasKeyOrCode) used by the invoice rules.
  • Added tests covering valid “code-only” notes and invalid notes missing both key and code.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
addons/pl/favat/bill.go Adds invoice-level notes validation and a helper predicate for enforcing key/code presence.
addons/pl/favat/bill_test.go Adds test cases verifying the new notes validation behavior.

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

Comment on lines +163 to +169
func noteHasKeyOrCode(val any) bool {
n, ok := val.(*org.Note)
if !ok || n == nil {
return true
}
return n.Key != "" || n.Code != ""
}
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

noteHasKeyOrCode currently returns true for a nil *org.Note. That means an invoice unmarshaled with notes: [null] would pass this new per-note check, but will still panic during validation because invoiceExemptionNotePresent / invoiceSingleExemptionNote call isExemptionNote(note) without a nil-guard (dereferencing note.Key). Consider treating nil note elements as invalid here (return false when n == nil) and/or adding nil-checks where notes are iterated so validation never panics on null notes.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Agreed.

Comment on lines +696 to +719
t.Run("note with only code is valid", func(t *testing.T) {
inv := standardInvoice()
inv.Notes = []*org.Note{
{
Code: "ABC",
Text: "Note with code only",
},
}
require.NoError(t, inv.Calculate())
err := rules.Validate(inv)
assert.NoError(t, err)
})

t.Run("note without key or code is invalid", func(t *testing.T) {
inv := standardInvoice()
inv.Notes = []*org.Note{
{
Text: "Note without key or code",
},
}
require.NoError(t, inv.Calculate())
err := rules.Validate(inv)
assert.ErrorContains(t, err, "note key or code must be set")
})
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

Add a regression test for notes containing a nil element (e.g. inv.Notes = []*org.Note{nil} or unmarshaled notes:[null]) to ensure rules.Validate(inv) does not panic and instead returns a validation error. This guards against nil-pointer panics in note-related validators.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Agreed.

@mrdanwa
Copy link
Copy Markdown
Author

mrdanwa commented Apr 9, 2026

Looks good, but you need to get that test coverage up

Thanks, all covered now!

Base automatically changed from rules to main April 13, 2026 16:27
Copy link
Copy Markdown
Collaborator

@samlown samlown left a comment

Choose a reason for hiding this comment

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

A few changes required.

func noteHasKeyOrCode(val any) bool {
n, ok := val.(*org.Note)
if !ok || n == nil {
return true
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This should return false. If the method doesn't know what its dealing with, it should assume false by default.

Comment on lines +696 to +719
t.Run("note with only code is valid", func(t *testing.T) {
inv := standardInvoice()
inv.Notes = []*org.Note{
{
Code: "ABC",
Text: "Note with code only",
},
}
require.NoError(t, inv.Calculate())
err := rules.Validate(inv)
assert.NoError(t, err)
})

t.Run("note without key or code is invalid", func(t *testing.T) {
inv := standardInvoice()
inv.Notes = []*org.Note{
{
Text: "Note without key or code",
},
}
require.NoError(t, inv.Calculate())
err := rules.Validate(inv)
assert.ErrorContains(t, err, "note key or code must be set")
})
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Agreed.

Comment on lines +163 to +169
func noteHasKeyOrCode(val any) bool {
n, ok := val.(*org.Note)
if !ok || n == nil {
return true
}
return n.Key != "" || n.Code != ""
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Agreed.

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.

4 participants