[Bug][SubscriptionBilling] Usage Data Generic Import OnModify assigns wrong Customer ID and never fills Customer Name

Aperta Adatta ai principianti
#14,443 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
74/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Ambito
backend

Direzione di ricerca

Apri UsageDataGenericImport.Table.al in src/Apps/W1/Subscription Billing/App/Usage Based Billing/Tables/ e leggi OnModify, InitRecord e il trigger OnValidate di Customer ID; l'attuale FindFirst su "Usage Data Supp. Customer" filtra solo per Supplier No.. Poi controlla UsageDataSuppCustomer.Table.al, dove "Customer Name" è un FlowField, e nota che CreateUsageDataCustomers in GenericConnectorProcessing.Codeunit.al chiama TestField("Customer ID"). Fatto significa che un Customer ID vuoto sopravvive a una modifica invariato, e che un Customer Name viene compilato dal record che corrisponde a Supplier Reference = il Customer ID della riga, verificato tramite i passaggi di riproduzione nella pagina Usage Data Generic Import.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Approved Team: Finance
Describe the issue

When imported generic usage data lines are changed afterwards, the system can silently attach a line to the wrong customer.

If a line was imported without a customer identifier, any later change to that line (for example, correcting the quantity on the imported lines page) fills in the identifier of the first customer set up for that usage data supplier. That customer has nothing to do with the line. No message is shown. If the supplier is set up to create customers automatically, processing the imported lines then creates and processes usage data for that wrong customer, and the usage ends up billed to the wrong customer.

The customer name on imported lines is never filled either. A changed line gets the name of the same unrelated first customer instead of the customer it belongs to. When the identifier is entered or changed, the name stays empty even if a matching customer is set up.

This happens every time a line is saved with triggers, both on a user edit in the page and when an extension modifies the line with triggers.

Affected objects:

  • src/Apps/W1/Subscription Billing/App/Usage Based Billing/Tables/UsageDataGenericImport.Table.al
Expected behavior

1 — Empty Customer ID must stay empty on modify

An empty Customer ID must not be filled by OnModify. It should stay empty, so that Process Imported Lines reports the missing customer. With "Create Customers" enabled, CreateUsageDataCustomers in GenericConnectorProcessing.Codeunit.al already runs TestField("Customer ID") for this.

Where it breaks: OnModify (L322) calls InitRecord (L334). InitRecord filters table 8012 "Usage Data Supp. Customer" only by "Supplier No." and takes the first record (L346):

if ("Customer ID" = '') or ("Customer Name" = '') then begin
    UsageDataCustomer.Reset();
    UsageDataCustomer.SetRange("Supplier No.", UsageDataSupplier."No.");
    if UsageDataCustomer.FindFirst() then begin
        if "Customer ID" = '' then
            "Customer ID" := UsageDataCustomer."Supplier Reference";
        if "Customer Name" = '' then
            "Customer Name" := UsageDataCustomer."Customer Name";
    end;
end;
  • An empty "Customer ID" gets the "Supplier Reference" of the supplier's first usage data customer.
  • An empty "Customer Name" is taken from that same first record, not from the record whose "Supplier Reference" equals the line's "Customer ID".

2 — Customer Name must be filled from the matching usage data customer

"Customer Name" should come from the "Usage Data Supp. Customer" record with "Supplier No." = the import's supplier and "Supplier Reference" = the line's "Customer ID". This applies in both InitRecord and OnValidate of "Customer ID".

Where it breaks: "Customer Name" (field 5) in UsageDataSuppCustomer.Table.al is a FlowField. Neither InitRecord nor OnValidate of "Customer ID" (L90) calculates it, so the value copied is always empty.

Proposed fix

InitRecord exits when "Customer ID" is empty or "Customer Name" is already filled; otherwise it filters "Usage Data Supp. Customer" by "Supplier No." and "Supplier Reference" = "Customer ID", uses SetAutoCalcFields("Customer Name") and copies the name. OnValidate of "Customer ID" gets SetAutoCalcFields("Customer Name") before its FindFirst().

Steps to reproduce
  1. Open Usage Data Suppliers and create supplier GENERIC with Type = Generic.
  2. Open Generic Import Settings for GENERIC and leave Create Customers turned off.
  3. Open Usage Data Customers for GENERIC and create two entries:
    • Supplier Reference CUST-A → Customer No. 10000
    • Supplier Reference CUST-B → Customer No. 20000
  4. Create a usage data import for GENERIC and import a file with two lines:
    • Line 1: Customer ID empty, Quantity 5
    • Line 2: Customer ID CUST-B, Customer Name empty, Quantity 5
  5. Open the Usage Data Generic Import page for the import.
  6. Change Quantity on line 1 to 6.
    → Expected: Customer ID stays empty. Actual: Customer ID = CUST-A.
  7. Change Quantity on line 2 to 6.
    → Expected: Customer Name = name of customer 20000. Actual: Customer Name stays empty.
Additional context

Reproduced on BC 29.1 and earlier versions, and on current main.

Workaround: assign Customer ID / Customer Name directly and save with Modify(false), and do not edit lines with an empty Customer ID on the page.

I will provide a fix for a bug
  • I will provide a fix for a bug
Lingua principale
AL
Stelle
730
Fork
514
Merge medio
2g 23h
PR unite (30g)
601

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/BCApps

Tutte le issue di microsoft/BCApps

Issue simili

Altre issue su Backend & API Design

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.