Subscription Billing: respect Default Dimension Priorities on Subscription Lines#8115
Subscription Billing: respect Default Dimension Priorities on Subscription Lines#8115Franco111000 wants to merge 3 commits into
Conversation
…ption Lines Fixes microsoft#8084. SubscriptionLine.SetDefaultDimensions becomes the single priority-aware entry point: passes SourceCodeSetup.Sales / .Purchases so Default Dimension Priority is consulted, adds Customer / Vendor as a dim source from the linked contract, and inherits the contract dim set via GetRecDefaultDimID. Mirrors the standard SalesLine.CreateDim pattern in Base App. UpdateFromCustomerContract / UpdateFromVendorContract and the other Pathway B call sites now route through SetDefaultDimensions instead of blind-merging the contract dim set as slot 2. The billing-time merge at CreateBillingDocuments.Codeunit.al lines 264 / 383 is intentionally unchanged. After this fix the Subscription Line already carries priority-resolved values, so the existing "Service Commitment wins" merge produces the correct result while preserving the original design intent that subscription line dimensions stay authoritative at billing.
|
Looks clean and good. I think @Franco111000 is more than capable of finishing this one. From my side, this one can be converted to real PR. I would just like to run all the tests to see if any of those needs adjustment. |
|
Thanks @miljance! Converting to ready for review. Looking forward to the test results, I'll iterate on anything that needs adjustment. |
|
Hi @Franco111000, Two tests are currently failing:
Can you check out and give your thoughts? |
…ustom dims Previous attempt made SubscriptionLine.SetDefaultDimensions priority-aware, but that recomputed the Subscription Line dim from scratch and wiped any already-present custom dimensions, e.g. the auto-insert Customer-Contract dimension propagated via UpdateRelatedVendorServiceCommDimensions to a paired Vendor Subscription Line. New approach: - Revert SetDefaultDimensions to its original Item-only behavior. - Introduce ApplyContractDimensions on Subscription Line. It merges three slots via DimensionManagement.GetCombinedDimensionSetID: current SC dim, Contract dim, and a priority overlay built via DimMgt.GetTableIDsForHigherPriorities + GetRecDefaultDimID containing only Item / G/L Account sources that outrank the Contract partner table per Default Dimension Priority. - UpdateFromCustomerContract / UpdateFromVendorContract and the Pathway B call sites (CreateCustomerContractLineFromServiceCommitment, CreateVendorContractLineFromServiceCommitment, the Import paths) now call ApplyContractDimensions. - Reorders in CustSubContractLine and VendSubContractLine CreateServiceObjectWithServiceCommitment reverted; no longer needed. When no Default Dim Priorities are configured (or when Customer/Vendor outrank Item, the BC default), ApplyContractDimensions degrades to a blind merge with the Contract dim winning on conflict, matching the previous behavior. Only the explicit priority configuration from microsoft#8084 (Item over Customer) triggers the overlay slot. Adds cleanup of the Default Dimension Priority rows the new test inserts so they do not leak to downstream tests in the suite.
|
@miljance, both failures traced to the same cause: my first commit made Pushed a restructure:
Could you give it another run when you have a moment? |
|
@Franco111000 PR looks good and all tests pass. The Two small things I'd like addressed before merging:
Both should be straightforward to include in this PR. Let me know if anything is unclear. |
…s-link procedures Extracts the duplicated dim-source-building logic from SetDefaultDimensions and ApplyContractDimensions into a local helper AddDefaultDimensionSources on Subscription Line. Switches the Subscription Header lookup from an unguarded Get (errors on missing) to a guarded if Get then (silent skip) so the helper is safe to reuse in both contexts. No caller relies on the previous error path. Extends the priority-aware merge to the two cross-link procedures that previously bypassed it: - CustSubContractLine.DeleteRelatedVendorServiceCommDimensions now applies ApplyContractDimensions(VendorContract.Dim, SourceCodeSetup.Purchases, Database::Vendor) on each paired vendor Subscription Line, so Default Dimension Priority for source code Purchases is honored when the customer contract line is deleted and the vendor lines are recomputed. - VendSubContractLine.UpdateServiceCommitmentDimensions now applies ApplyContractDimensions(CustomerContract.Dim, SourceCodeSetup.Sales, Database::Customer) when propagating Customer Contract dim onto a paired Vendor Subscription Line, so the same Sales priority configuration the rest of the PR respects also flows through the cross-link. Under vanilla BC priority configuration (Customer/Vendor outrank Item by default) the overlay stays empty and the behavior remains identical to the prior blind merge.
|
@miljance, both done in the latest commit:
|
What/why
Fixes #8084.
When a Customer Subscription Contract spawns Sales Invoices, Default Dimension
Priorities (table 354) were not respected. With priorities set as Item = 1,
Customer = 2 the resulting Sales Line still carried the Customer's dimension
value instead of the Item's.
Per the discussion with @miljance on #8084, the simple swap of
GetCombinedDimensionSetIDparameter order at the merge step would fix the reported case but would also let
Sales Line defaults beat genuine Subscription Line user overrides, which is a
regression against the original design intent ("Subscription Line dimensions
should overwrite any duplicates from the default dimensions"). This PR addresses
the root cause upstream so both behaviors hold: priorities are respected during
Subscription Line creation, and Subscription Line dimensions remain authoritative
at billing time.
The bug had two compounding causes inside the Subscription Billing module:
SubscriptionLine.SetDefaultDimensionscalledDimMgt.GetDefaultDimID(..., '', ...)with an empty Source Code, soDefault Dimension Prioritywas never read. Only Item / G/L Account were added as dim sources, never Customer / Vendor.GetCombinedDimensionSetIDis a blind last-slot-wins merge.UpdateFromCustomerContractthen merged the Customer Contract dim set into the Subscription Line as slot 2, so Customer values systematically overrode whatever was on the Subscription Line.The fix makes
SubscriptionLine.SetDefaultDimensionsthe single priority-awareentry point for all dim computation:
SourceCodeSetup.Sales(Customer side) orSourceCodeSetup.Purchases(Vendor side) soDefault Dimension Priorityis consultedGetRecDefaultDimIDwith the contract'sDimension Set IDpassed asInheritFromDimSetIDandDatabase::Customer/Database::VendorasInheritFromTableNo, mirroring the standardSalesLine.CreateDimpattern in Base AppUpdateFromCustomerContractandUpdateFromVendorContractnow route throughSetDefaultDimensionsinstead of blind-merging the contract dim set. Samechange at the Pathway B call sites where an existing Subscription Line is
assigned to a contract (
CustomerSubscriptionContract.CreateCustomerContractLineFromServiceCommitment,VendorSubscriptionContract.CreateVendorContractLineFromServiceCommitment, andthe Import paths).
The blind merge at billing time (
CreateBillingDocuments.Codeunit.allines 264/ 383) is intentionally left unchanged. After this fix the Subscription Line's
Dimension Set IDis already priority-resolved, so the existing "ServiceCommitment wins over Sales Line" merge produces the correct result while
preserving the design intent that subscription line dimensions stay
authoritative for billing, which lines up with @miljance's clarification: "the
contract dimensions should win over any conflicting ones from the Subscription
Lines but still respecting the configured priority order."
Linked work
How I validated
RespectDefaultDimensionPrioritiesOnCustomerContractCreationinService Comm. Dimensions. Configures Default Dim Priority Item = 1, Customer = 2 for source code Sales, gives Customer and Item conflicting values on the same dimension, asserts the resulting Subscription Line carries Item's value.Risk & compatibility
Existing tests in
ServiceCommDimensions.Codeunit.almay need adjustments ifthey rely on the previous "Customer Contract dim always wins" merge order in
scenarios with overlapping dim codes. Will iterate based on CI results.
The two cross-link call sites that propagate Customer Contract dim onto
vendor-paired Subscription Lines (
CustSubContractLine.DeleteRelatedVendorServiceCommDimensions,VendSubContractLine.UpdateServiceCommitmentDimensions) are intentionally nottouched in this PR. They involve a related but distinct concern about
cross-partner dim propagation. Happy to follow up once the direction here is
settled.
Opening as draft so @miljance and the consultant can weigh in before we finalize.