microsoft / microsoft/BCApps

[Bug]: Calculate Inventory applies default dimensions from an unrelated Location whose Code equals the Item No.

Open
#9,100 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Approved Team: SCM
Dominant language
AL
Stars
683
Forks
459
Avg merge
3d 26m
Merged PRs (30d)
633

Description

Describe the issue

Report 790 "Calculate Inventory", procedure CreateDimFromDefault(), filters Default Dimension with two independent OR-filters:

DefaultDimension.SetFilter("No.", '%1|%2', TempQuantityOnHandBuffer."Item No.", TempQuantityOnHandBuffer."Location Code");
DefaultDimension.SetFilter("Table ID", '%1|%2', DATABASE::Item, DATABASE::Location);

Because "No." and "Table ID" are filtered independently, the combinations are never paired per table. If an Item's No. happens to equal the Code of some unrelated Location (for example both are 10), that unrelated Location's default dimensions pass both filters and leak onto the counting journal line, even when the inventory is calculated for a completely different location.

Verified still present in current main: src/Layers/W1/BaseApp/Inventory/Counting/Journal/CalculateInventory.Report.al, CreateDimFromDefault().

The fix is to replace the cross-product filter with two scoped reads: one for ("Table ID" = Database::Item, "No." = Item No.) and one for ("Table ID" = Database::Location, "No." = Location Code).

Expected behavior

Only the default dimensions of the counted Item and of the Location actually being counted are applied to the physical inventory journal line. A Location that merely shares its Code with the Item's No. must not contribute dimensions.

Steps to reproduce
  1. Create Item with No. = 10.
  2. Create Location with Code = 10 and add default dimensions to it.
  3. Post some inventory for Item 10 on a different location (e.g. BLUE).
  4. Run Calculate Inventory (report 790) for location BLUE.
  5. The journal line receives the default dimensions of Location 10, which has nothing to do with the count.
Additional context

This is a copy of microsoft/BusinessCentralApps#1542 (reported by Karel Koncel, labeled Approved/SCM in the contribution pilot). It was being fixed in microsoft/BusinessCentralApps#1908, which was reviewed (a regression test was requested and added) but was closed unmerged when the repository was retired. Re-filing here per the retirement notice to re-submit the fix against BCApps.

I will provide a fix for a bug
  • I will provide a fix for a bug

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/Layers/W1/BaseApp/Inventory/Counting/Journal/CalculateInventory.Report.al at report 790's CreateDimFromDefault() procedure. Reproduce the Item No. and Location Code collision described in the issue, then verify that only the counted Item and Location dimensions reach the physical inventory journal line; add or update a regression test based on the prior fix context.

Written by the indexing model from the issue text.

Assessment

Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
75/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.