Skip to content

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

Description

@Franco111000

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    SCMGitHub request for SCM area

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions