ERPNext CRM categorisation

Hi All,
Hope you all are doing good. I wanted to perform the below in ERPNext CRM, if anyone could assist-
1.Ability to add leads under a specific department
2.Unless given exclusive permission, a user should see only leads specific to his/her departments and not other departments leads
3.Show list the tasks that are to be done for a given department lead

Hi @Sai_Swadesh Welcome to ERPNext

To do this you can add Department field on Lead form (Link type with Department in the Options to link it to Department[existing Doctype])

Give Permissions to Users to respective Departments through User Permissions Doctype and if you want to share leads with people who do not belong to that Department, you can Share the Lead from Left side of the Form
Reference to documentation

Use Report Builder for simple reports or Build custom Query/Script report for special needs

add custom field department to doctype Lead via either customize form

Assign department in lead by authorized user

add the highlighted lines to your custom app’s hooks.py file

also add the following function codes into relevant py file, e.g api.py under the module folder of the custom app

here the code for copy and adapt.

from __future__ import unicode_literals

import frappe

def get_permission_query_conditions(user):

    if not user: user = frappe.session.user

    roles = [r for r in frappe.get_roles() if r in ['Sales Manager','System Manager']]

    if roles:

        return ""

    else:    

        return """(department = (select department from `tabEmployee` where user_id=%(user)s limit 1)

                or owner=%(user)s)""" % {

            "user": frappe.db.escape(user),

        }

def has_permission(doc, user):

    if not user: user = frappe.session.user

    roles = [r for r in frappe.get_roles() if r in ['Sales Manager','System Manager']]

    department = frappe.db.get_value('Employee',{'user_id': user}, 'department')    

    if roles or doc.owner==user or doc.department==department:

        return True

    return False

to be clarified further.

here the similar post for reference Hook has_permission + permission function on docType - #11 by szufisher

Thanks, @Manan_Shah! can you please elaborate the process that needs to be done for adding a field

I am a complete functional guy, if you could assist me with this. That would be very resourceful

You can refer this video ERPNext Simple Customisations - YouTube
and this documentation Creating Custom Link Field

You could use the Territory feature. Assign all the people in one department to a certain Territory and the other people to another Territory. And then use User Permissions to restrict a department to it’s Territory.

Hope this helps.

Thanks

Jay