---
id: change/bcapps/13479
type: change
title: "#13479 [29.x][ALL-E] Canceling a posted purchase invoice fails or misallocates item charges assigned to posted document types other than Purchase Receipts"
summary: Fixed a bug where canceling a posted purchase invoice could fail or reverse item charges incorrectly when charges were assigned to documents other than Purchase Receipts. The fix now handles all supported document types and uses the correct cost amount field for each.
tier: official
language: en
tags:
  - fix
  - releases/29.x
  - bc29
  - codeunit copy document mgt.
  - codeunit item charge assgnt. (purch.)
  - codeunit item charge assgnt. (sales)
system: platform
review:
  state: reviewed
  by: opus
  at: "2026-12-01T01:07:31.009Z"
  flags: []
generated:
  at: "2026-12-06T00:14:19.053Z"
  pipeline: 0.2.0
  prompts:
    extract-change: 1
  input_hash: dbe0726bd63ba32b7c75d6689c863cc76d0c2e37
evidence:
  - kind: code
    url: https://github.com/microsoft/BCApps/pull/13479
    title: "microsoft/BCApps#13479: [29.x][ALL-E] Canceling a posted purchase invoice fails or misallocates item charges assigned to posted document types other than Purchase Receipts"
    date: "2026-11-30"
    commit: dbe0726bd63ba32b7c75d6689c863cc76d0c2e37
    t: null
    quote: null
links:
  learn: []
  objects:
    - object/codeunit/6620
    - object/codeunit/5805
    - object/codeunit/5807
  features: []
  topics: []
  localizations: []
  videos: []
  posts: []
  guidelines: []
  changes: []
  related:
    - to: https://learn.microsoft.com/dynamics365/business-central/dev-itpro/developer/devenv-creating-and-interacting-with-odatav4-bound-action
      title: Creating and Interacting with an OData V4 Bound Action
      label: possibly related
      why: touches Codeunit 6620 "Copy Document Mgt."
      by: code
    - to: https://learn.microsoft.com/dynamics365/business-central/dev-itpro/developer/devenv-extending-item-charges
      title: Extending Item Charges Distribution Methods
      label: possibly related
      why: touches Codeunit 5805 "Item Charge Assgnt. (Purch.)"
      by: code
    - to: https://learn.microsoft.com/dynamics365/business-central/sales-how-correct-cancel-sales-invoice
      title: Correct or cancel a posted sales invoice
      label: possibly related
      why: Explains canceling posted purchase invoices and automatic corrective document creation.
      by: model
    - to: https://learn.microsoft.com/dynamics365/business-central/reports/report-5806
      title: Item Charges - Specification (report)
      label: possibly related
      why: Documents item charges specification and their posting in various document types.
      by: model
number: 13479
repo: microsoft/BCApps
source_id: bcapps-prs
url: https://github.com/microsoft/BCApps/pull/13479
kind: pr
base_branch: releases/29.x
major: "29"
merged_at: "2026-11-30T17:19:35Z"
author: sanjmaurya
author_type: User
community_contribution: false
labels:
  - "Ownership: Needs Review"
  - "Team: Other"
change_class: code
change_kind: fix
behavior_change: true
breaking: false
files:
  count: 10
  additions: 980
  deletions: 124
  al: 8
apps:
  - Base Application
objects_touched:
  - key: codeunit/6620
    page: codeunit/6620
    type: codeunit
    id: 6620
    name: Copy Document Mgt.
    app: Base Application
    status: modified
  - key: codeunit/5805
    page: codeunit/5805
    type: codeunit
    id: 5805
    name: Item Charge Assgnt. (Purch.)
    app: Base Application
    status: modified
  - key: codeunit/5807
    page: codeunit/5807
    type: codeunit
    id: 5807
    name: Item Charge Assgnt. (Sales)
    app: Base Application
    status: modified
