nabinhait | 601c196 | 2011-06-14 17:52:03 +0530 | [diff] [blame] | 1 | import webnotes |
Ravi Dey | 3333ca1 | 2011-07-04 16:23:19 +0530 | [diff] [blame] | 2 | from webnotes import msgprint |
nabinhait | 601c196 | 2011-06-14 17:52:03 +0530 | [diff] [blame] | 3 | |
| 4 | feed_dict = { |
| 5 | # Project |
Rushabh Mehta | 3a50b34 | 2011-07-06 14:50:30 +0530 | [diff] [blame] | 6 | 'Project': ['[%(status)s]', '#000080'], |
nabinhait | 601c196 | 2011-06-14 17:52:03 +0530 | [diff] [blame] | 7 | |
| 8 | # Sales |
| 9 | 'Lead': ['%(lead_name)s', '#000080'], |
| 10 | 'Quotation': ['[%(status)s] To %(customer_name)s worth %(currency)s %(grand_total_export)s', '#4169E1'], |
| 11 | 'Sales Order': ['[%(status)s] To %(customer_name)s worth %(currency)s %(grand_total_export)s', '#4169E1'], |
| 12 | |
| 13 | # Purchase |
| 14 | 'Supplier': ['%(supplier_name)s, %(supplier_type)s', '#6495ED'], |
| 15 | 'Purchase Order': ['[%(status)s] %(name)s To %(supplier_name)s for %(currency)s %(grand_total_import)s', '#4169E1'], |
| 16 | |
| 17 | # Stock |
| 18 | 'Delivery Note': ['[%(status)s] To %(customer_name)s', '#4169E1'], |
| 19 | |
| 20 | # Accounts |
| 21 | 'Journal Voucher': ['[%(voucher_type)s] %(name)s', '#4169E1'], |
| 22 | 'Payable Voucher': ['To %(supplier_name)s for %(currency)s %(grand_total_import)s', '#4169E1'], |
| 23 | 'Receivable Voucher':['To %(customer_name)s for %(currency)s %(grand_total_export)s', '#4169E1'], |
| 24 | |
| 25 | # HR |
| 26 | 'Expense Voucher': ['[%(approval_status)s] %(name)s by %(employee_name)s', '#4169E1'], |
| 27 | 'Salary Slip': ['%(employee_name)s for %(month)s %(fiscal_year)s', '#4169E1'], |
| 28 | 'Leave Transaction':['%(leave_type)s for %(employee)s', '#4169E1'], |
| 29 | |
| 30 | # Support |
| 31 | 'Customer Issue': ['[%(status)s] %(description)s by %(customer_name)s', '#000080'], |
| 32 | 'Maintenance Visit':['To %(customer_name)s', '#4169E1'], |
Ravi Dey | 913d7b5 | 2011-07-04 17:18:01 +0530 | [diff] [blame] | 33 | 'Support Ticket': ['[%(status)s] %(subject)s', '#000080'] |
nabinhait | 601c196 | 2011-06-14 17:52:03 +0530 | [diff] [blame] | 34 | } |
| 35 | |
Ravi Dey | 3333ca1 | 2011-07-04 16:23:19 +0530 | [diff] [blame] | 36 | feed_dict_color = { |
| 37 | # Project |
| 38 | 'Project': '#000080', |
| 39 | |
| 40 | # Sales |
| 41 | 'Lead': '#000080', |
| 42 | 'Quotation': '#4169E1', |
| 43 | 'Sales Order': '#4169E1', |
| 44 | |
| 45 | # Purchase |
| 46 | 'Supplier': '#6495ED', |
| 47 | 'Purchase Order': '#4169E1', |
| 48 | |
| 49 | # Stock |
| 50 | 'Delivery Note': '#4169E1', |
| 51 | |
| 52 | # Accounts |
| 53 | 'Journal Voucher': '#4169E1', |
| 54 | 'Payable Voucher': '#4169E1', |
| 55 | 'Receivable Voucher': '#4169E1', |
| 56 | |
| 57 | # HR |
| 58 | 'Expense Voucher': '#4169E1', |
| 59 | 'Salary Slip': '#4169E1', |
| 60 | 'Leave Transaction': '#4169E1', |
| 61 | |
| 62 | # Support |
| 63 | 'Customer Issue': '#000080', |
| 64 | 'Maintenance Visit': '#4169E1', |
| 65 | 'Support Ticket': '#000080' |
| 66 | } |
nabinhait | 601c196 | 2011-06-14 17:52:03 +0530 | [diff] [blame] | 67 | |
| 68 | def make_feed(doc, subject, color): |
| 69 | "makes a new Feed record" |
Ravi Dey | 3333ca1 | 2011-07-04 16:23:19 +0530 | [diff] [blame] | 70 | #msgprint(subject) |
nabinhait | 601c196 | 2011-06-14 17:52:03 +0530 | [diff] [blame] | 71 | from webnotes.model.doc import Document |
| 72 | webnotes.conn.sql("delete from tabFeed where doc_type=%s and doc_name=%s", (doc.doctype, doc.name)) |
| 73 | f = Document('Feed') |
| 74 | f.doc_type = doc.doctype |
| 75 | f.doc_name = doc.name |
| 76 | f.subject = subject |
| 77 | f.color = color |
| 78 | f.save(1) |
Ravi Dey | 913d7b5 | 2011-07-04 17:18:01 +0530 | [diff] [blame] | 79 | |
| 80 | def update_feed1(doc): |
| 81 | "adds a new feed" |
| 82 | prop_rec = webnotes.conn.sql("select value from `tabProperty Setter` where doc_type = %s and property = 'subject'", (doc.doctype)) |
| 83 | if prop_rec: |
| 84 | subject = prop_rec[0][0] |
| 85 | else: |
| 86 | rec = webnotes.conn.sql("select subject from tabDocType where name=%s", (doc.doctype)) |
| 87 | subject = rec[0][0] |
nabinhait | 601c196 | 2011-06-14 17:52:03 +0530 | [diff] [blame] | 88 | |
Ravi Dey | 913d7b5 | 2011-07-04 17:18:01 +0530 | [diff] [blame] | 89 | subject, color = [subject, feed_dict_color.get(doc.doctype)] |
| 90 | if subject: |
| 91 | subject = subject % doc.fields |
| 92 | make_feed(doc, subject, color) |
Ravi Dey | e2ddb24 | 2011-07-04 16:47:24 +0530 | [diff] [blame] | 93 | |
Ravi Dey | ffecc71 | 2011-07-07 13:51:46 +0530 | [diff] [blame] | 94 | def update_feed(doc, method=None): |
nabinhait | 601c196 | 2011-06-14 17:52:03 +0530 | [diff] [blame] | 95 | "adds a new feed" |
Rushabh Mehta | 3a50b34 | 2011-07-06 14:50:30 +0530 | [diff] [blame] | 96 | if method=='validate': |
| 97 | return |
Ravi Dey | e2ddb24 | 2011-07-04 16:47:24 +0530 | [diff] [blame] | 98 | subject, color = feed_dict.get(doc.doctype, [None, None]) |
nabinhait | 601c196 | 2011-06-14 17:52:03 +0530 | [diff] [blame] | 99 | if subject: |
Ravi Dey | 9514ee9 | 2011-07-04 16:49:25 +0530 | [diff] [blame] | 100 | subject = subject % doc.fields |
| 101 | make_feed(doc, subject, color) |