Need help in customizing invoices

Hello everyone
I would like to customize my invoices to have the sales person name (basically the user that created the invoice) and their pre-saved signature.

So first of all I would create a new “image” field in the employee doctype to store the employee’s signature (rather than having a signature field where they have to sign on every invoice creation)

Then I would customize the SINV doctype to have a field where it stores the employee name that created the invoice and signature (both read-only)

Then I would have to modify the print view to include those fields where I would have the signature and employee name under.

My question is regarding the second point, how would I make erpnext get the employee name and their signature?

Thanks for any assistance

@Yamen_Zakhour , Please find this post.

1 Like

Every doctype in erpnext has the record of the owner (the user who created the document). So basically you will need a custom signature field only in the User doctype to upload the signature of the employee user.

In the print format, you can fetch the user by {{doc.owner}} and get the signature field by {{frappe.get_doc("User", doc.owner).signature}}.

1 Like

The user doctype can’t be modified, if I added their signature field to the employee doctype I should change it to {{frappe.get_doc("Employee", doc.owner).signature}} … will this work?

Not quite. The primary key of 'User' is not the same primary key as 'Employee’.

For example, you could have this:

You will need a “helper” function that takes you from User ID to Employee document:

def get_employee_by_user_id(user_id: str):

    employee_key = frappe.db.exists({
        'doctype': 'Employee',
        'user_id': user_id})
	if employee_key:
		doc_employee = frappe.get_doc('Employee', employee_key[0][0])
        return doc_employee
	return None

Now your Jina would be this:

{{ get_employee_by_user_id(doc.owner).signature }} 
1 Like

Appreciate your help! Thanks