Skip to content

Make pay.DueDate amount optional - #951

Draft
migueltorresvalls wants to merge 1 commit into
mainfrom
relax-due-dates-validation
Draft

Make pay.DueDate amount optional#951
migueltorresvalls wants to merge 1 commit into
mainfrom
relax-due-dates-validation

Conversation

@migueltorresvalls

@migueltorresvalls migueltorresvalls commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Relax GOBL-PAY-DUEDATE-02 so a due date without an amount is valid.

Use case: when parsing CII documents into GOBL, ram:PartialPaymentAmount and ram:PartialPaymentPercent are optional fields that gobl.cii treats as parse-only — they are not part of the EN16931 / Factur-X / ZUGFeRD schemas, so they're read when present but never emitted. A payment term carrying only a ram:DueDateDateTime is therefore a perfectly valid source document, yet the converted GOBL invoice failed validation: DueDate.Amount was a non-pointer num.Amount, so the missing amount materialized as zero, CalculateDues rescaled it to 0.00, and GOBL-PAY-DUEDATE-02 ("amount must not be zero") rejected the whole document. The fix stops inventing a zero amount for due dates that never declared one, instead of loosening the check on amounts that are actually set.

How gobl.ubl handles the same situation: instead of leaving the amount unset, it assumes a single due date covers the full amount (payment_parse.go), which CalculateDues then turns into the payable total:

// If there's only one due date, set its percent to 100
if payment.Terms != nil && len(payment.Terms.DueDates) == 1 {
    percent, err := num.PercentageFromString("100%")
    if err != nil {
        return err
    }
    payment.Terms.DueDates[0].Percent = &percent
}

invopop/gobl.cii#88 (draft) ports that same behavior to gobl.cii.

Changes:

  • pay: DueDate.Amount is now *num.Amount with omitempty, matching the other optional amounts; an absent amount stays absent
  • pay: CalculateDues leaves due dates without an amount or percent untouched; percent-derived amounts are still calculated and rescaled
  • GOBL-PAY-DUEDATE-02 now only fires for an explicitly set zero amount (num.NotZero already skips nil)
  • Regenerated data/schemas/pay/terms.json: amount no longer required on pay.DueDate

Notes:

  • Up for discussion how we handle this: it's not clear we should always be assuming 100% at parse time (the source document doesn't state it), nor whether GOBL should accept amount-less due dates instead — or both, since the 100% assumption only covers the single-due-date case and multiple due dates without amounts would still need this relaxation.
  • gobl.cii assigns dd.Amount from a parsed value; it needs a one-line pointer change when bumping to a gobl version including this.

Generated with Claude Code — https://claude.ai/code/ecc6fcbb-f34f-4ab9-bc09-90ec8cc9c4ae

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@codecov

codecov Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.99%. Comparing base (9cbe45b) to head (e5af1b1).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #951      +/-   ##
==========================================
- Coverage   95.02%   94.99%   -0.03%     
==========================================
  Files         327      321       -6     
  Lines       17773    17338     -435     
==========================================
- Hits        16888    16471     -417     
+ Misses        546      539       -7     
+ Partials      339      328      -11     

☔ View full report in Codecov by Harness.
📢 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.

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.

1 participant