added all EN16931 invoice types to UBL writer#846
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the invoice type classification logic in the UBL writer to support all EN16931 invoice types. The previous implementation only handled three invoice types (Invoice, Correction, and CreditNote) and threw exceptions for all others. The new implementation comprehensively classifies all 13 credit note types defined in the EN16931 standard.
- Replaced hardcoded if-else chain with a dedicated
_IsInvoiceAccordingToEn16931method using a switch statement - Added support for 12 additional credit note types that were previously unsupported
- Changed error handling behavior from throwing NotImplementedException to treating unknown types as invoices
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| private bool _IsInvoiceAccordingToEn16931(InvoiceType type) | ||
| { | ||
| switch (type) | ||
| { | ||
| case InvoiceType.CreditNoteRelatedToGoodsOrServices: | ||
| case InvoiceType.CreditNoteRelatedToFinancialAdjustments: | ||
| case InvoiceType.SelfBilledCreditNote: | ||
| case InvoiceType.ConsolidatedCreditNoteGoodsAndServices: | ||
| case InvoiceType.CreditNoteForPriceVariation: | ||
| case InvoiceType.DelcredereCreditNote: | ||
| case InvoiceType.CreditNote: | ||
| case InvoiceType.FactoredCreditNote: | ||
| case InvoiceType.OcrPaymentCreditNote: | ||
| case InvoiceType.ReversalOfCredit: | ||
| case InvoiceType.SelfBilledFactoredCreditNote: | ||
| case InvoiceType.PrepaymentCreditNoteCorrected: | ||
| case InvoiceType.ForwardersCreditNote: | ||
| return false; | ||
| default: | ||
| return true; | ||
| } | ||
| } // !_IsInvoiceAccordingToEn16931() |
There was a problem hiding this comment.
The _IsInvoiceAccordingToEn16931 method has comprehensive coverage of EN16931 credit note types. However, there's no test coverage for this new functionality. The PR checklist indicates "Unit tests added/updated" is not checked. Consider adding tests that verify:
- All credit note invoice types return false
- All invoice types return true
- Edge cases with new invoice types that may be added in the future are handled correctly by the default case
This is especially important since the old code would throw NotImplementedException for unsupported types, but the new code silently treats them as invoices via the default case, which is a behavioral change.
| default: | ||
| return true; |
There was a problem hiding this comment.
The default case returns true for all invoice types not explicitly listed as credit notes. While this approach works for current EN16931 types, it changes the behavior from the previous implementation which threw NotImplementedException for unrecognized types. Consider adding a comment documenting that:
- All EN16931 invoice types are covered by this method
- The default case assumes new types will be invoices unless explicitly added to the credit note list
This will help future maintainers understand the design decision and remember to update this method when new credit note types are added to the InvoiceType enum.
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
Summary
Added all EN16931 invoice types to UBL writer
Checklist
.Result/GetAwaiter().GetResult())CancellationTokenrespecteddotnet buildno warnings as errors)dotnet format --verify-no-changespassesBreaking changes?