def wechat_notify(bundle=None): from cloud.cloud.doctype.cloud_company.cloud_company import get_wechat_app from cloud.cloud.doctype.cloud_company_group.cloud_company_group import list_users from wechat.api import send_doc # Get all teams for that site teams = [ st[0] for st in frappe.db.get_values("Tickets RegionTeam", { "parent": bundle.tickets_region, "type": bundle.tickets_type }, "team") ] user_list = {} for team in teams: app = get_wechat_app( frappe.db.get_value("Cloud Company Group", team, "company")) if app: if not user_list.has_key(app): user_list[app] = [] for d in list_users(st[0]): user_list[app].append(d.name) for app in user_list: send_doc(app, 'Tickets Ticket Bundle', bundle.name, user_list[app])
def wechat_notify_by_name(err_name, err_doc=None): from cloud.cloud.doctype.cloud_company_group.cloud_company_group import list_users from cloud.cloud.doctype.cloud_company.cloud_company import get_wechat_app err_doc = err_doc or frappe.get_doc("IOT Device Error", err_name) if err_doc.status in ["New", "Open"]: user_list = [] bunch = frappe.db.get_value("IOT Device", err_doc.device, "bunch") if bunch is None: print("No user binded") return bunch_doc = frappe.get_doc("IOT Device Bunch", bunch) if bunch_doc.owner_type == "Cloud Company Group": print("Cloud Company Group", bunch_doc.owner_id) user_list = [d.name for d in list_users(bunch_doc.owner_id)] else: user_list.append(bunch_doc.owner_id) if len(user_list) > 0: app = get_wechat_app(bunch_doc.get_company()) if app: from wechat.api import send_doc send_doc(app, 'IOT Device Error', err_doc.name, user_list)
def wechat_notify_by_ticket_name(ticket_name, ticket_doc=None): ticket_doc = ticket_doc or frappe.get_doc("Tickets Ticket", ticket_name) region = ticket_doc.get_region_address() user_list = {} user_list = get_users_by_region(user_list, region.town, ticket_doc) user_list = get_users_by_region(user_list, region.county, ticket_doc) user_list = get_users_by_region(user_list, region.city, ticket_doc) user_list = get_users_by_region(user_list, region.province, ticket_doc) for app in user_list: #print("Send wechat notify : {0} to users {1} via app {2}".format(task_doc.as_json(), user_list[app], app)) from wechat.api import send_doc send_doc(app, 'Tickets Ticket', ticket_doc.name, user_list[app])