@@ -27,13 +27,10 @@ import type {
2727 ConnectionName ,
2828 Connections ,
2929 CustomUnit ,
30- InvoiceItem ,
3130 NetSuiteAccount ,
3231 NetSuiteConnection ,
3332 NetSuiteCustomList ,
3433 NetSuiteCustomSegment ,
35- NetSuiteTaxAccount ,
36- NetSuiteVendor ,
3734 PolicyConnectionSyncProgress ,
3835 PolicyFeatureName ,
3936 Rate ,
@@ -1490,89 +1487,59 @@ function settingsPendingAction(settings?: string[], pendingFields?: PendingField
14901487 return pendingFields [ key ] ;
14911488}
14921489
1493- function findSelectedVendorWithDefaultSelect ( vendors : NetSuiteVendor [ ] | undefined , selectedVendorId : string | undefined ) {
1494- const selectedVendor = ( vendors ?? [ ] ) . find ( ( { id} ) => id === selectedVendorId ) ;
1495- return selectedVendor ?? vendors ?. [ 0 ] ?? undefined ;
1496- }
1497-
1498- function findSelectedBankAccountWithDefaultSelect ( accounts : NetSuiteAccount [ ] | undefined , selectedBankAccountId : string | undefined ) {
1499- const selectedBankAccount = ( accounts ?? [ ] ) . find ( ( { id} ) => id === selectedBankAccountId ) ;
1500- return selectedBankAccount ?? accounts ?. [ 0 ] ?? undefined ;
1501- }
1502-
1503- function findSelectedInvoiceItemWithDefaultSelect ( invoiceItems : InvoiceItem [ ] | undefined , selectedItemId : string | undefined ) {
1504- const selectedInvoiceItem = ( invoiceItems ?? [ ] ) . find ( ( { id} ) => id === selectedItemId ) ;
1505- return selectedInvoiceItem ?? invoiceItems ?. [ 0 ] ?? undefined ;
1506- }
1507-
1508- function findSelectedTaxAccountWithDefaultSelect ( taxAccounts : NetSuiteTaxAccount [ ] | undefined , selectedAccountId : string | undefined ) {
1509- const selectedTaxAccount = ( taxAccounts ?? [ ] ) . find ( ( { externalID} ) => externalID === selectedAccountId ) ;
1510- return selectedTaxAccount ?? taxAccounts ?. [ 0 ] ?? undefined ;
1511- }
1512-
15131490function getNetSuiteVendorOptions ( policy : Policy | undefined , selectedVendorId : string | undefined ) : SelectorType [ ] {
15141491 const vendors = policy ?. connections ?. netsuite ?. options . data . vendors ;
15151492
1516- const selectedVendor = findSelectedVendorWithDefaultSelect ( vendors , selectedVendorId ) ;
1517-
15181493 return ( vendors ?? [ ] ) . map ( ( { id, name} ) => ( {
15191494 value : id ,
15201495 text : name ,
15211496 keyForList : id ,
1522- isSelected : selectedVendor ?. id === id ,
1497+ isSelected : id === selectedVendorId ,
15231498 } ) ) ;
15241499}
15251500
15261501function getNetSuitePayableAccountOptions ( policy : Policy | undefined , selectedBankAccountId : string | undefined ) : SelectorType [ ] {
15271502 const payableAccounts = policy ?. connections ?. netsuite ?. options . data . payableList ;
15281503
1529- const selectedPayableAccount = findSelectedBankAccountWithDefaultSelect ( payableAccounts , selectedBankAccountId ) ;
1530-
15311504 return ( payableAccounts ?? [ ] ) . map ( ( { id, name} ) => ( {
15321505 value : id ,
15331506 text : name ,
15341507 keyForList : id ,
1535- isSelected : selectedPayableAccount ?. id === id ,
1508+ isSelected : id === selectedBankAccountId ,
15361509 } ) ) ;
15371510}
15381511
15391512function getNetSuiteReceivableAccountOptions ( policy : Policy | undefined , selectedBankAccountId : string | undefined ) : SelectorType [ ] {
15401513 const receivableAccounts = policy ?. connections ?. netsuite ?. options . data . receivableList ;
15411514
1542- const selectedReceivableAccount = findSelectedBankAccountWithDefaultSelect ( receivableAccounts , selectedBankAccountId ) ;
1543-
15441515 return ( receivableAccounts ?? [ ] ) . map ( ( { id, name} ) => ( {
15451516 value : id ,
15461517 text : name ,
15471518 keyForList : id ,
1548- isSelected : selectedReceivableAccount ?. id === id ,
1519+ isSelected : id === selectedBankAccountId ,
15491520 } ) ) ;
15501521}
15511522
15521523function getNetSuiteInvoiceItemOptions ( policy : Policy | undefined , selectedItemId : string | undefined ) : SelectorType [ ] {
15531524 const invoiceItems = policy ?. connections ?. netsuite ?. options . data . items ;
15541525
1555- const selectedInvoiceItem = findSelectedInvoiceItemWithDefaultSelect ( invoiceItems , selectedItemId ) ;
1556-
15571526 return ( invoiceItems ?? [ ] ) . map ( ( { id, name} ) => ( {
15581527 value : id ,
15591528 text : name ,
15601529 keyForList : id ,
1561- isSelected : selectedInvoiceItem ?. id === id ,
1530+ isSelected : id === selectedItemId ,
15621531 } ) ) ;
15631532}
15641533
15651534function getNetSuiteTaxAccountOptions ( policy : Policy | undefined , subsidiaryCountry ?: string , selectedAccountId ?: string ) : SelectorType [ ] {
15661535 const taxAccounts = policy ?. connections ?. netsuite ?. options . data . taxAccountsList ;
15671536 const accountOptions = ( taxAccounts ?? [ ] ) . filter ( ( { country} ) => country === subsidiaryCountry ) ;
15681537
1569- const selectedTaxAccount = findSelectedTaxAccountWithDefaultSelect ( accountOptions , selectedAccountId ) ;
1570-
15711538 return accountOptions . map ( ( { externalID, name} ) => ( {
15721539 value : externalID ,
15731540 text : name ,
15741541 keyForList : externalID ,
1575- isSelected : selectedTaxAccount ?. externalID === externalID ,
1542+ isSelected : externalID === selectedAccountId ,
15761543 } ) ) ;
15771544}
15781545
@@ -1592,13 +1559,11 @@ function getNetSuiteReimbursableAccountOptions(policy: Policy | undefined, selec
15921559 const payableAccounts = policy ?. connections ?. netsuite ?. options . data . payableList ;
15931560 const accountOptions = getFilteredReimbursableAccountOptions ( payableAccounts ) ;
15941561
1595- const selectedPayableAccount = findSelectedBankAccountWithDefaultSelect ( accountOptions , selectedBankAccountId ) ;
1596-
15971562 return accountOptions . map ( ( { id, name} ) => ( {
15981563 value : id ,
15991564 text : name ,
16001565 keyForList : id ,
1601- isSelected : selectedPayableAccount ?. id === id ,
1566+ isSelected : id === selectedBankAccountId ,
16021567 } ) ) ;
16031568}
16041569
@@ -1610,13 +1575,11 @@ function getNetSuiteCollectionAccountOptions(policy: Policy | undefined, selecte
16101575 const payableAccounts = policy ?. connections ?. netsuite ?. options . data . payableList ;
16111576 const accountOptions = getFilteredCollectionAccountOptions ( payableAccounts ) ;
16121577
1613- const selectedPayableAccount = findSelectedBankAccountWithDefaultSelect ( accountOptions , selectedBankAccountId ) ;
1614-
16151578 return accountOptions . map ( ( { id, name} ) => ( {
16161579 value : id ,
16171580 text : name ,
16181581 keyForList : id ,
1619- isSelected : selectedPayableAccount ?. id === id ,
1582+ isSelected : id === selectedBankAccountId ,
16201583 } ) ) ;
16211584}
16221585
@@ -1633,13 +1596,14 @@ function getNetSuiteApprovalAccountOptions(policy: Policy | undefined, selectedB
16331596 } ;
16341597 const accountOptions = getFilteredApprovalAccountOptions ( [ defaultApprovalAccount ] . concat ( payableAccounts ?? [ ] ) ) ;
16351598
1636- const selectedPayableAccount = findSelectedBankAccountWithDefaultSelect ( accountOptions , selectedBankAccountId ) ;
1599+ // When nothing is explicitly set, the synthesized default approval account is the effective selection in NetSuite.
1600+ const effectiveSelectionId = selectedBankAccountId ?? CONST . NETSUITE_APPROVAL_ACCOUNT_DEFAULT ;
16371601
16381602 return accountOptions . map ( ( { id, name} ) => ( {
16391603 value : id ,
16401604 text : name ,
16411605 keyForList : id ,
1642- isSelected : selectedPayableAccount ?. id === id ,
1606+ isSelected : id === effectiveSelectionId ,
16431607 } ) ) ;
16441608}
16451609
@@ -2297,10 +2261,6 @@ export {
22972261 findCurrentXeroOrganization ,
22982262 getCurrentXeroOrganizationName ,
22992263 getXeroBankAccounts ,
2300- findSelectedVendorWithDefaultSelect ,
2301- findSelectedBankAccountWithDefaultSelect ,
2302- findSelectedInvoiceItemWithDefaultSelect ,
2303- findSelectedTaxAccountWithDefaultSelect ,
23042264 hasPolicyWithXeroConnection ,
23052265 getNetSuiteVendorOptions ,
23062266 canUseTaxNetSuite ,
0 commit comments