Skip to content

[Bug][Subscription Billing] Wrong number of days on vendor contract deferrals when the billing period lies within a single calendar month #10097

Description

Describe the issue

When a vendor subscription contract is invoiced for a billing period that starts and ends inside the same calendar month — for example a single day, or the first half of a month — the resulting vendor contract deferrals show a number of days that runs to the end of the month instead of the days actually billed.

The deferred amounts themselves are correct. Only the number of days is wrong, which makes the deferral lines look inconsistent with the amount and misleads anyone reconciling the deferral schedule against the billing period.

The same problem was reported and fixed for customer contracts, but the equivalent correction was never applied to vendor contracts, so purchase-side deferrals still show the old behaviour.

Expected behavior

The number of days on a deferral line must reflect the part of the billing period that falls into that calendar month:

  • If the billing period does not cross the end of its starting month, a single deferral line is created and its Number of Days must equal the length of the billing period.
    • 12.03.2026 – 12.03.2026 → one line with Number of Days = 1
    • 12.03.2026 – 20.03.2026 → one line with Number of Days = 9
    • 01.03.2026 – 15.03.2026 → one line with Number of Days = 15
  • Otherwise each line reflects either the whole calendar month, the part of the first month from the billing start, or the part of the last month up to the billing end.
    • 12.03.2026 – 11.05.2026 → 20 / 30 / 11

Actual behavior today for the single-month cases above: 20 / 20 / 31.

Cause and proposed fix

InsertContractDeferralPeriods in VendorDeferralsMngmt.Codeunit.al picks the number of days like this:

if (i = NumberOfPeriods) and (NumberOfPeriods > 1) and (FirstMonthIsPartial or LastMonthIsPartial) then
    VendorContractDeferral."Number of Days" := LastMonthDays
else
    if (i = 1) and FirstMonthIsPartial then
        VendorContractDeferral."Number of Days" := FirstMonthDays
    else
        VendorContractDeferral."Number of Days" := Date2DMY(CalcDate('<CM>', VendorContractDeferral."Posting Date"), 1);

The NumberOfPeriods > 1 guard excludes the single-period case from the first branch, so a one-month billing period falls through to FirstMonthDays (start of billing period until end of month) or to the full calendar month.

The customer-side codeunit already handles this with a dedicated single-period branch (added by #7122):

if NumberOfPeriods = 1 then
    CustomerContractDeferral."Number of Days" := NumberOfDaysInSchedule
else
    ...

The same branch should be added to VendorDeferralsMngmt.InsertContractDeferralPeriods. NumberOfDaysInSchedule is already computed there as "Recurring Billing to" - "Recurring Billing from" + 1, so no new calculation is needed, and the NumberOfPeriods > 1 guard on the last-period branch becomes redundant.

There is also no test coverage for vendor deferrals — src/Apps/W1/Subscription Billing/Test/Deferrals/ only contains CustomerDeferralsTest.Codeunit.al, which is why the customer-side fix left the vendor side behind. A vendor counterpart covering the single-month period and the multi-month split should be added along with the fix.

Steps to reproduce

  1. Open Subscriptions and create a subscription with a subscription line that has a vendor (supplier) assigned, with a monthly billing rhythm.
  2. Open Vendor Subscription Contracts and create a contract for that vendor, then assign the subscription line to it.
  3. On the vendor contract, choose Create Billing Proposal and set the billing date so that the resulting billing period starts and ends in the same calendar month — for example Recurring Billing from 12.03.2026 and Recurring Billing to 12.03.2026.
  4. Choose Create Billing Documents to create the purchase invoice, then post it.
  5. Open Vendor Subscription Contract Deferrals for the contract.

Observed: one deferral line with Number of Days = 20 (12.03. until the end of March).
Expected: one deferral line with Number of Days = 1.

Repeat with a billing period of 12.03.2026 – 11.05.2026 to confirm the multi-month case is unaffected (20 / 30 / 11), and with 12.03.2026 – 12.03.2026 on a customer subscription contract to see the already-correct behaviour on the sales side (Number of Days = 1).

Additional context

The customer-side half of this issue was fixed by "Incorrect deferral amount calculation in Subscription Billing when the contract start date is not the first day of the month" (#7122), which added the single-period branch to CustomerDeferralsMngmt only. This issue is the remaining vendor-side half.

I will provide a fix for a bug

  • I will provide a fix for a bug

Metadata

Metadata

Labels

ApprovedThe issue is approvedFinanceGitHub request for Finance area

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions