From 33ae2c4c0d0ef2c75399a96b8bf087e684029ef6 Mon Sep 17 00:00:00 2001 From: ccheng Date: Wed, 5 Feb 2025 05:04:05 +0100 Subject: [PATCH] fix(Sales/js): autofill billing address without division in contractEditDialog --- tine20/Sales/js/AddressSearchCombo.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tine20/Sales/js/AddressSearchCombo.js b/tine20/Sales/js/AddressSearchCombo.js index bcc83955417..342a5b9c065 100644 --- a/tine20/Sales/js/AddressSearchCombo.js +++ b/tine20/Sales/js/AddressSearchCombo.js @@ -41,9 +41,10 @@ Tine.Sales.AddressSearchCombo = Ext.extend(Tine.Tinebase.widgets.form.RecordPick this.on('beforeselect', async (field, adr, idx) => { if (adr.get('type') === 'postal') { const form = this.findParentBy((c) => {return c instanceof Ext.form.FormPanel}).getForm(); - const category = form.findField('document_category').selectedRecord; + const category = form.findField('document_category')?.selectedRecord; const division = category?.data?.division_id; - const selectedCustomer = form.findField('customer_id').selectedRecord; + const selectedCustomer = form.findField('customer_id')?.selectedRecord; + if (!selectedCustomer) return; const customer = selectedCustomer.json?.original_id ? await Tine.Sales.getCustomer(selectedCustomer.json.original_id) : selectedCustomer.data; const debitors = _.filter(customer.debitors, (deb) => { return _.get(deb, 'division_id.id', deb) === division?.id}); if (debitors) { @@ -108,6 +109,13 @@ Tine.Sales.AddressSearchCombo = Ext.extend(Tine.Tinebase.widgets.form.RecordPick // in orders debitor of 'delivery', 'billing' should match receipient? // in all documents debitor should match precursor receipient? typeRecord = typeRecords[0]; + + if (!typeRecord && !division) { + const addrs = _.flatten(_.map(_.cloneDeep(customer.data.debitors), (debitor) => { + return debitor['billing']; + })); + typeRecord = addrs[0]; + } } if (typeRecord && !this.isExplicitlyCleared) { const address = Tine.Tinebase.data.Record.setFromJson(typeRecord, this.recordClass);