---
id: change/bcapps/9984
type: change
title: "#9984 [Main] Error with unposted prepayment amounts on Order"
summary: Fixed an error where unposted prepayment amounts on sales and purchase orders were calculated incorrectly when the quantity to invoice was modified, by making the prepayment deduction calculation idempotent across multiple trigger invocations.
tier: official
language: en
tags:
  - fix
  - main
  - bc30
  - table purchase line
  - table sales line
system: purchasing
review:
  state: reviewed
  by: opus
  at: "2026-10-08T02:09:43.515Z"
  flags: []
generated:
  at: "2026-10-08T01:26:53.141Z"
  pipeline: 0.2.0
  prompts:
    extract-change: 1
  input_hash: 18d5d6b1910ad30698e8d3855c9bfd2173b05aa8
evidence:
  - kind: code
    url: https://github.com/microsoft/BCApps/pull/9984
    title: "microsoft/BCApps#9984: [Main] Error with unposted prepayment amounts on Order"
    date: "2026-08-11"
    commit: 18d5d6b1910ad30698e8d3855c9bfd2173b05aa8
    t: null
    quote: Error with unposted prepayment amounts on Order
links:
  learn: []
  objects:
    - object/table/39
    - object/table/37
  features: []
  topics: []
  localizations: []
  videos: []
  posts: []
  guidelines: []
  changes: []
number: 9984
repo: microsoft/BCApps
source_id: bcapps-prs
url: https://github.com/microsoft/BCApps/pull/9984
kind: pr
base_branch: main
major: "30"
merged_at: "2026-08-11T13:26:34Z"
author: sanjmaurya
author_type: User
community_contribution: true
labels:
  - "ADO: Sync"
  - From Fork
  - "Team: SCM"
change_class: code
change_kind: fix
behavior_change: true
breaking: false
files:
  count: 30
  additions: 338
  deletions: 78
  al: 26
apps:
  - Base Application
objects_touched:
  - key: table/39
    page: table/39
    type: table
    id: 39
    name: Purchase Line
    app: Base Application
    status: modified
  - key: table/37
    page: table/37
    type: table
    id: 37
    name: Sales Line
    app: Base Application
    status: modified
objects_unjoined:
  - path: src/Layers/BE/BaseApp/Sales/Document/SalesLine.Table.al
    status: modified
    reason: not-in-snapshot
obsoletions: []
backports: []
fixes_issues: []
work_items:
  - 645184
systems:
  - purchasing
  - sales
quote: Error with unposted prepayment amounts on Order
joined_against:
  major: "30"
  commit: f18567dc08e2bd162bf192e1da4d714b57eb099f
---

# #9984 [Main] Error with unposted prepayment amounts on Order

> Fixed an error where unposted prepayment amounts on sales and purchase orders were calculated incorrectly when the quantity to invoice was modified, by making the prepayment deduction calculation idempotent across multiple trigger invocations.

[Pull request](https://github.com/microsoft/BCApps/pull/9984) · merged into `main` (BC30) on 2026-08-11 by sanjmaurya (community contribution) · 30 files (+338 -78), 26 AL · fix · tier official · reviewed (checked by Opus)

## What changed

- The CalcPrepaymentToDeduct function was being called twice during Qty. to Invoice field updates, causing different rounding results based on the current field value
- Changed the calculation to reset the prepayment deduction field to zero before recomputing, ensuring deterministic simple-branch rounding each time
- The final invoice still applies proration logic to true up totals when marked as final
- Fix applied uniformly across all localization layers (W1, NA, BE, CH, DACH, ES, FI, GB, IT, NL, NO, RU, SE, APAC)
- Added comprehensive test cases for both sales and purchase prepayment rounding scenarios
- Behaviour changes for users or extensions.

## AL objects touched

- [Table 39 "Purchase Line"](../../objects/table/39.md), Base Application: modified
- [Table 37 "Sales Line"](../../objects/table/37.md), Base Application: modified
- `src/Layers/BE/BaseApp/Sales/Document/SalesLine.Table.al`: modified, not in the BC30 snapshot

## Context

- Work items: AB#645184
- Labels: ADO: Sync, From Fork, Team: SCM
- Systems: purchasing, sales
- From the description: "Error with unposted prepayment amounts on Order"

Source: metadata of a merged pull request in microsoft/BCApps (bcapps): title, labels, changed paths and counts, with a summary in our words. No source text and no description beyond one short quote (D10, D61).
