fix: set Recurring Billing before Pay-to Vendor validation in CreatePurchaseHeaderFromContract#7827
Open
jeffreybulanadi wants to merge 2 commits intomicrosoft:mainfrom
Conversation
…urchaseHeaderFromContract (microsoft#4302) The CreatePurchaseHeaderFromContract procedure was missing PurchaseHeader.Recurring Billing := true before calling Validate(Pay-to Vendor No.). On the sales side, CreateSalesHeaderFromContract already sets Recurring Billing := true before Validate(Sell-to Customer No.), but the equivalent line was absent on the purchase side. Localization extensions such as the Hungarian localization add a validation trigger on Pay-to Vendor No. that checks whether the document is a recurring billing document. Because the flag was not set at that point, the trigger raised You cannot make this change because the document is linked to a contract, blocking all vendor billing document creation when such a localization was installed. Fix: add PurchaseHeader.Recurring Billing := true immediately after SetHideValidationDialog, matching the existing sales-side pattern. Regression test CreateBillingDocumentsForVendorContractSetsRecurring BillingBeforeVendorValidation added to RecurringBillingDocsTest. The test creates a vendor contract with a separate Pay-to Vendor (the exact field validated), creates billing documents, and asserts that the resulting purchase header carries Recurring Billing = true and that Pay-to Vendor No. matches the contract.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes vendor billing document creation for vendor contracts when localization extensions validate "Pay-to Vendor No." differently for recurring billing documents by ensuring the purchase header is marked as recurring billing before vendor field validation runs.
Changes:
- Set
PurchaseHeader."Recurring Billing" := trueimmediately afterSetHideValidationDialog(true)inCreatePurchaseHeaderFromContract, before validating vendor fields. - Add a new test intended to cover the regression scenario for contracts with separate Pay-to Vendor.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/Apps/W1/Subscription Billing/App/Billing/Codeunits/CreateBillingDocuments.Codeunit.al |
Marks the purchase header as recurring billing before "Pay-to Vendor No." validation to avoid localization-triggered validation failures. |
src/Apps/W1/Subscription Billing/Test/Billing/RecurringBillingDocsTest.Codeunit.al |
Adds a regression test for the vendor contract scenario with differing Pay-to vs Buy-from vendor. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…validation Add codeunit 148456 'Rec. Billing Purch. Hdr. Sub.' with SingleInstance=true and EventSubscriberInstance=Manual. The subscriber hooks OnBeforeValidateEvent on Purchase Header.'Pay-to Vendor No.' and errors if 'Recurring Billing' is false. The test binds this subscriber before CreateBillingDocuments and unbinds before assertions. This ensures the test fails without the production fix (line 636 in CreateBillingDocuments.Codeunit.al) and passes with it, verifying field ordering. Expand app.json ID range from 148455..148455 to 148455..148456 to accommodate the new codeunit.
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.
Fixes #4302
Problem
In
CreateBillingDocuments.Codeunit.al,CreatePurchaseHeaderFromContractcallsValidate("Pay-to Vendor No.", ...)before settingPurchaseHeader."Recurring Billing" := true. Localization extensions (such as the Hungarian localization) add a validation trigger on the"Pay-to Vendor No."field that checks whether the document is a recurring billing document. Because the flag wasfalseat that point, the trigger raised:...blocking all vendor billing document creation whenever such a localization was installed.
Root Cause
The sales-side procedure
CreateSalesHeaderFromContractcorrectly sets"Recurring Billing" := truebefore callingValidate("Sell-to Customer No.", ...). The purchase-side procedureCreatePurchaseHeaderFromContractwas missing the equivalent line before its vendor validation calls.Fix
Add
PurchaseHeader."Recurring Billing" := true;immediately afterSetHideValidationDialog(true), mirroring the established pattern on the sales side:Sales side (already correct):
Purchase side (after fix):
Tests
Added
CreateBillingDocumentsForVendorContractSetsRecurringBillingBeforeVendorValidationtoRecurringBillingDocsTest(codeunit 139687). The test:PurchaseHeader."Recurring Billing" = truePurchaseHeader."Pay-to Vendor No."matches the contract