def lead_quote_share(lead_doc): check_sys = 0 emp_stat = frappe.get_value("User", lead_doc.lead_owner, "enabled") quote_dict = frappe.db.sql("""SELECT name FROM `tabQuotation` WHERE lead = '%s' AND customer IS NULL""" %(lead_doc.name), as_dict=1) if quote_dict: for quote in quote_dict: quote_doc = frappe.get_doc("Quotation", quote.name) if quote_doc.owner != lead_doc.lead_owner: #Create Share for Quote role_list = get_user_roles(lead_doc.lead_owner) check_sys = check_system_manager(user=lead_doc.lead_owner) else: role_list = [] if check_sys != 1 and emp_stat == 1 and role_list: role_in_settings, write_access,share_access, notify_by_email = \ check_role_usershare(role_list=role_list, doctype=quote_doc.doctype) if role_in_settings: shared_dict = get_shared(document_type=quote_doc.doctype, document_name=quote_doc.name) user_in_shared_dict = 0 if shared_dict: for shared_doc in shared_dict: if shared_doc.user != lead_doc.lead_owner: remove(quote_doc.doctype, quote_doc.name, shared_doc.user) else: user_in_shared_dict = 1 if user_in_shared_dict != 1: add(quote_doc.doctype, quote_doc.name, user=lead_doc.lead_owner, write=write_access, \ share=share_access, notify=notify_by_email)
def lead_address_share(lead_doc): check_sys = 0 emp_stat = frappe.get_value("User", lead_doc.lead_owner, "enabled") add_dict = frappe.db.sql("""SELECT parent FROM `tabDynamic Link` WHERE parenttype = 'Address' AND link_doctype = '%s' AND link_name = '%s'""" %(lead_doc.doctype, lead_doc.name), as_dict=1) if add_dict: for address in add_dict: add_doc = frappe.get_doc("Address", address.parent) if add_doc.owner != lead_doc.lead_owner: #Create Share for Quote role_list = get_user_roles(lead_doc.lead_owner) check_sys = check_system_manager(user=lead_doc.lead_owner) else: role_list = [] if check_sys != 1 and emp_stat == 1 and role_list: role_in_settings, write_access,share_access, notify_by_email = \ check_role_usershare(role_list=role_list, doctype=add_doc.doctype) if role_in_settings: shared_dict = get_shared(document_type=add_doc.doctype, document_name=add_doc.name) user_in_shared_dict = 0 if shared_dict: for shared_doc in shared_dict: if shared_doc.user != lead_doc.lead_owner: remove(add_doc.doctype, add_doc.name, shared_doc.user) else: user_in_shared_dict = 1 if user_in_shared_dict != 1: add(add_doc.doctype, add_doc.name, user=lead_doc.lead_owner, write=write_access, \ share=share_access, notify=notify_by_email)
def post(user, doctype, names): names = json.loads(names) users = json.loads(user) for x in users: if x[1] == 1: for name in names: add(doctype, name, user=x[0], read=1, write=1, share=0, everyone=0, flags=None, notify=0) return users
def share_file_with_customer_user(file, user, notify=0): share.add("File", file, user=user, read=1, write=0, share=0, everyone=0, flags=None, notify=notify) share_all_children(file, user)
def add_shaerd_with(self): from frappe.share import add if self.transaction_to: add( doctype = 'Administrative Communications', name = self.name, user = self.transaction_to, read = 1, write = 1, share = 1, )
def on_submit(self): frappe.get_doc("Administrative Transaction", self.administrative_transaction).set_status( update=True, status='Pending') from frappe.share import add if self.assigned_to_user: add(self.doctype, self.name, self.assigned_to_user, 1, 1, 1, 0) if self.assignment_transaction_cc: for atc in self.assignment_transaction_cc: if atc.employee_email: add(self.doctype, self.name, atc.employee_email, 1, 0, 0, 0)
def share_file_with_customer_user_top(file, user, notify=0): if user == None: return #frappe.errprint("sharing %s with %s from share_file_with_customer_user_top" % (file, user)) share.add("File", file, user=user, read=1, write=0, share=0, everyone=0, flags=None, notify=notify)
def share_all_children(file, user): children = frappe.db.sql( "select name from `tabFile` where is_folder = 0 and folder = '%s'" % file, as_list=1) frappe.errprint(children) for child in children: share.add("File", child[0], user=user, read=1, write=0, share=0, everyone=0, flags=None, notify=0)
def assign_to_user(self): if not self.is_new(): from frappe.desk.form.assign_to import add if self.assign_to == 1: if frappe.db.sql("""SELECT `owner` FROM `tabToDo` WHERE `reference_type`=%(doctype)s AND `reference_name`=%(name)s AND `status`='Open' AND `owner`=%(assign_to)s""", { "assign_to": self.transaction_to, "doctype": "Administrative Communications", "name": self.name }): frappe.msgprint(_("This Assignment Already in user's To Do list")) else: add({ "assign_to": self.transaction_to, "doctype": "Administrative Communications", "name": self.name, "description": self.subject })
def lead_docshare(lead_doc): check_sys = 0 emp_stat = frappe.get_value("User", lead_doc.lead_owner, "enabled") if lead_doc.owner != lead_doc.lead_owner: role_list = get_user_roles(lead_doc.lead_owner) check_sys = check_system_manager(user=lead_doc.lead_owner) else: role_list = [] if check_sys != 1 and emp_stat == 1 and role_list: role_in_settings, write_access,share_access, notify_by_email = \ check_role_usershare(role_list=role_list, doctype=lead_doc.doctype) if role_in_settings: shared_dict = get_shared(document_type=lead_doc.doctype, document_name=lead_doc.name) user_in_shared_dict = 0 if shared_dict: for shared_doc in shared_dict: if shared_doc.user != lead_doc.lead_owner: remove(lead_doc.doctype, lead_doc.name, shared_doc.user) else: user_in_shared_dict = 1 if user_in_shared_dict != 1: add(lead_doc.doctype, lead_doc.name, user=lead_doc.lead_owner, write=write_access, \ share=share_access, notify=notify_by_email)
def share_user(self): from frappe.share import add for member in self.members: if member.user: add(self.doctype, self.name, member.user, 1, 1, 0, 0)
def share_with_self(doctype, docname, owner): share.add(doctype=doctype, name=docname, user=owner, read=1, write=1) frappe.db.commit()