objects_unjoined:
  - path: src/Layers/IT/BaseApp/Utilities/CopyDocumentMgt.Codeunit.al
    status: modified
    reason: not-in-snapshot
  - path: src/Layers/NL/BaseApp/Utilities/CopyDocumentMgt.Codeunit.al
    status: modified
    reason: not-in-snapshot
  - path: src/Layers/RU/BaseApp/Utilities/CopyDocumentMgt.Codeunit.al
    status: modified
    reason: not-in-snapshot
obsoletions: []
backports: []
fixes_issues: []
work_items:
  - 657337
systems:
  - platform
  - purchasing
  - sales
quote: null
joined_against:
  major: "29"
  commit: 4e6a307ce8a2e8c5a28f8f0c4c2c7d561f4fe679
---

# #13479 [29.x][ALL-E] Canceling a posted purchase invoice fails or misallocates item charges assigned to posted document types other than Purchase Receipts

> Fixed a bug where canceling a posted purchase invoice could fail or reverse item charges incorrectly when charges were assigned to documents other than Purchase Receipts. The fix now handles all supported document types and uses the correct cost amount field for each.

[Pull request](https://github.com/microsoft/BCApps/pull/13479) · merged into `releases/29.x` (BC29) on 2026-11-30 by sanjmaurya · 10 files (+980 -124), 8 AL · fix · tier official · reviewed (checked by Opus)

## What changed

- Canceling a posted purchase invoice now recreates item charge assignments for Purchase Receipt, Transfer Receipt, Purchase Return Shipment, Sales Shipment and Sales Return Receipt
- Cost Amount (Non-Invtbl.) is used for Purchase Return Shipment and Sales Shipment; Cost Amount (Actual) is used for the other targets
- Rounding is based only on supported value entries, so skipped targets no longer shift quantities to the remaining assignments
- Changes are in Copy Document Mgt. across several layers, with small edits to the purchase and sales item charge assignment codeunits
- Behaviour changes for users or extensions.

## AL objects touched

- [Codeunit 6620 "Copy Document Mgt."](../../objects/codeunit/6620.md), Base Application: modified
- [Codeunit 5805 "Item Charge Assgnt. (Purch.)"](../../objects/codeunit/5805.md), Base Application: modified
- [Codeunit 5807 "Item Charge Assgnt. (Sales)"](../../objects/codeunit/5807.md), Base Application: modified
- `src/Layers/IT/BaseApp/Utilities/CopyDocumentMgt.Codeunit.al`: modified, not in the BC29 snapshot
- `src/Layers/NL/BaseApp/Utilities/CopyDocumentMgt.Codeunit.al`: modified, not in the BC29 snapshot
- `src/Layers/RU/BaseApp/Utilities/CopyDocumentMgt.Codeunit.al`: modified, not in the BC29 snapshot

## Context

- Work items: AB#657337
- Labels: Ownership: Needs Review, Team: Other
- Systems: platform, purchasing, sales

## Possibly related

No source states these links: they share an object, a model read them, or a person found the same subject.

- [Creating and Interacting with an OData V4 Bound Action](https://learn.microsoft.com/dynamics365/business-central/dev-itpro/developer/devenv-creating-and-interacting-with-odatav4-bound-action) — possibly related: touches Codeunit 6620 "Copy Document Mgt."
- [Extending Item Charges Distribution Methods](https://learn.microsoft.com/dynamics365/business-central/dev-itpro/developer/devenv-extending-item-charges) — possibly related: touches Codeunit 5805 "Item Charge Assgnt. (Purch.)"
- [Correct or cancel a posted sales invoice](https://learn.microsoft.com/dynamics365/business-central/sales-how-correct-cancel-sales-invoice) — possibly related: Explains canceling posted purchase invoices and automatic corrective document creation. (model-linked)
- [Item Charges - Specification (report)](https://learn.microsoft.com/dynamics365/business-central/reports/report-5806) — possibly related: Documents item charges specification and their posting in various document types. (model-linked)

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).
