Skip to content

Re-enable BR-CO-19 and BR-CO-20 validation with presence tracking#119

Merged
fank merged 1 commit intomainfrom
fix/issue-44-br-co-19-20-validation
Oct 14, 2025
Merged

Re-enable BR-CO-19 and BR-CO-20 validation with presence tracking#119
fank merged 1 commit intomainfrom
fix/issue-44-br-co-19-20-validation

Conversation

@fank
Copy link
Copy Markdown
Collaborator

@fank fank commented Oct 14, 2025

Summary

Fixes #44

This PR re-enables BR-CO-19 and BR-CO-20 validation checks that were disabled in PR #43. The solution implements presence tracking to distinguish between:

  • XML elements that are present but empty (validation violation)
  • XML elements that are not present at all (no violation)
  • Programmatically built invoices (no validation, writer ensures correctness)

Changes

  • model.go: Added unexported presence tracking fields:

    • billingPeriodPresent to Invoice struct for BG-14 tracking
    • linePeriodPresent to InvoiceLine struct for BG-26 tracking
  • parser_cii.go & parser_ubl.go: Updated both parsers to set presence flags when XML elements exist using XPath count expressions

  • validate_core.go: Re-enabled validation logic:

    • BR-CO-19: If BG-14 (INVOICING PERIOD) is present in XML, at least one date (BT-73 or BT-74) must be filled
    • BR-CO-20: If BG-26 (INVOICE LINE PERIOD) is present in XML, at least one date (BT-134 or BT-135) must be filled
  • validate_core_test.go: Added comprehensive test cases:

    • TestBRCO19_InvoicingPeriodRequiresDate: Tests both CII and UBL formats
    • TestBRCO20_InvoiceLinePeriodRequiresDate: Tests both CII and UBL formats

Test Results

All tests pass, including:

  • New BR-CO-19 and BR-CO-20 validation tests
  • Full existing test suite (no regressions)

Test Plan

  • Run specific BR-CO-19 and BR-CO-20 tests
  • Run full test suite to verify no regressions
  • Tests cover both CII and UBL formats
  • Tests verify violation detection when periods are present but empty

Fixes #44

This commit implements presence tracking for BG-14 (INVOICING PERIOD) and
BG-26 (INVOICE LINE PERIOD) to properly validate BR-CO-19 and BR-CO-20.

Changes:
- Add unexported presence tracking fields (billingPeriodPresent, linePeriodPresent)
  to Invoice and InvoiceLine structs
- Update both CII and UBL parsers to set presence flags when XML elements exist
- Re-enable BR-CO-19: validates that if BG-14 is present, at least one date
  (BT-73 or BT-74) must be filled
- Re-enable BR-CO-20: validates that if BG-26 is present, at least one date
  (BT-134 or BT-135) must be filled
- Add comprehensive test cases for both validation rules

The solution distinguishes three scenarios:
1. Parsing XML with element present but empty → validation violation
2. Parsing XML with element not present → no violation
3. Programmatic invoice building → no validation (writer ensures correctness)
@fank fank force-pushed the fix/issue-44-br-co-19-20-validation branch from 4147810 to 4cff3d2 Compare October 14, 2025 05:18
@fank fank merged commit a33f761 into main Oct 14, 2025
9 checks passed
@fank fank deleted the fix/issue-44-br-co-19-20-validation branch October 14, 2025 05:57
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.

Re-enable BR-CO-19 and BR-CO-20 validation with proper implementation

1 participant