[Master] - Sustainability: Specific Carbon Tracking, Item Charge emissions & setup fixes (Bugs 641051, 641486, 641487, 641049, 641222, 641055, 641289, 641224, 641309)#9613
Conversation
…Fixes-for-Specific-Carbon-Tracking
|
Both OnPostItemChargePerOrderOnAfterCopyToItemJnlLine and OnPostItemJnlLineJobConsumption call PurchaseHeader.Get(...) before checking whether the item journal line actually has quantity to post. When that quantity guard fails, the header lookup is wasted on a posting hot path; move the guard ahead of Get in both procedures. Knowledge: Line mapping was unavailable, so this was posted as an issue comment. 👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.12.4 |
|
The subscriber for Undo Service Shipment Line's OnAfterCopyItemJnlLineFromServShpt takes ServiceShipmentLine as its second parameter, but the publisher's second parameter is ServiceShipmentHeader. Subscriber parameters must follow the publisher signature exactly, so ServiceShipmentHeader needs to be inserted before ServiceShipmentLine. Suggested fix (apply manually — could not be anchored as a one-click suggestion): local procedure OnAfterCopyItemJnlLineFromServShptForUndoServiceShipment(var ItemJournalLine: Record "Item Journal Line"; ServiceShipmentHeader: Record "Service Shipment Header"; ServiceShipmentLine: Record "Service Shipment Line")Knowledge: Line mapping was unavailable, so this was posted as an issue comment. 👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.12.4 |
|
The subscriber for Undo Service Consumption Line's OnAfterCopyItemJnlLineFromServShpt also skips the publisher's ServiceShipmentHeader parameter and declares ServiceShipmentLine second instead. Subscriber parameters must match the publisher signature verbatim, so this declaration needs the header parameter inserted before the line parameter. Suggested fix (apply manually — could not be anchored as a one-click suggestion): local procedure OnAfterCopyItemJnlLineFromServShptForUndoServiceConsumption(var ItemJournalLine: Record "Item Journal Line"; ServiceShipmentHeader: Record "Service Shipment Header"; ServiceShipmentLine: Record "Service Shipment Line")Knowledge: Line mapping was unavailable, so this was posted as an issue comment. 👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.12.4 |
|
@v-rohangarg20 please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
PR description
Sustainability – Fixes for Specific Carbon Tracking, Item Charge emissions, value‑chain posting & setup
Fixes AB#641051, AB#641486, AB#641487, AB#641049, AB#641222, AB#641055, AB#641289, AB#641224, AB#641309
This PR groups related fixes around Specific carbon tracking, item‑charge emission posting, value‑chain (purchase/sales/service/undo) emission handling, and Sustainability Setup.
Bug 641051 – Item Charge CO2e not distributed across received/applied quantity
Issue: Posting a purchase Item Charge assigned the full "CO2e to Assign" to one item journal line; for charges applied to split item ledger entries emissions weren't spread proportionally.
Solution: Added split detection (GetDistributeItemCharge via SplitItemLedgerEntriesExist) and proportional allocation CO2e to Assign × ChargeQtyToPostBase / ItemChargeTotalQty, plus OnPostItemTrackingItemChargePerOrderOnAfterCalcFactor to split remaining CO2e per tracking specification. Also skips GetTotalCO2eAmount for purchase item‑charge value entries.
Bug 641486 – Wrong sign on Total CO2e when splitting from applied‑from entries
Issue: Emissions derived from an "Applies‑from Entry" (returns/negative adjustments) could post with the wrong sign.
Solution: Derived explicit Sign from Total CO2e and used Sign * Abs(CO2eAmount/CO2eQuantity) * Abs(Quantity); prorated the non‑split branch by quantity.
Bug 641487 – Missing/incorrect value entries for Undo Purchase Receipt & Service documents
Issue: Undo purchase receipt didn't reverse/recreate value entries; service documents didn't post emissions; service‑shipment positive adjustments wrongly inherited Correction.
Solution: Added undo subscribers (Undo Purchase Receipt Line, Undo Posting Management) recomputing emissions via UpdateSustainabilityItemJournalLine; added Sales/Service subscriber support; guarded the Correction assignment for Service Shipment positive adjustments.
Bug 641049 – No warning to enable Item Tracking when Carbon Tracking Method = Specific
Issue: Setting Specific was allowed with no serial/lot‑specific tracking and no feedback.
Solution: Added WarnIfSpecificCarbonTrackingLacksItemTracking, invoked from "Carbon Tracking Method" OnValidate and "Item Tracking Code" OnAfterValidate; shows a message when the tracking code is missing or not IsSpecific().
Bug 641222 – CO2e per Unit not visible/editable on Item Journal
Issue: Item Journal showed only "Total CO2e"; "CO2e per Unit" required Page Inspector.
Solution: Added a "CO2e per Unit" control before "Total CO2e" on the "Sust. Item Journal" page extension.
Bug 641055 – Scope 3 Distance: Installation Multiplier defaults to 0 in purchase documents (0 emissions)
Issue: On distance‑based Scope 3 purchase lines, Installation Multiplier defaulted to 0, so Distance × Factor × Multiplier = 0 — while the journal (InitValue = 1) worked.
Solution: Set InitValue = 1 on the purchase line "Installation Multiplier" field to mirror the journal, and removed Installation Multiplier from the formula zero‑checks (ClearEmissionInformation, CheckEmissionMustBeZeroWhenFormulaIsUpdated, CheckSustainabilityFormula) and gated recalculation via IsSustainabilityFormulaPurchaseLine(), so per‑unit/Fuel/Custom lines are unaffected.
Bug 641289 – Item Charge Emissions: wrong tooltip & not activated with Value Chain Tracking
Issue: Tooltip said "(currently not operating)"; enabling Value Chain Tracking didn't turn on Item Charge Emissions.
Solution: Added Rec.Validate("Item Charge Emissions", true) to the auto‑enable routine, corrected the Item Charge tooltip, and clarified the Enable Value Chain Tracking tooltip to list all auto‑enabled options.
Bug 641224 – Fixed Asset emissions posted for non‑Acquisition Cost FA lines
Issue: A purchase FA line with "FA Posting Type" ≠ Acquisition Cost (e.g. Maintenance) could still post sustainability entries, which isn't valid.
Solution: Restricted sustainability value‑entry posting to Acquisition Cost FA lines; posting with another FA posting type now errors ("It is only allowed to post Sustainability Entry for Acquisition Cost.") and creates no Sustainability Ledger Entry. Covered by new test TestSustValueChainFixedAssetForPurchaseInvoiceWithoutAcqCost.
Bug 641309 – Item Reclassification uses averaged emissions instead of Specific (lot/serial) carbon tracking
Issue: When an item uses Carbon Tracking Method = Specific, an item reclassification (location move) transferred cost correctly per tracked lots/serials, but emissions were calculated from an averaged CO2e per unit × quantity, ignoring the specific per‑lot/serial CO2e.
Solution: In GetTotalCO2eAmount (Sustainability Post Mgt), run the applied‑entries lookup first and, for Transfer entries, derive TotalCO2e from the specific applied CO2e (AppliedAmount / AppliedQuantity × Quantity), falling back to the averaged CO2e per unit only when no specific applied data exists — so emissions follow the moved lots/serials, mirroring how cost is transferred.
Files changed (14): SustItem.TableExt.al, SustItemJournal.PageExt.al, SustItemPostSubscriber.Codeunit.al, SustainabilityPostMgt.Codeunit.al, SustPurchaseSubscriber.Codeunit.al, SustainabilityPurchLine.TableExt.al, SustSalesSubscriber.Codeunit.al, SustServiceSubscriber.Codeunit.al, SustainabilitySetup.Page.al, SustainabilitySetup.Table.al, plus tests SustItemChrgAssignTest.Codeunit.al, SustValueChainFixedAsset.Codeunit.al, SustValueEntryTest.Codeunit.al, SustainabilityServiceTests.Codeunit.al.
Risk & compatibility: Scoped to the Sustainability app (posting subscribers, purchase line defaults, setup UI). Existing averaged/non‑item‑charge flows preserved; Transfer/specific paths only change when specific applied data exists. No schema/breaking changes.