def assign(): from frappe.desk.form import assign_to assign_to.add({ "assign_to": "*****@*****.**", "doctype": task.doctype, "name": task.name, "description": "Close this task" })
def assign_task_to_users(self, task, users): for user in users: args = { 'assign_to' : user, 'doctype' : task.doctype, 'name' : task.name, 'description' : task.description or task.subject, } assign_to.add(args)
def assign_todo(self): # Creating ToDo for assigned user. if self.assign_to: assign_to = [assign_to.user for assign_to in self.assign_to] add({ 'doctype': self.doctype, "name": self.name, 'assign_to': assign_to })
def on_submit_kanban_dialog(docname, doctype, values): """To update and save kanban card from dialog box !""" values = json.loads(values) doc = frappe.get_doc(doctype, docname) if "assign_to" in values.keys(): assignees = values.pop("assign_to") add({"doctype": doctype, "name": docname, "assign_to": assignees}) doc.update(values) doc.save()
def assign_task_to_users(self, task, users): for user in users: args = { 'assign_to': [user], 'doctype': task.doctype, 'name': task.name, 'description': task.description or task.subject, 'notify': self.notify_users_by_email } assign_to.add(args)
def assign_task_to_owner(name, msg, users): for d in users: args = { 'doctype' : 'Subscription', 'assign_to' : d, 'name' : name, 'description' : msg, 'priority' : 'High' } assign_to.add(args)
def assign_task_to_users(self, task, users): for user in users: args = { "assign_to": [user], "doctype": task.doctype, "name": task.name, "description": task.description or task.subject, "notify": self.notify_users_by_email, } assign_to.add(args)
def assign_task_to_owner(doc, doctype, msg, users): for d in users: from frappe.desk.form import assign_to args = { 'assign_to' : d, 'doctype' : doctype, 'name' : doc, 'description' : msg, 'priority' : 'High' } assign_to.add(args)
def handle_incoming_connect_error(self, description): self.db_set("enable_incoming", 0) for user in get_system_managers(only_name=True): assign_to.add({ 'assign_to': user, 'doctype': self.doctype, 'name': self.name, 'description': description, 'priority': 'High', 'notify': 1 })
def create_duplicate_project(prev_doc, project_name): ''' Create duplicate project based on the old project ''' import json prev_doc = json.loads(prev_doc) if project_name == prev_doc.get('name'): frappe.throw( _("Use a name that is different from previous project name")) # change the copied doc name to new project name project = frappe.copy_doc(prev_doc) project.name = project_name project.project_template = '' project.project_name = project_name project.status = 'Open' project.percent_complete = 0 project.insert() # fetch all the task linked with the old project task_list = frappe.get_all("Task", filters={'project': prev_doc.get('name')}, fields=['name']) # Create duplicate task for all the task new_task_list = [] for task in task_list: task = frappe.get_doc('Task', task) new_task = frappe.copy_doc(task) new_task.project = project.name new_task.parent_task = None new_task.depends_on = None new_task.status = 'Open' new_task.completed_by = '' new_task.progress = 0 new_task.insert() assigned_user = frappe.db.get_value( "ToDo", filters={'reference_name': task.name}, fieldname="owner") if assigned_user: args = { 'doctype': 'Task', 'name': new_task.name, 'assign_to': assigned_user, } add(args) task_dict = { 'previous_task_name': task.name, 'new_task_name': new_task.name, } new_task_list.append(task_dict) handle_task_linking(new_task_list) project.db_set('project_template', prev_doc.get('project_template'))
def assign_tasks(asset_maintenance_name, assign_to_member, maintenance_task, next_due_date): team_member = frappe.db.get_value('User', assign_to_member, "email") args = { 'doctype' : 'Asset Maintenance', 'assign_to' : [team_member], 'name' : asset_maintenance_name, 'description' : maintenance_task, 'date' : next_due_date } if not 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""", args): assign_to.add(args)
def assign_tasks(doctype_name, assign_to_member, task_name,content, next_due_date=None): team_member = frappe.get_doc('User', assign_to_member).email args = { 'doctype' : 'Engine Repair Sheet', 'assign_to' : team_member, 'name' : task_name, 'description' : content, 'date' : next_due_date } if not 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""", args): assign_to.add(args) #client :gergely simon.create a new repair sheet doctype and auto assign
def handle_incoming_connect_error(self, description): self.db_set("enable_incoming", 0) for user in get_system_managers(only_name=True): try: assign_to.add({ 'assign_to': user, 'doctype': self.doctype, 'name': self.name, 'description': description, 'priority': 'High', 'notify': 1 }) except assign_to.DuplicateToDoError: frappe.message_log.pop() pass
def do_assignment(self, doc): # clear existing assignment, to reassign assign_to.clear(doc.get('doctype'), doc.get('name')) user = self.get_user() assign_to.add( dict(assign_to=user, doctype=doc.get('doctype'), name=doc.get('name'), description=frappe.render_template(self.description, doc), assignment_rule=self.name)) # set for reference in round robin self.db_set('last_user', user)
def assign_tasks(asset_maintenance_name, assign_to_member, maintenance_task, next_due_date): team_member = frappe.db.get_value("User", assign_to_member, "email") args = { "doctype": "Asset Maintenance", "assign_to": [team_member], "name": asset_maintenance_name, "description": maintenance_task, "date": next_due_date, } if not 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""", args, ): assign_to.add(args)
def assign_to_user(doc, subject_field): assign_user = None if doc.customer: assign_user = frappe.db.get_value('Customer', doc.customer, 'account_manager') elif doc.lead: assign_user = frappe.db.get_value('Lead', doc.lead, 'lead_owner') if assign_user and assign_user != 'Administrator': if not assign_to.get(dict(doctype=doc.doctype, name=doc.name)): assign_to.add({ "assign_to": assign_user, "doctype": doc.doctype, "name": doc.name, "description": doc.get(subject_field) })
def create_appointment(doc): new_doc = frappe.new_doc("Appointment") new_doc.customer_name = doc['name1'] new_doc.customer_phone_number = doc['mobile_number'] new_doc.doctor = doc['doctor_id'] new_doc.doctor_name = doc['doctor_name'] new_doc.lead = doc['mobile_number'] new_doc.status = "Open" new_doc.customer_details = doc['diseases'] new_doc.scheduled_time = doc['scheduled_date_time'] new_doc.insert() assign_to.add({ "assign_to": doc['doctor_id'], "doctype": "Appointment", "name": new_doc.name })
def create_tasks(self): # Check that at least one item is "Applicable" in checklist table applicable_items = 0 all_required_dates_entered = True for item in self.ecr_checklist: if item.is_applicable == 1: applicable_items += 1 if not item.required_date: all_required_dates_entered = False if applicable_items == 0: frappe.throw( _("Please mark at least one checklist item as applicable")) elif not all_required_dates_entered: frappe.throw( _("Please add a Required Date for all checklist items")) else: tasks_created = 0 for checklist_item in self.ecr_checklist: if not checklist_item.task and checklist_item.is_applicable == 1: # Create task task = frappe.new_doc("Task") task.flags.ignore_permissions = True task.subject = self.name + ": " + checklist_item.description task.project = "ECR Open Item List" task.origin_document_type = "Engineering Change Request" task.origin_document = self.name task.exp_end_date = checklist_item.required_date task.save() task.origin_child_field_reference = str( self.idx) + ": " + checklist_item.description # Assign Task to user (as ToDo) args = { 'doctype': 'Task', 'assign_to': checklist_item.responsible, 'name': task.name, 'description': task.subject, 'date': checklist_item.required_date, 'notify': 1 } assign_to.add(args) checklist_item.task = task.name tasks_created += 1 self.status = "In Progress" frappe.msgprint(str(tasks_created) + " New Tasks Created") self.save()
def create_appointment(self): new_doc=frappe.new_doc("Appointment") new_doc.customer_name=self.lead_name new_doc.customer_phone_number=self.phone new_doc.doctor = self.doctor_id new_doc.doctor_name = self.doctor_name new_doc.lead=self.name new_doc.status="Open" #new_doc.customer_details=self.diseases new_doc.scheduled_time=self.schedule_date new_doc.insert() assign_to.add({ "assign_to": self.doctor_id, "doctype": "Appointment", "name": new_doc.name }) frappe.db.set_value("Lead",self.name,"status", "Appointment Scheduled")
def randomly_assign(docs): from frappe.desk.form.assign_to import add # USAGE # # args = { # "assign_to": , # "doctype": , # "name": , # "description": # } if isinstance(docs, basestring): import json docs = json.loads(docs) from frappe import get_all, bold, _ collector_users = [d.user for d in \ get_all("Case Record Settings User", fields=["user"])] import random random.shuffle(collector_users) length = len(collector_users) idx = 0 from frappe.utils import cint, get_fullname for doctype, name in docs: random.shuffle(collector_users) collector_user = collector_users[cint((idx + length)**length % length)] add({ "assign_to": collector_user, "doctype": doctype, "name": name, "description": _("Randomly assigned by {}" \ .format(bold(get_fullname()))) }) idx += 1
def do_assignment(self, doc): # clear existing assignment, to reassign assign_to.clear(doc.get('doctype'), doc.get('name')) user = self.get_user() assign_to.add( dict(assign_to=[user], doctype=doc.get('doctype'), name=doc.get('name'), description=frappe.render_template(self.description, doc), assignment_rule=self.name, notify=True, date=doc.get(self.due_date_based_on) if self.due_date_based_on else None)) # set for reference in round robin self.db_set('last_user', user)
def handle_incoming_connect_error(self, description): self.db_set("enable_incoming", 0) for user in get_system_managers(only_name=True): try: assign_to.add( { "assign_to": user, "doctype": self.doctype, "name": self.name, "description": description, "priority": "High", "notify": 1, } ) except assign_to.DuplicateToDoError: frappe.message_log.pop() pass
def test_assign(self): from frappe.desk.form.assign_to import add ev = frappe.get_doc(self.test_records[0]).insert() add({ "assign_to": "*****@*****.**", "doctype": "Event", "name": ev.name, "description": "Test Assignment" }) ev = frappe.get_doc("Event", ev.name) self.assertEqual(ev._assign, json.dumps(["*****@*****.**"])) # add another one add({ "assign_to": self.test_user, "doctype": "Event", "name": ev.name, "description": "Test Assignment" }) ev = frappe.get_doc("Event", ev.name) self.assertEqual(set(json.loads(ev._assign)), set(["*****@*****.**", self.test_user])) # close an assignment todo = frappe.get_doc( "ToDo", { "reference_type": ev.doctype, "reference_name": ev.name, "owner": self.test_user }) todo.status = "Closed" todo.save() ev = frappe.get_doc("Event", ev.name) self.assertEqual(ev._assign, json.dumps(["*****@*****.**"])) # cleanup ev.delete()
def assign_warranty_claim(warranty_claim, method): if not frappe.get_all("ToDo", filters={ "reference_type": "Warranty Claim", "reference_name": warranty_claim.name }): repair_settings = frappe.get_doc("Repair Settings") user_emails = [] for notification in repair_settings.notification_settings: if notification.status == warranty_claim.status: if notification.user: user_emails.append(notification.user) if notification.role: user_emails.extend(get_emails_from_role(notification.role)) if notification.cc: notification.cc = notification.cc.replace(",", "\n") user_emails.extend(notification.cc.split("\n")) user_emails = list(set(user_emails)) admin_email = frappe.db.get_value("User", "Administrator", "email") if admin_email in user_emails: user_emails.remove(admin_email) for user in user_emails: assign_to.add({ 'assign_to': user, 'doctype': "Warranty Claim", 'name': warranty_claim.name, 'description': "Service Request {0} just moved to the '{1}' status".format( warranty_claim.name, warranty_claim.status), 'priority': 'Medium', 'notify': 1 })
def copy_from_template(self): ''' Copy tasks from template ''' if self.project_template and not frappe.db.get_all( 'Task', dict(default_project=self.name), limit=1): # has a template, and no loaded tasks, so lets create if not self.expected_start_date: # project starts today self.expected_start_date = today() template = frappe.get_doc('Project Template', self.project_template) if not self.project_type: self.project_type = template.project_type # create tasks from template for task in template.tasks: task_doc = frappe.get_doc( dict(doctype='Task', subject=task.subject, status='Open', exp_start_date=add_days(self.expected_start_date, task.start), exp_end_date=add_days(self.expected_start_date, task.start + task.duration), description=task.description, task_weight=task.task_weight, projects=[dict(is_default=1, project=project_name)])) task_doc.append("projects", { "is_default": 1, "project": self.name }) task_doc.insert() if task.assigned_user: args = { 'doctype': 'Task', 'name': task_doc.name, 'assign_to': [task.assigned_user], } add(args)
def handle_incoming_connect_error(self, description): '''Disable email account if 3 failed attempts found''' if self.get_failed_attempts_count() == 3: self.db_set("enable_incoming", 0) for user in get_system_managers(only_name=True): try: assign_to.add({ 'assign_to': user, 'doctype': self.doctype, 'name': self.name, 'description': description, 'priority': 'High', 'notify': 1 }) except assign_to.DuplicateToDoError: frappe.message_log.pop() pass else: self.set_failed_attempts_count(self.get_failed_attempts_count() + 1)
def on_submit(self): if not self.warehouse: throw(_("Ware house is required!!")) if self.order_source_type == 'Tickets Ticket': doc = frappe.get_doc('Tickets Ticket', self.order_source_id) doc.run_method("on_delivery_order_commit", self) try: assign_to.add({ 'assign_to': self.owner, 'doctype': self.doctype, 'name': self.name, 'description': _("Delivery Order approved!"), 'date': self.planned_date, 'priority': 'High', 'notify': 0 }) except assign_to.DuplicateToDoError: frappe.message_log.pop() pass for item in self.items: if item.serial_no: doc = frappe.get_doc("Stock Serial No", item.serial_no) if not doc: throw( _("Serial NO is not validate! {0}").format( item.serial_no)) if doc.warehouse != self.warehouse: throw( _("Serial NO {0} is not in Warehouse {1} but in {2}"). format(item.serial_no, self.warehouse, doc.warehouse)) doc.warehouse = None doc.save() else: item_type = 'Stock Batch No' item_id = item.batch_no if not item.batch_no: item_type = 'Stock Item' item_id = item.item self.__in_station(item_type, item_id, item.qty)
def test_assign(self): from frappe.desk.form.assign_to import add ev = frappe.get_doc(self.test_records[0]).insert() add({ "assign_to": "*****@*****.**", "doctype": "Event", "name": ev.name, "description": "Test Assignment" }) ev = frappe.get_doc("Event", ev.name) self.assertEqual(ev._assign, json.dumps(["*****@*****.**"])) # add another one add({ "assign_to": self.test_user, "doctype": "Event", "name": ev.name, "description": "Test Assignment" }) ev = frappe.get_doc("Event", ev.name) self.assertEqual(set(json.loads(ev._assign)), set(["*****@*****.**", self.test_user])) # close an assignment todo = frappe.get_doc("ToDo", {"reference_type": ev.doctype, "reference_name": ev.name, "owner": self.test_user}) todo.status = "Closed" todo.save() ev = frappe.get_doc("Event", ev.name) self.assertEqual(ev._assign, json.dumps(["*****@*****.**"])) # cleanup ev.delete()
def handle_incoming_connect_error(self, description): if test_internet(): if self.get_failed_attempts_count() > 2: self.db_set("enable_incoming", 0) for user in get_system_managers(only_name=True): try: assign_to.add({ 'assign_to': user, 'doctype': self.doctype, 'name': self.name, 'description': description, 'priority': 'High', 'notify': 1 }) except assign_to.DuplicateToDoError: frappe.message_log.pop() pass else: self.set_failed_attempts_count(self.get_failed_attempts_count() + 1) else: frappe.cache().set_value("workers:no-internet", True)
def validate(self): self.set_lead_name() self._prev = frappe._dict({ "contact_date": frappe.db.get_value("Lead", self.name, "contact_date") if \ (not cint(self.get("__islocal"))) else None, "ends_on": frappe.db.get_value("Lead", self.name, "ends_on") if \ (not cint(self.get("__islocal"))) else None, "contact_by": frappe.db.get_value("Lead", self.name, "contact_by") if \ (not cint(self.get("__islocal"))) else None, }) # self.set_status() self.check_email_id_is_unique() if self.email_id: if not self.flags.ignore_email_validation: validate_email_address(self.email_id, True) if self.email_id == self.lead_owner: frappe.throw(_("Lead Owner cannot be same as the Lead")) if self.email_id == self.contact_by: frappe.throw(_("Next Contact By cannot be same as the Lead Email Address")) if self.is_new() or not self.image: self.image = has_gravatar(self.email_id) if self.contact_date and getdate(self.contact_date) < getdate(nowdate()): frappe.throw(_("Next Contact Date cannot be in the past")) if (self.ends_on and self.contact_date and (getdate(self.ends_on) < getdate(self.contact_date))): frappe.throw(_("Ends On date cannot be before Next Contact Date.")) if self.contact_by: assign_to.add({ "assign_to": self.contact_by, "doctype": self.doctype, "name": self.name })
def create_demande(doc, method): if (doc.creer_demande_materiel == 1): stock_settings = frappe.get_single('Stock Settings') req = make_material_request(doc.name) req.schedule_date = doc.delivery_date req.material_request_type = "Material Transfer" req.title = _("{0}").format(req.material_request_type) user = stock_settings.compte_assigner_stock req.save() req.title = _("{0}").format(req.material_request_type) doc.demande_associe = req.name for line in doc.items: line.qts_prepares = line.qty doc.save() req.submit() assign_to.add({ "assign_to": user, "doctype": "Material Request", "name": req.name, "description": "Transfert" + " - " + doc.name }) frappe.msgprint("Demande materiel cree !")
def test_notification_to_assignee(self): todo = frappe.new_doc("ToDo") todo.description = "Test Notification" todo.save() assign_to.add({ "assign_to": ["*****@*****.**"], "doctype": todo.doctype, "name": todo.name, "description": "Close this Todo", }) assign_to.add({ "assign_to": ["*****@*****.**"], "doctype": todo.doctype, "name": todo.name, "description": "Close this Todo", }) # change status of todo todo.status = "Closed" todo.save() email_queue = frappe.get_doc("Email Queue", { "reference_doctype": "ToDo", "reference_name": todo.name }) self.assertTrue(email_queue) # check if description is changed after alert since set_property_after_alert is set self.assertEquals(todo.description, "Changed by Notification") recipients = [d.recipient for d in email_queue.recipients] self.assertTrue("*****@*****.**" in recipients) self.assertTrue("*****@*****.**" in recipients)