Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for writing InvoicePeriod (billing period dates) to line items when exporting invoices in UBL format, addressing issue #841.
Key Changes
- Added InvoicePeriod element to line items in UBL output, including StartDate and EndDate child elements based on the TradeLineItem's BillingPeriodStart and BillingPeriodEnd properties
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (tradeLineItem.BillingPeriodStart.HasValue && tradeLineItem.BillingPeriodEnd.HasValue) | ||
| { | ||
| _Writer.WriteStartElement("cac", "InvoicePeriod"); | ||
| _Writer.WriteElementString("cbc", "StartDate", _formatDate(tradeLineItem.BillingPeriodStart.Value, false, true)); | ||
| _Writer.WriteElementString("cbc", "EndDate", _formatDate(tradeLineItem.BillingPeriodEnd.Value, false, true)); |
There was a problem hiding this comment.
The condition on this line requires both BillingPeriodStart AND BillingPeriodEnd to be present. However, the document-level InvoicePeriod logic at line 158 uses OR logic (allowing either date), and other format writers like InvoiceDescriptor20Writer.cs also use OR logic. This inconsistency means line items with only a start date or only an end date won't have their InvoicePeriod written in UBL format. Consider changing this to match the pattern: if (tradeLineItem.BillingPeriodStart.HasValue || tradeLineItem.BillingPeriodEnd.HasValue)
| if (tradeLineItem.BillingPeriodStart.HasValue && tradeLineItem.BillingPeriodEnd.HasValue) | |
| { | |
| _Writer.WriteStartElement("cac", "InvoicePeriod"); | |
| _Writer.WriteElementString("cbc", "StartDate", _formatDate(tradeLineItem.BillingPeriodStart.Value, false, true)); | |
| _Writer.WriteElementString("cbc", "EndDate", _formatDate(tradeLineItem.BillingPeriodEnd.Value, false, true)); | |
| if (tradeLineItem.BillingPeriodStart.HasValue || tradeLineItem.BillingPeriodEnd.HasValue) | |
| { | |
| _Writer.WriteStartElement("cac", "InvoicePeriod"); | |
| if (tradeLineItem.BillingPeriodStart.HasValue) | |
| { | |
| _Writer.WriteElementString("cbc", "StartDate", _formatDate(tradeLineItem.BillingPeriodStart.Value, false, true)); | |
| } | |
| if (tradeLineItem.BillingPeriodEnd.HasValue) | |
| { | |
| _Writer.WriteElementString("cbc", "EndDate", _formatDate(tradeLineItem.BillingPeriodEnd.Value, false, true)); | |
| } |
| if (tradeLineItem.BillingPeriodStart.HasValue && tradeLineItem.BillingPeriodEnd.HasValue) | ||
| { | ||
| _Writer.WriteStartElement("cac", "InvoicePeriod"); | ||
| _Writer.WriteElementString("cbc", "StartDate", _formatDate(tradeLineItem.BillingPeriodStart.Value, false, true)); | ||
| _Writer.WriteElementString("cbc", "EndDate", _formatDate(tradeLineItem.BillingPeriodEnd.Value, false, true)); | ||
| _Writer.WriteEndElement(); // !InvoicePeriod | ||
| } |
There was a problem hiding this comment.
There is no test coverage for the newly added line-level InvoicePeriod functionality in UBL format. While the reader already supports reading InvoicePeriod from line items (InvoiceDescriptor22UblReader.cs lines 545-546), there are no tests verifying that the writer correctly outputs this data. Consider adding a test in XRechnungUBLTests.cs that creates a line item with BillingPeriodStart and BillingPeriodEnd, saves it to UBL format, loads it back, and verifies the dates are preserved.
closes #841
Summary
added invoiceperiod to line items in ubl
Checklist
dotnet buildno warnings as errors)dotnet format --verify-no-changespassesBreaking changes?