@@ -3,8 +3,10 @@ import { routeFilters } from 'src/utils/filters';
33import { fyo } from '../initFyo' ;
44import { SidebarConfig , SidebarItem , SidebarRoot } from './types' ;
55
6- export async function getSidebarConfig ( ) : Promise < SidebarConfig > {
7- const sideBar = await getCompleteSidebar ( ) ;
6+ export async function getSidebarConfig (
7+ accountingSettings ?: typeof fyo . singles . AccountingSettings // Accept AccountingSettings here
8+ ) : Promise < SidebarConfig > {
9+ const sideBar = await getCompleteSidebar ( accountingSettings ) ;
810 return getFilteredSidebar ( sideBar ) ;
911}
1012
@@ -33,7 +35,7 @@ function getFilteredSidebar(sideBar: SidebarConfig): SidebarConfig {
3335}
3436
3537async function getRegionalSidebar (
36- accountingSettings : typeof fyo . singles . AccountingSettings
38+ accountingSettings ? : typeof fyo . singles . AccountingSettings // Use passed settings
3739) : Promise < SidebarRoot [ ] > {
3840 const hasGstin = ! ! accountingSettings ?. gstin ;
3941 if ( ! hasGstin ) {
@@ -63,7 +65,7 @@ async function getRegionalSidebar(
6365}
6466
6567async function getInventorySidebar (
66- accountingSettings : typeof fyo . singles . AccountingSettings
68+ accountingSettings ? : typeof fyo . singles . AccountingSettings // Use passed settings
6769) : Promise < SidebarRoot [ ] > {
6870 const hasInventory = ! ! accountingSettings ?. enableInventory ;
6971 if ( ! hasInventory ) {
@@ -154,19 +156,24 @@ function getReportSidebar(): SidebarRoot {
154156 } ;
155157}
156158
157- async function getCompleteSidebar ( ) : Promise < SidebarConfig > {
158- // Explicitly load singletons to ensure the latest values are used
159- const accountingSettings = ( await fyo . doc . getDoc (
160- 'AccountingSettings'
161- ) ) as typeof fyo . singles . AccountingSettings ;
159+ async function getCompleteSidebar (
160+ initialAccountingSettings ?: typeof fyo . singles . AccountingSettings
161+ ) : Promise < SidebarConfig > {
162+ // Use the passed settings or explicitly load singletons if not provided
163+ const accountingSettings =
164+ initialAccountingSettings ||
165+ ( ( await fyo . doc . getDoc (
166+ 'AccountingSettings'
167+ ) ) as typeof fyo . singles . AccountingSettings ) ;
168+
162169 const systemSettings = ( await fyo . doc . getDoc (
163170 'SystemSettings'
164171 ) ) as typeof fyo . singles . SystemSettings ;
165172 const inventorySettings = ( await fyo . doc . getDoc (
166173 'InventorySettings'
167174 ) ) as typeof fyo . singles . InventorySettings ;
168175
169- // Pre-compute project visibility for clarity
176+ // Pre-compute project visibility for clarity using the consistent accountingSettings instance
170177 const hideProjects = ! accountingSettings ?. enableProjects ;
171178
172179 return [
@@ -332,9 +339,9 @@ async function getCompleteSidebar(): Promise<SidebarConfig> {
332339 ] as SidebarItem [ ] ,
333340 } ,
334341 getReportSidebar ( ) ,
335- ...( await getInventorySidebar ( accountingSettings ) ) , // Await and spread result
336- ( await getPOSSidebar ( inventorySettings ) ) , // Await for POS sidebar
337- ...( await getRegionalSidebar ( accountingSettings ) ) , // Await and spread result
342+ ...( await getInventorySidebar ( accountingSettings ) ) ,
343+ await getPOSSidebar ( inventorySettings ) ,
344+ ...( await getRegionalSidebar ( accountingSettings ) ) ,
338345 {
339346 label : t `Setup` ,
340347 name : 'setup' ,
0 commit comments