Set Default Cost Center Based On Logged-In User

Hello,

I want to default cost center based on logged-in user. I tried User Permission but unfortunately it didn’t set default value…even-though it listed-out assigned cost center…means user would still need to select cost center.

I tried using custom script, but don’t have idea what is the best way to get cost center value in user permission record.

I tried frappe.defaults.get_user_default(“cost_center”) or frappe.defaults.get_user_default(“Cost Center”) but it’snot working…

What is the best approach to achieve this?

Thanks

@jof2jc user permission should work.

@nabin any reason this should not work?

@rmehta User Permission doesn’t set default value. It’s just filter the records (assigned-values) for each user. The users still have to select proper cost center on transaction form.

In which form user defaults does not come?

In Sales / Purchase Invoice, it sets based on item-wise cost center or from POS Profile. I think we can’t give highest priority to the user defaults.

But, cost center should be set in Journal Entry based on user defaults.

@nabinhait In Sales Invoice. In my opinion user defaults should get highest priority for default value…because it’s related to security permission.

It’s really not ideal if on every transaction form the user has to select cost center manually.

I think for now I have to use custom script.to define cost center for each user. Do you know what client side function to get user defined cost center?

Thanks for help

Currently how it works:

Onloading of the form, set it based on default cost center in company

On change of items, it fetches based on POS Profile / Project / Item / Item Group.

I think we can change onload part, there it should consider user defaults over company default.

@rmehta what do you say?

1 Like

@nabinhait it seems a good work around eventhough I prefer user defaults on top priority to override everything as most ideal solution. It not just for cost center but also for all fields.

Ok, regarding your idea…If we don’t define cost center on item/item group then will user-defaults still get override?

Make sense!

Yes, if you don’t define cost center in item / item group, then system should take user defaults. I will fix that in the upcoming release.

1 Like

@nabinhait, is this fixed already? Thanks

Yes, now it should consider cost center from user properties, if cost center not defined in item / item group / project / pos profile.

any suggestion or solution on the said issue can any one guide.

now in v12 , the cost center is set in POS profile but still its take the default from item
I think pos profile should be the highst priority .

Issue reported here https://github.com/frappe/erpnext/issues/22149

1 Like

I will try my best to uploud pr soon , @clarkej thanks for assign th issue to the topic .
best regards