microsoft / ALAppExtensions

Repository for collaboration on Microsoft AL application add-on and localization extensions for Microsoft Dynamics 365 Business Central.
MIT License
748 stars 600 forks source link

[Event Request] Codeunit 1002 "Job Create - Invoice" - procedure CreateSalesLine #26759

Closed mrabus closed 5 days ago

mrabus commented 1 week ago

For a customization, I require the following event to change the behavior of the "Job Create - Invoice" codeunit.

//Codeunit 1002 "Job Create - Invoice" - procedure CreateSalesLine 
if SalesLine.Type <> SalesLine.Type::" " then begin
    SalesLine.Validate("Unit of Measure Code", JobPlanningLine."Unit of Measure Code");
    SalesLine.Validate(Quantity, Factor * JobPlanningLine."Qty. to Transfer to Invoice");
    if JobPlanningLine."Bin Code" <> '' then
        SalesLine."Bin Code" := JobPlanningLine."Bin Code";
    if JobInvCurrency then begin
        OnCreateSalesLineOnBeforeValidateCurrencyCode(IsHandled, SalesLine, JobPlanningLine);
        if not IsHandled then begin
            Currency.Get(SalesLine."Currency Code");
            SalesLine.Validate("Unit Price",
            Round(JobPlanningLine."Unit Price" * SalesHeader."Currency Factor",
                Currency."Unit-Amount Rounding Precision"));
        end;
    end else
        SalesLine.Validate("Unit Price", JobPlanningLine."Unit Price");
    SalesLine.Validate("Unit Cost (LCY)", JobPlanningLine."Unit Cost (LCY)");
    SalesLine.Validate("Line Discount %", JobPlanningLine."Line Discount %");
    SalesLine."Inv. Discount Amount" := 0;
    SalesLine."Inv. Disc. Amount to Invoice" := 0;
    SalesLine.UpdateAmounts();
end;
//NEW CODE
OnBeforeCheckPricesIncludingVATAndSetJobInfos(SalesLine, JobPlanningLine, IsHandled);
if not IsHandled then
//NEW CODE
    if not SalesHeader."Prices Including VAT" then
        SalesLine.Validate("Job Contract Entry No.", JobPlanningLine."Job Contract Entry No.");
    SalesLine."Job No." := JobPlanningLine."Job No.";
    SalesLine."Job Task No." := JobPlanningLine."Job Task No.";
//NEW CODE
end;
//NEW CODE
SalesLine.Description := JobPlanningLine.Description;
SalesLine."Description 2" := JobPlanningLine."Description 2";
SalesLine."Line No." := GetNextLineNo(SalesLine);
OnBeforeInsertSalesLine(SalesLine, SalesHeader, Job, JobPlanningLine, JobInvCurrency);
SalesLine.Insert(true);

[IntegrationEvent(false, false)]
local procedure OnBeforeCheckPricesIncludingVATAndSetJobInfos(var SalesLine: Record "Sales Line"; JobPlanningLine: Record "Job Planning Line"; var IsHandled: Boolean)
begin
end;

Additional context

In some cases, I need to skip the check of "Prices including VAT" and the "Job No." and "Job Task No." field. Therefore, I propose to introduce this event as shown Internal work item: AB#539832

JesperSchulz commented 5 days ago

Thanks for reporting this. We agree, and we’ll publish a fix asap, either in an update for the current version or in the next major release. Please do not reply to this, as we do not monitor closed issues. If you have follow-up questions or requests, please create a new issue where you reference this one.

Build ID: 21487.