def get_top_field_tags(dt): from webnotes.model.doctype import get_property tf = get_property(dt, 'tag_fields') if not tf: return [] # restrict to only 2 fields tf = tuple(set(tf.split(',')))[:2] tl = [] for t in tf: t = t.strip() # disastrous query but lets try it! tl += webnotes.conn.sql("""select `%s`, count(*), '%s' from `tab%s` where docstatus!=2 and ifnull(`%s`, '')!='' group by `%s` order by count(*) desc limit 10""" % (t, t, dt, t, t), as_list=1) if tl: tl.sort(lambda x, y: y[1] - x[1]) return tl[:10]
def set_naming_series(self): if not self.naming_series: # pick default naming series from webnotes.model.doctype import get_property self.naming_series = get_property(self.doctype, "options", "naming_series") if self.naming_series: self.naming_series = self.naming_series.split("\n") self.naming_series = self.naming_series[0] or self.naming_series[1]
def get_default_naming_series(doctype): """get default value for `naming_series` property""" from webnotes.model.doctype import get_property naming_series = get_property(doctype, "options", "naming_series") if naming_series: naming_series = naming_series.split("\n") return naming_series[0] or naming_series[1] else: return None
def _set_name(self, autoname, istable): self.localname = self.name # get my object import webnotes.model.code so = webnotes.model.code.get_server_obj(self, []) # amendments if self.amended_from: self._get_amended_name() # by method elif so and hasattr(so, 'autoname'): r = webnotes.model.code.run_server_obj(so, 'autoname') if r: return r # based on a field elif autoname and autoname.startswith('field:'): n = self.fields[autoname[6:]] if not n: raise Exception, 'Name is required' self.name = n.strip() elif autoname and autoname.startswith("naming_series:"): if not self.naming_series: # pick default naming series from webnotes.model.doctype import get_property self.naming_series = get_property(self.doctype, "options", "naming_series") if not self.naming_series: webnotes.msgprint(webnotes._("Naming Series mandatory"), raise_exception=True) self.naming_series = self.naming_series.split("\n") self.naming_series = self.naming_series[ 0] or self.naming_series[1] self.name = make_autoname(self.naming_series + '.#####') # based on expression elif autoname and autoname.startswith('eval:'): doc = self # for setting self.name = eval(autoname[5:]) # call the method! elif autoname and autoname != 'Prompt': self.name = make_autoname(autoname, self.doctype) # given elif self.fields.get('__newname', ''): self.name = self.fields['__newname'] # default name for table elif istable: self.name = make_autoname('#########', self.doctype) # unable to determine a name, use a serial number! if not self.name: self.name = make_autoname('#########', self.doctype)
def set_naming_series(self): if not self.naming_series: # pick default naming series from webnotes.model.doctype import get_property self.naming_series = get_property(self.doctype, "options", "naming_series") if self.naming_series: self.naming_series = self.naming_series.split("\n") self.naming_series = self.naming_series[ 0] or self.naming_series[1]
def _set_name(self, autoname, istable): self.localname = self.name # get my object import webnotes.model.code so = webnotes.model.code.get_server_obj(self, []) # amendments if self.amended_from: self._get_amended_name() # by method elif so and hasattr(so, 'autoname'): r = webnotes.model.code.run_server_obj(so, 'autoname') if r: return r # based on a field elif autoname and autoname.startswith('field:'): n = self.fields[autoname[6:]] if not n: raise Exception, 'Name is required' self.name = n.strip() elif autoname and autoname.startswith("naming_series:"): if not self.naming_series: # pick default naming series from webnotes.model.doctype import get_property self.naming_series = get_property(self.doctype, "options", "naming_series") if not self.naming_series: webnotes.msgprint(webnotes._("Naming Series mandatory"), raise_exception=True) self.naming_series = self.naming_series.split("\n") self.naming_series = self.naming_series[0] or self.naming_series[1] self.name = make_autoname(self.naming_series+'.#####') # based on expression elif autoname and autoname.startswith('eval:'): doc = self # for setting self.name = eval(autoname[5:]) # call the method! elif autoname and autoname!='Prompt': self.name = make_autoname(autoname, self.doctype) # given elif self.fields.get('__newname',''): self.name = self.fields['__newname'] # default name for table elif istable: self.name = make_autoname('#########', self.doctype) # unable to determine a name, use a serial number! if not self.name: self.name = make_autoname('#########', self.doctype)
def get_template(): """download template""" template_type = webnotes.form_dict.get('type') from webnotes.model.doctype import get_property naming_options = get_property("Journal Voucher", "naming_series", "options") voucher_type = get_property("Journal Voucher", "voucher_type", "options") if template_type == "Two Accounts": extra_note = "" columns = '''"Naming Series","Voucher Type","Posting Date","Amount","Debit Account","Credit Account","Cost Center","Against Sales Invoice","Against Purchase Invoice","Against Journal Voucher","Remarks","Due Date","Ref Number","Ref Date"''' else: extra_note = ''' "5. Put the account head as Data label each in a new column" "6. Put the Debit amount as +ve and Credit amount as -ve"''' columns = '''"Naming Series","Voucher Type","Posting Date","Cost Center","Against Sales Invoice","Against Purchase Invoice","Against Journal Voucher","Remarks","Due Date","Ref Number","Ref Date"''' webnotes.response['result'] = '''"Voucher Import: %(template_type)s" "Each entry below will be a separate Journal Voucher." "Note:" "1. Dates in format: %(user_fmt)s" "2. Cost Center is required for Income or Expense accounts" "3. Naming Series Options: %(naming_options)s" "4. Voucher Type Options: %(voucher_type)s"%(extra_note)s "-------Common Values-----------" "Company:","%(default_company)s" "--------Data----------" %(columns)s ''' % { "template_type": template_type, "user_fmt": webnotes.conn.get_value('Control Panel', None, 'date_format'), "default_company": webnotes.conn.get_default("company"), "naming_options": naming_options.replace("\n", ", "), "voucher_type": voucher_type.replace("\n", ", "), "extra_note": extra_note, "columns": columns } webnotes.response['type'] = 'csv' webnotes.response['doctype'] = "Voucher-Import-%s" % template_type
def get_top_field_tags(dt): from webnotes.model.doctype import get_property tf = get_property(dt, 'tag_fields') if not tf: return [] # restrict to only 2 fields tf = tuple(set(tf.split(',')))[:2] tl = [] for t in tf: t = t.strip() # disastrous query but lets try it! tl += webnotes.conn.sql("""select `%s`, count(*), '%s' from `tab%s` where docstatus!=2 and ifnull(`%s`, '')!='' group by `%s` order by count(*) desc limit 10""" % (t, t, dt, t, t), as_list=1) if tl: tl.sort(lambda x, y: y[1]-x[1]) return tl[:10]
def process_message(self, mail): """ Updates message from support email as either new or reply """ from home import update_feed content, content_type = '[Blank Email]', 'text/plain' if mail.text_content: content, content_type = mail.text_content, 'text/plain' else: content, content_type = mail.html_content, 'text/html' thread_list = mail.get_thread_id() email_id = mail.mail['From'] if "<" in mail.mail['From']: import re re_result = re.findall('(?<=\<)(\S+)(?=\>)', mail.mail['From']) if re_result and re_result[0]: email_id = re_result[0] from webnotes.utils import decode_email_header full_email_id = decode_email_header(mail.mail['From']) for thread_id in thread_list: exists = webnotes.conn.sql("""\ SELECT name FROM `tabSupport Ticket` WHERE name=%s AND raised_by REGEXP %s """ , (thread_id, '(' + email_id + ')')) if exists and exists[0] and exists[0][0]: from webnotes.model.code import get_obj st = get_obj('Support Ticket', thread_id) st.make_response_record(content, full_email_id, content_type) # to update modified date #webnotes.conn.set(st.doc, 'status', 'Open') st.doc.status = 'Open' st.doc.save() update_feed(st.doc, 'on_update') webnotes.conn.commit() # extract attachments self.save_attachments(st.doc, mail.attachments) webnotes.conn.begin() return from webnotes.model.doctype import get_property opts = get_property('Support Ticket', 'options', 'naming_series') # new ticket from webnotes.model.doc import Document d = Document('Support Ticket') d.description = content d.subject = decode_email_header(mail.mail['Subject']) d.raised_by = full_email_id d.content_type = content_type d.status = 'Open' d.naming_series = opts and opts.split("\n")[0] or 'SUP' try: d.save(1) except: d.description = 'Unable to extract message' d.save(1) else: # update feed update_feed(d, 'on_update') # send auto reply if cint(self.email_settings.send_autoreply): self.send_auto_reply(d) webnotes.conn.commit() # extract attachments self.save_attachments(d, mail.attachments) webnotes.conn.begin()
def get_default_naming_series(doctype): from webnotes.model.doctype import get_property naming_series = get_property(doctype, "options", "naming_series") naming_series = naming_series.split("\n") return naming_series[0] or naming_series[1]
def process_message(self, mail): """ Updates message from support email as either new or reply """ from home import update_feed content, content_type = '[Blank Email]', 'text/plain' if mail.text_content: content, content_type = mail.text_content, 'text/plain' else: content, content_type = mail.html_content, 'text/html' thread_list = mail.get_thread_id() email_id = mail.mail['From'] if "<" in mail.mail['From']: import re re_result = re.findall('(?<=\<)(\S+)(?=\>)', mail.mail['From']) if re_result and re_result[0]: email_id = re_result[0] for thread_id in thread_list: exists = webnotes.conn.sql( """\ SELECT name FROM `tabSupport Ticket` WHERE name=%s AND raised_by REGEXP %s """, (thread_id, '(' + email_id + ')')) if exists and exists[0] and exists[0][0]: from webnotes.model.code import get_obj st = get_obj('Support Ticket', thread_id) st.make_response_record(content, mail.mail['From'], content_type) # to update modified date #webnotes.conn.set(st.doc, 'status', 'Open') st.doc.status = 'Open' st.doc.save() update_feed(st.doc, 'on_update') webnotes.conn.commit() # extract attachments self.save_attachments(st.doc, mail.attachments) return from webnotes.model.doctype import get_property opts = get_property('Support Ticket', 'options', 'naming_series') # new ticket from webnotes.model.doc import Document d = Document('Support Ticket') d.description = content d.subject = mail.mail['Subject'] d.raised_by = mail.mail['From'] d.content_type = content_type d.status = 'Open' d.naming_series = opts and opts.split("\n")[0] or 'SUP' try: d.save(1) except: d.description = 'Unable to extract message' d.save(1) else: # update feed update_feed(d, 'on_update') # send auto reply self.send_auto_reply(d) webnotes.conn.commit() # extract attachments self.save_attachments(d, mail.attachments)
def process_message(self, mail): """ Updates message from support email as either new or reply """ from home import update_feed content, content_type = "[Blank Email]", "text/plain" if mail.text_content: content, content_type = mail.text_content, "text/plain" else: content, content_type = mail.html_content, "text/html" thread_list = mail.get_thread_id() email_id = mail.mail["From"] if "<" in mail.mail["From"]: import re re_result = re.findall("(?<=\<)(\S+)(?=\>)", mail.mail["From"]) if re_result and re_result[0]: email_id = re_result[0] for thread_id in thread_list: exists = webnotes.conn.sql( """\ SELECT name FROM `tabSupport Ticket` WHERE name=%s AND raised_by REGEXP %s """, (thread_id, "(" + email_id + ")"), ) if exists and exists[0] and exists[0][0]: from webnotes.model.code import get_obj st = get_obj("Support Ticket", thread_id) st.make_response_record(content, mail.mail["From"], content_type) # to update modified date # webnotes.conn.set(st.doc, 'status', 'Open') st.doc.status = "Open" st.doc.save() update_feed(st.doc, "on_update") webnotes.conn.commit() # extract attachments self.save_attachments(st.doc, mail.attachments) return from webnotes.model.doctype import get_property opts = get_property("Support Ticket", "options", "naming_series") # new ticket from webnotes.model.doc import Document d = Document("Support Ticket") d.description = content d.subject = mail.mail["Subject"] d.raised_by = mail.mail["From"] d.content_type = content_type d.status = "Open" d.naming_series = opts and opts.split("\n")[0] or "SUP" try: d.save(1) except: d.description = "Unable to extract message" d.save(1) else: # update feed update_feed(d, "on_update") # send auto reply if cint(self.email_settings.send_autoreply): self.send_auto_reply(d) webnotes.conn.commit() # extract attachments self.save_attachments(d, mail.attachments)
def process_message(self, mail): """ Updates message from support email as either new or reply """ from home import update_feed content, content_type = "[Blank Email]", "text/plain" if mail.text_content: content, content_type = mail.text_content, "text/plain" else: content, content_type = mail.html_content, "text/html" thread_list = mail.get_thread_id() email_id = mail.mail["From"] if "<" in mail.mail["From"]: import re re_result = re.findall("(?<=\<)(\S+)(?=\>)", mail.mail["From"]) if re_result and re_result[0]: email_id = re_result[0] from webnotes.utils import decode_email_header full_email_id = decode_email_header(mail.mail["From"]) for thread_id in thread_list: exists = webnotes.conn.sql( """\ SELECT name FROM `tabSupport Ticket` WHERE name=%s AND raised_by REGEXP %s """, (thread_id, "(" + email_id + ")"), ) if exists and exists[0] and exists[0][0]: st = webnotes.get_obj("Support Ticket", thread_id) from core.doctype.communication.communication import make make( content=content, sender=full_email_id, doctype="Support Ticket", name=thread_id, lead=st.doc.lead, contact=st.doc.contact, ) st.doc.status = "Open" st.doc.save() update_feed(st, "on_update") # extract attachments self.save_attachments(st.doc, mail.attachments) return from webnotes.model.doctype import get_property opts = get_property("Support Ticket", "options", "naming_series") # new ticket from webnotes.model.doc import Document d = Document("Support Ticket") d.description = content d.subject = decode_email_header(mail.mail["Subject"]) d.raised_by = full_email_id d.content_type = content_type d.status = "Open" d.naming_series = opts and opts.split("\n")[0] or "SUP" try: d.save(1) try: # extract attachments self.save_attachments(d, mail.attachments) except Exception, e: self.description += "\n\n[Did not pull attachment]" except: d.description = "Unable to extract message" d.save(1) else: # send auto reply if cint(self.email_settings.send_autoreply): if "mailer-daemon" not in d.raised_by.lower(): self.send_auto_reply(d)
def process_message(self, mail): """ Updates message from support email as either new or reply """ from home import update_feed content, content_type = '[Blank Email]', 'text/plain' if mail.text_content: content, content_type = mail.text_content, 'text/plain' else: content, content_type = mail.html_content, 'text/html' thread_list = mail.get_thread_id() email_id = mail.mail['From'] if "<" in mail.mail['From']: import re re_result = re.findall('(?<=\<)(\S+)(?=\>)', mail.mail['From']) if re_result and re_result[0]: email_id = re_result[0] from webnotes.utils import decode_email_header full_email_id = decode_email_header(mail.mail['From']) for thread_id in thread_list: exists = webnotes.conn.sql("""\ SELECT name FROM `tabSupport Ticket` WHERE name=%s AND raised_by REGEXP %s """ , (thread_id, '(' + email_id + ')')) if exists and exists[0] and exists[0][0]: st = webnotes.get_obj('Support Ticket', thread_id) from support.doctype.communication.communication import make make(content=content, sender=full_email_id, doctype="Support Ticket", name=thread_id, lead = st.doc.lead, contact=st.doc.contact) st.doc.status = 'Open' st.doc.save() update_feed(st.doc, 'on_update') # extract attachments self.save_attachments(st.doc, mail.attachments) return from webnotes.model.doctype import get_property opts = get_property('Support Ticket', 'options', 'naming_series') # new ticket from webnotes.model.doc import Document d = Document('Support Ticket') d.description = content d.subject = decode_email_header(mail.mail['Subject']) d.raised_by = full_email_id d.content_type = content_type d.status = 'Open' d.naming_series = opts and opts.split("\n")[0] or 'SUP' try: d.save(1) except: d.description = 'Unable to extract message' d.save(1) else: # update feed update_feed(d, 'on_update') # send auto reply if cint(self.email_settings.send_autoreply): if "mailer-daemon" not in d.raised_by.lower(): self.send_auto_reply(d) # extract attachments self.save_attachments(d, mail.attachments)