Skip to content

Make the document type configurable, add the preceding invoice reference, allow BT-30 without a scheme - #63

Open
ahmedm10 wants to merge 1 commit into
halfbyte:mainfrom
konvenit:MP-53292-credit-notes-upstream
Open

ahmedm10 wants to merge 1 commit into
halfbyte:mainfrom
konvenit:MP-53292-credit-notes-upstream

Conversation

@ahmedm10

@ahmedm10 ahmedm10 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The document type code (BT-3) is hardcoded to 380 (commercial invoice), marked # TODO: make configurable. Credit notes (381) and corrected invoices (384) can therefore not be written; a cancellation goes out as an invoice with negative amounts, which recipients' software books the wrong way.

A credit note or correction should also refer to the invoice it relates to (BG-3, preceding invoice reference: BT-25 number, BT-26 issue date). There is no way to write that today.

Finally, SpecifiedLegalOrganization/ID (BT-30) always carries a schemeID, defaulting to 0002 (French SIRENE). The scheme is optional in EN 16931 (BT-30-1), and an identifier without a registered scheme — for example a German commercial register entry such as HRB München 123456 — would be mislabelled as a SIRENE number.

Change

  • Invoice#type_code (BT-3): written as given, 380 when not set.
  • Invoice#preceding_invoice_id (BT-25) and #preceding_invoice_issue_date (BT-26, optional): written as InvoiceReferencedDocument after the monetary summation, where the CII schema places it. Version 2 only, like attachments.
  • TradeParty#legal_organization: { id: '...', scheme_id: nil } writes the ID without schemeID. Without the key, 0002 is still the default.

Existing callers get the same XML as before. The one behaviour change: a caller that passes scheme_id: nil explicitly used to get 0002 and now gets no scheme.

Tests

Six new tests in test/invoice_test.rb: the type code defaults to 380; a 381 credit note with the preceding invoice and its date, also validated against the schematron (based on make_eu_invoice, because make_de_invoice does not pass the version 2 schematron on its own); the preceding invoice without a date; no preceding invoice by default; BT-30 without a scheme; BT-30 still defaults to 0002. The full suite passes.

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