Skip to content

Commit

Permalink
fix(Sales/js): autofill billing address without division in contractE…
Browse files Browse the repository at this point in the history
…ditDialog
  • Loading branch information
ccheng-dev committed Feb 12, 2025
1 parent c5a6bcd commit 33ae2c4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions tine20/Sales/js/AddressSearchCombo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 33ae2c4

Please sign in to comment.