[Main]- Standard-cost purchase receipts use Direct Unit Cost instead of Standard Cost when cumulative expected-cost rounding is enabled - #10094
Conversation
Agentic PR Review - Round 1Recommendation: AcceptWhat this PR doesThis PR fixes a bug where posting a purchase receipt for a Standard-cost item incorrectly calculates The fix adds an early SuggestionsNo suggestions. Risk assessment and necessityRisk: The change is a targeted two-line guard in a single local function. The only behavioral change is that Necessity: The bug causes the interim inventory value and the Inventory Accrual (Interim) G/L balance to be overstated for every Standard-cost purchase receipt when cumulative expected-cost rounding is enabled. The fix correctly restores standard costing semantics (inventory always valued at Standard Cost) without touching any shared code path. The scope is appropriate for a targeted bug fix.
|
Bug 646424: [master] [Repair Item] [ALL-E] Standard-cost purchase receipts use Direct Unit Cost instead of Standard Cost when cumulative expected-cost rounding is enabled
AB#646424
Issue: When posting a purchase receipt (receive only, no invoice) for an item with Costing Method = Standard, the Cost Amount (Expected) on the Value Entry is calculated from the Direct Unit Cost on the purchase line instead of the item's Standard Cost (e.g. Standard Cost 0.134 × 1000 posts 136.00 instead of 134.00). This overstates the interim inventory value and the Inventory Accrual (Interim) G/L amount, breaking the standard costing principle that inventory is always valued at Standard Cost.
Cause: In CalcPosShares in ItemJnlPostLine.Codeunit.al, the fix for Bug 631139 (PR 245490) introduced ShouldUseCumulativeRoundingForExpectedCost to switch the expected-cost basis from ItemJnlLine."Unit Cost" * ItemJnlLine.Quantity to ItemJnlLine.Amount in order to eliminate a 0.01 rounding residual across partial receipts. For FIFO/Average items these two expressions are equivalent, but the guard did not exclude Standard costing, where ItemJnlLine.Amount carries the vendor's Direct Unit Cost and legitimately differs from Standard Cost — so the price difference was silently capitalised into inventory instead of being recognised as Purchase Variance on invoicing.
Solution: Added an early if Item."Costing Method" = Item."Costing Method"::Standard then exit(false); check to ShouldUseCumulativeRoundingForExpectedCost in ItemJnlPostLine.Codeunit.al (W1 plus the APAC, CH, ES, IT and RU layers), so Standard-cost items fall back to the Unit Cost * Quantity basis and post expected cost at Standard Cost. The two scenarios are mutually exclusive on Costing Method, so Bug 631139's cumulative-rounding behaviour is fully preserved for FIFO/Average/LIFO/Specific items, and the price difference is correctly posted to Purchase Variance when the receipt is invoiced. Added regression test StandardCostItemExpectedCostUsesStandardCostOnReceipt to codeunit 137018.