Skip to content

Added InvoicePeriod to ItemLine#845

Merged
stephanstapel merged 3 commits intomasterfrom
invoiceperiod-for-ubl-items
Dec 13, 2025
Merged

Added InvoicePeriod to ItemLine#845
stephanstapel merged 3 commits intomasterfrom
invoiceperiod-for-ubl-items

Conversation

@stephanstapel
Copy link
Owner

closes #841

Summary

added invoiceperiod to line items in ubl

Checklist

  • [ x] Code follows repo Coding Instructions
  • [x ] Public APIs documented (XML)
  • [x ] Unit tests added/updated
  • Analyzers clean (dotnet build no warnings as errors)
  • dotnet format --verify-no-changes passes

Breaking changes?

  • [ x] No
  • Yes (explain impact & migration)

Copilot AI review requested due to automatic review settings December 13, 2025 17:32
Copy link
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 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.

Comment on lines 669 to 673
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));
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

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

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)

Suggested change
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));
}

Copilot uses AI. Check for mistakes.
Comment on lines 669 to 675
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
}
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
@stephanstapel stephanstapel merged commit 4597099 into master Dec 13, 2025
2 checks passed
@stephanstapel stephanstapel deleted the invoiceperiod-for-ubl-items branch December 13, 2025 20:25
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.

Missing InvoicePeriod In ItemLine in UBL22

1 participant