Skip to content

fix: update parent doc link field when nested Quick Edit Form#1506

Open
the-narwhal wants to merge 1 commit into
frappe:masterfrom
the-narwhal:adding-customer-while-creating-invoice-bug
Open

fix: update parent doc link field when nested Quick Edit Form#1506
the-narwhal wants to merge 1 commit into
frappe:masterfrom
the-narwhal:adding-customer-while-creating-invoice-bug

Conversation

@the-narwhal

@the-narwhal the-narwhal commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

Problem

When creating a new linked record from inside a Quick Edit Form (QEF) — for example, creating an Address while in the middle of creating a Customer on an invoice — the newly-created child record is silently never linked back to the parent.

Likely fixes #1487 too

Steps to reproduce:

  1. Open a new Sales Invoice
  2. Click the Customer field → Create a new customer
  3. Inside the Customer QEF, click the Address field → Create a new address
  4. Fill in and save the address
  5. Save the customer

Result: The customer is saved without the address. No error is shown; the data is silently dropped.


Root Cause

Link.vue (and its siblings DynamicLink.vue, MultiLabelLink.vue) use the following pattern in openNewDoc():

const doc = fyo.doc.getNewDoc(schemaName, { name, ...filters });
openQuickEdit({ doc });

doc.once('afterSync', () => {
  this.$router.back();
  this.results = [];
  this.triggerChange(doc.name);   // relies on `this` being alive
});

openQuickEdit pushes a new route whose query changes the schemaName and name parameters. In Desk.vue the QEF component is keyed on exactly those values:

<component
  :is="Component"
  :key="route.query.schemaName + route.query.name"
/>

When the Address QEF opens, the key changes from "PartyNew Party 01" to "AddressNew Address 01", which destroys the Party QEF — and with it, the Link component whose this is closed over in the listener.

When the address is later saved and afterSync fires, triggerChange calls this.$emit('change', …). Vue 3 returns early from $emit when a component is unmounted (instance.isUnmounted guard), so the event never propagates, parentDoc.set() is never called, and the address field on the Party doc is never updated.


Fix

Capture parentDoc and fieldname before the navigation destroys the component, then directly call parentDoc.set() in the listener as a guaranteed fallback — regardless of whether the Link component is still alive:

const parentDoc = this.doc;
const fieldname = this.df.fieldname;

doc.once('afterSync', () => {
  this.$router.back();
  this.results = [];
  this.triggerChange(doc.name);
  // Directly set on the parent doc to handle the case where this
  // component has been unmounted (nested QEF scenario).
  if (parentDoc && fieldname) {
    parentDoc.set(fieldname, doc.name).catch(() => {});
  }
});

Because the parent doc is wrapped in Vue's reactive(), the recreated QEF instance (which gets the same cached doc object) will reactively reflect the updated field value without any extra wiring.

triggerChange is kept as well so the first-level case (non-nested QEF, where the component is still alive) continues to work exactly as before.


Files Changed

File Change
src/components/Controls/Link.vue Capture parentDoc/fieldname; add direct parentDoc.set() call in afterSync listener
src/components/Controls/DynamicLink.vue Same fix
src/components/Controls/MultiLabelLink.vue Same fix

When a Quick Edit Form (QEF) is opened from within another QEF (e.g.
creating an Address while creating a Party), Desk.vue re-keys the QEF
component on `schemaName + name`, destroying the parent QEF and the
Link component whose `this` reference is captured in the afterSync
listener. Vue 3 silently no-ops $emit on unmounted components, so
triggerChange never reaches the parent doc's set(), leaving the link
field unset (data loss).

Fix by capturing parentDoc and fieldname before navigation and calling
parentDoc.set(fieldname, doc.name) directly in the afterSync listener.
Applies to Link, DynamicLink, and MultiLabelLink controls.

Likely fixes frappe#1487 too
@the-narwhal the-narwhal marked this pull request as ready for review April 5, 2026 01:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 [Bug] - adding customer while creating an invoice throws errors

1 participant