Skip to content

[Event Request] New IntegrationEvent in procedure SendDocToCartera of codeunit 12 #29531

@ccastro-pwd

Description

@ccastro-pwd

Why do you need this change?

The current implementation of SendDocToCartera only handles Invoice documents. Partners need a supported extension point to add/override logic so Credit Memos (and potentially other document types in the future) can be sent to cartera following custom business rules.

Describe the request

Requested Change

Introduce a new IntegrationEvent raised at the end of SendDocToCartera, with sufficient context (journal line, ledger entries, doc type, buffer) to allow subscribers to:

  • Detect when the standard logic has processed the document.
  • Add complementary logic to handle Credit Memos and other scenarios.
  • Optionally modify related entries if needed.

Affected Object

  • Object: Codeunit 12 (e.g., Gen. Jnl.-Post Line in classic NAV/BC naming).
  • Spanish Version
  • Procedure: SendDocToCartera

Current Procedure (for reference)

procedure SendDocToCartera(GenJnlLine3: Record "Gen. Journal Line"; var VendLedgEntry4: Record "Vendor Ledger Entry"; var CustLedgEntry4: Record "Cust. Ledger Entry"; DocType: Option Sale,Purchase; var CVLedgEntryBuf4: Record "CV Ledger Entry Buffer")
var
    PaymentMethod: Record "Payment Method";
begin
    if (not PaymentMethod.Get(GenJnlLine3."Payment Method Code")) or
        (not PaymentMethod."Invoices to Cartera") or
        (GenJnlLine3.Amount = 0) or (CVLedgEntryBuf4."Remaining Amount" = 0)
    then
        exit;
    case GenJnlLine3."Document Type" of
        GenJnlLine3."Document Type"::Invoice:
            begin
                GenJnlLine3.Description :=
                  CopyStr(
                    StrSubstNo(Text1100006, GenJnlLine3."Document No."),
                    1,
                    MaxStrLen(GenJnlLine3.Description));
                GenJnlLine3."Bill No." := '1';
                case DocType of
                    DocType::Purchase:
                        begin
                            DocPost.CreatePayableDoc(GenJnlLine3, CVLedgEntryBuf4, BillFromJournal);
                            VendLedgEntry4."Document Situation" := VendLedgEntry4."Document Situation"::Cartera;
                            VendLedgEntry4."Document Status" := VendLedgEntry4."Document Status"::Open;
                        end;
                    DocType::Sale:
                        begin
                            DocPost.CreateReceivableDoc(GenJnlLine3, CVLedgEntryBuf4, BillFromJournal);
                            CustLedgEntry4."Document Situation" := CustLedgEntry4."Document Situation"::Cartera;
                            CustLedgEntry4."Document Status" := CustLedgEntry4."Document Status"::Open;
                        end;
                end;
            end;
    end;
end;

Proposed Event Signature

Add the following event at the end of SendDocToCartera (after standard processing), using var where partners may need to adjust entries:

[IntegrationEvent(false, false)]
local procedure OnAfterSendDocToCartera(
    var GenJnlLine: Record "Gen. Journal Line";
    var VendLedgEntry: Record "Vendor Ledger Entry";
    var CustLedgEntry: Record "Cust. Ledger Entry";
    DocType: Option Sale,Purchase;
    var CVLedgEntryBuf: Record "CV Ledger Entry Buffer")
begin
end;

Placement

Raise the event as the last statement of the procedure, e.g.:

// ... existing logic

OnAfterSendDocToCartera(GenJnlLine3, VendLedgEntry4, CustLedgEntry4, DocType, CVLedgEntryBuf4);

Rationale

  • Partners need to extend cartera handling to include Credit Memos without modifying base code.
  • An OnAfter... event fits standard extensibility patterns and avoids altering standard behavior.
  • Passing the same records by var provides maximum flexibility (e.g., updating statuses or descriptions).

Backward Compatibility

  • No breaking change: The event is additive.
  • Existing behavior for invoices remains unchanged.
  • Partners can opt in by subscribing to the event.

Acceptance Criteria

  • Event OnAfterSendDocToCartera exists in codeunit 12 and is raised at the end of SendDocToCartera.
  • Event parameters include: GenJnlLine, VendLedgEntry, CustLedgEntry, DocType, CVLedgEntryBuf.
  • Event parameters for records are var to allow adjustments.
  • Standard invoice logic continues to work without regression.

Labels

  • Type: Enhancement
  • Area: Posting / Cartera
  • Extensibility
    Internal work item: AB#616765

Metadata

Metadata

Assignees

No one assigned

    Labels

    FinanceGitHub request for Finance areaevent-requestRequest for adding an event

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions