Skip to content

Commit

Permalink
fix: fix payload and display of dynamic fields in xero clone settings (
Browse files Browse the repository at this point in the history
…#1074)

Problem: Dynamic fields that use destination attributes were unusable in Xero clone settings

Cause: Export settings and clone settings use different formats to store destination attributes. However, the same methods were used to ingest data and build the payload

Solution: Patch the values in clone settings - while setting the default form values and while building the payload
  • Loading branch information
1 parent 5fcb07e commit c7a822f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ export class XeroCloneSettingModel {
const importSettingPayload = XeroImportSettingModel.constructPayload(importSettingForm);
const advancedSettingPayload = XeroAdvancedSettingModel.constructPayload(advancedSettingForm);

// Set the bank_account in the payload to the selected field value without formatting it
// Since we format them on component init (clone settings only)
exportSettingPayload.general_mappings.bank_account = exportSettingForm.get('bankAccount')?.value;
importSettingPayload.general_mappings.default_tax_code = importSettingForm.get('defaultTaxCode')?.value;
advancedSettingPayload.general_mappings.payment_account = advancedSettingForm.get('billPaymentAccount')?.value;

if (!isTaxGroupSyncAllowed) {
importSettingPayload.workspace_general_settings.import_tax_codes = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,20 @@ export class XeroCloneSettingsComponent implements OnInit {
this.advancedSettingForm = XeroAdvancedSettingModel.mapAPIResponseToFormGroup(this.cloneSetting.advanced_settings, this.adminEmails, destinationAttributes.BANK_ACCOUNT);
this.setupAdvancedSettingFormWatcher();

// Convert field values from destination attributes to *default* destination attributes
const controls = [
this.exportSettingForm.get('bankAccount'),
this.importSettingForm.get('defaultTaxCode'),
this.advancedSettingForm.get('billPaymentAccount')
];

for (const control of controls) {
const fullDestinationAttribute: DestinationAttribute | null = control?.value;
control?.setValue(
fullDestinationAttribute && ExportSettingModel.formatGeneralMappingPayload(fullDestinationAttribute)
);
}

this.isLoading = false;
});
}
Expand Down

0 comments on commit c7a822f

Please sign in to comment.