Skip to content

fix: set Recurring Billing before Pay-to Vendor validation in CreatePurchaseHeaderFromContract#7827

Open
jeffreybulanadi wants to merge 2 commits intomicrosoft:mainfrom
jeffreybulanadi:fix/4302-recurring-billing-purchase-header
Open

fix: set Recurring Billing before Pay-to Vendor validation in CreatePurchaseHeaderFromContract#7827
jeffreybulanadi wants to merge 2 commits intomicrosoft:mainfrom
jeffreybulanadi:fix/4302-recurring-billing-purchase-header

Conversation

@jeffreybulanadi
Copy link
Copy Markdown

@jeffreybulanadi jeffreybulanadi commented Apr 23, 2026

Fixes #4302

Problem

In CreateBillingDocuments.Codeunit.al, CreatePurchaseHeaderFromContract calls Validate("Pay-to Vendor No.", ...) before setting PurchaseHeader."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 was false 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 whenever such a localization was installed.

Root Cause

The sales-side procedure CreateSalesHeaderFromContract correctly sets "Recurring Billing" := true before calling Validate("Sell-to Customer No.", ...). The purchase-side procedure CreatePurchaseHeaderFromContract was missing the equivalent line before its vendor validation calls.

Fix

Add PurchaseHeader."Recurring Billing" := true; immediately after SetHideValidationDialog(true), mirroring the established pattern on the sales side:

Sales side (already correct):

SalesHeader.SetHideValidationDialog(true);
SalesHeader."Recurring Billing" := true;
SalesHeader.Validate("Sell-to Customer No.", ...);

Purchase side (after fix):

PurchaseHeader.SetHideValidationDialog(true);
PurchaseHeader."Recurring Billing" := true;
PurchaseHeader.Validate("Pay-to Vendor No.", ...);

Tests

Added CreateBillingDocumentsForVendorContractSetsRecurringBillingBeforeVendorValidation to RecurringBillingDocsTest (codeunit 139687). The test:

  1. Creates a vendor contract with a separate Pay-to Vendor (the exact field whose validation triggers the error)
  2. Creates a billing proposal and billing documents from that contract
  3. Asserts PurchaseHeader."Recurring Billing" = true
  4. Asserts PurchaseHeader."Pay-to Vendor No." matches the contract

…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.
Copilot AI review requested due to automatic review settings April 23, 2026 03:35
@jeffreybulanadi jeffreybulanadi requested a review from a team as a code owner April 23, 2026 03:35
@github-actions github-actions Bot added AL: Apps (W1) Add-on apps for W1 From Fork Pull request is coming from a fork labels Apr 23, 2026
Copy link
Copy Markdown
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

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" := true immediately after SetHideValidationDialog(true) in CreatePurchaseHeaderFromContract, 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.
@jeffreybulanadi jeffreybulanadi requested a review from a team as a code owner April 23, 2026 03:47
@JesperSchulz JesperSchulz added the Finance GitHub request for Finance area label Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AL: Apps (W1) Add-on apps for W1 Finance GitHub request for Finance area From Fork Pull request is coming from a fork

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Subscription & Recurring Billing - Validation Problem

3 participants