[Solved] ERPNext change self.owner while saving a doctype

Hi all,
Can anybody tell me how to change owner field of any doctype with any other user while creating a doctype?

thanks

Any specific doctype you have in mind?

For example I’ve changed the customer associated with Quotation by setting the “customer” field to the desired Customer.name value.

Or do you mean owner as in permissions?

:smiley: I just realized you meant the ‘owner’ field of a doctype.

I don’t believe you can set it at creation time as ‘frappe.session.user’ is hardcoded to be set as the owner.

Have you tried creating the record, saving it, then edit the owner field then save again?

Owner is a current session user and should not be altered.
Just a thought, it seems ethically also wrong to create a record with someone else name. :stuck_out_tongue_winking_eye:

Hello @KanchanChauhan
Yes, I am agree with you…
But I need to show for example, customer’s Sales Order to their assigned supplier’s.
ie. Whenever a Supplier logins, he should see / only see his customer’s Sales Order, not other Supplier’s customers.

My scenario is,
Each registered customer’s in the system has a supplier assigned by the Administrator.
More specifically, a supplier has one or more customers assigned for him.
But a customer has only one supplier.
Whenever a customer place a sales order through cart, the sales order is dynamically assigned to his Supplier. So when a supplier logins to the system, he should see his customer’s sales order not other customer’s sales order.

If i use permissions by setting ‘If Owner’, the database must be changed like that. I realised that if Owner field of Sales Order is customer is changed to Supplier’s name, I get only sales order meant to that Supplier.

Is any other way to implement this?
OR how can one change the owner field of ‘Sales order’ like documents.?

Any help
Thanks

@Felipe_Orellana @KanchanChauhan

Thanks for the reply…

I found a solution to this…

we cannot change owner field of a doctype on submit…
But I could do it on_update() function like,

on_update(self):
** self.owner = desired_user**

Thanks all

2 Likes