Re-enable BR-CO-19 and BR-CO-20 validation with presence tracking#119
Merged
Re-enable BR-CO-19 and BR-CO-20 validation with presence tracking#119
Conversation
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)
4147810 to
4cff3d2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
Changes
model.go: Added unexported presence tracking fields:
billingPeriodPresenttoInvoicestruct for BG-14 trackinglinePeriodPresenttoInvoiceLinestruct for BG-26 trackingparser_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:
validate_core_test.go: Added comprehensive test cases:
TestBRCO19_InvoicingPeriodRequiresDate: Tests both CII and UBL formatsTestBRCO20_InvoiceLinePeriodRequiresDate: Tests both CII and UBL formatsTest Results
All tests pass, including:
Test Plan