-
Notifications
You must be signed in to change notification settings - Fork 436
Bug 646432: [master] [Sustainability] Line does not indicate/enforce which Calculation Foundation is in use; all formula input fields are editable #10183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| namespace Microsoft.Sustainability.Purchase; | ||
|
|
||
| using Microsoft.Purchases.Document; | ||
| using Microsoft.Sustainability.Calculation; | ||
| using Microsoft.Sustainability.Setup; | ||
|
|
||
| pageextension 6211 "Sust. Purch. Order Subform" extends "Purchase Order Subform" | ||
|
|
@@ -14,6 +15,11 @@ pageextension 6211 "Sust. Purch. Order Subform" extends "Purchase Order Subform" | |
| Visible = SustainabilityVisible; | ||
| ApplicationArea = Basic, Suite; | ||
| ToolTip = 'Specifies the value of the Sustainability Account No. field.'; | ||
|
|
||
| trigger OnValidate() | ||
| begin | ||
| SetFormulaInputEditability(); | ||
| end; | ||
| } | ||
| field("Energy Source Code"; Rec."Energy Source Code") | ||
| { | ||
|
|
@@ -32,30 +38,35 @@ pageextension 6211 "Sust. Purch. Order Subform" extends "Purchase Order Subform" | |
| } | ||
| field("Fuel/Electricity"; Rec."Fuel/Electricity") | ||
| { | ||
| Editable = FuelElectricityEditable; | ||
| Visible = SustainabilityFormulasFieldVisible; | ||
| ApplicationArea = Basic, Suite; | ||
| ToolTip = 'Specifies the fuel or electricity of the purchase line.'; | ||
| } | ||
| field(Distance; Rec.Distance) | ||
| { | ||
| Editable = DistanceEditable; | ||
| Visible = SustainabilityFormulasFieldVisible; | ||
| ApplicationArea = Basic, Suite; | ||
| ToolTip = 'Specifies the distance of the purchase line.'; | ||
| } | ||
| field("Custom Amount"; Rec."Custom Amount") | ||
| { | ||
| Editable = CustomAmountEditable; | ||
| Visible = SustainabilityFormulasFieldVisible; | ||
| ApplicationArea = Basic, Suite; | ||
| ToolTip = 'Specifies the custom amount of the purchase line.'; | ||
| } | ||
| field("Installation Multiplier"; Rec."Installation Multiplier") | ||
| { | ||
| Editable = InstallationMultiplierEditable; | ||
| Visible = SustainabilityFormulasFieldVisible; | ||
| ApplicationArea = Basic, Suite; | ||
| ToolTip = 'Specifies the installation multiplier of the purchase line.'; | ||
| } | ||
| field("Time Factor"; Rec."Time Factor") | ||
| { | ||
| Editable = TimeFactorEditable; | ||
| Visible = SustainabilityFormulasFieldVisible; | ||
| ApplicationArea = Basic, Suite; | ||
| ToolTip = 'Specifies the time factor of the purchase line.'; | ||
|
|
@@ -122,6 +133,16 @@ pageextension 6211 "Sust. Purch. Order Subform" extends "Purchase Order Subform" | |
| VisibleSustainabilityControls(); | ||
| end; | ||
|
|
||
| trigger OnAfterGetRecord() | ||
| begin | ||
| SetFormulaInputEditability(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SetFormulaInputEditability is invoked unconditionally from OnAfterGetRecord/OnAfterGetCurrRecord (and from the Sust. Account No. OnValidate trigger) on the Purchase Order Subform even when the sustainability formula fields are not visible (SustainabilityFormulasFieldVisible = false, i.e. 'Use Formulas In Purch. Docs' is off in Sustainability Setup). This causes an unnecessary lookup into 'Sustainability Calc. Mgt.' for every row rendered on a purchase order subform for customers who do not use this feature at all. Guard the call with the existing SustainabilityFormulasFieldVisible flag so the cost is only paid when the fields are actually shown. Suggested fix (apply manually — could not be anchored as a one-click suggestion): local procedure SetFormulaInputEditability()
begin
if not SustainabilityFormulasFieldVisible then
exit;
SustainabilityCalcMgt.GetFormulaInputEditability(Rec, FuelElectricityEditable, DistanceEditable, CustomAmountEditable, InstallationMultiplierEditable, TimeFactorEditable);
end;Knowledge: 👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.33.4 |
||
| end; | ||
|
|
||
| trigger OnAfterGetCurrRecord() | ||
| begin | ||
| SetFormulaInputEditability(); | ||
| end; | ||
|
|
||
| local procedure VisibleSustainabilityControls() | ||
| var | ||
| SustainabilitySetup: Record "Sustainability Setup"; | ||
|
|
@@ -132,7 +153,15 @@ pageextension 6211 "Sust. Purch. Order Subform" extends "Purchase Order Subform" | |
| SustainabilityFormulasFieldVisible := SustainabilitySetup."Use Formulas In Purch. Docs"; | ||
| end; | ||
|
|
||
| local procedure SetFormulaInputEditability() | ||
| begin | ||
| SustainabilityCalcMgt.GetFormulaInputEditability(Rec, FuelElectricityEditable, DistanceEditable, CustomAmountEditable, InstallationMultiplierEditable, TimeFactorEditable); | ||
| end; | ||
|
|
||
| var | ||
| SustainabilityCalcMgt: Codeunit "Sustainability Calc. Mgt."; | ||
| SustainabilityVisible: Boolean; | ||
| SustainabilityFormulasFieldVisible: Boolean; | ||
| FuelElectricityEditable, DistanceEditable, CustomAmountEditable : Boolean; | ||
| InstallationMultiplierEditable, TimeFactorEditable : Boolean; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetCalculationParameters in 'Sustainability Calc. Mgt.' caches the 'Emission Scope' and 'Calculation Foundation' of a Sustain. Account Category in page-lifetime Dictionary fields (EmissionScopeCache / CalculationFoundationCache) keyed only by account category code, with no invalidation. Because the 'Sustainability Calc. Mgt.' codeunit instance is held as a page-level variable on both the Sustainability Journal page and the Purchase Order Subform, the cache lives for the whole page session. If a user edits an account category's Emission Scope or Calculation Foundation (e.g. via the Sustain. Account Categories page) while a Sustainability Journal or Purchase Order page is already open, the open page keeps showing stale field editability for that category until it is closed and reopened, since the cached values are never refreshed or invalidated. Consider keying/expiring the cache per page-open, or accepting this as a known limitation given account categories are typically static setup data (should be confirmed with the author).
Agent judgement — not directly backed by a BCQuality knowledge article.
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.33.4