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'], |
Anand Doshi | edb45c6 | 2012-01-19 17:12:17 +0530 | [diff] [blame] | 19 | 'Purchase Receipt': ['[%(status)s] From %(supplier)s', '#4169E1'], |
nabinhait | 601c196 | 2011-06-14 17:52:03 +0530 | [diff] [blame] | 20 | |
| 21 | # Accounts |
| 22 | 'Journal Voucher': ['[%(voucher_type)s] %(name)s', '#4169E1'], |
| 23 | 'Payable Voucher': ['To %(supplier_name)s for %(currency)s %(grand_total_import)s', '#4169E1'], |
| 24 | 'Receivable Voucher':['To %(customer_name)s for %(currency)s %(grand_total_export)s', '#4169E1'], |
| 25 | |
| 26 | # HR |
| 27 | 'Expense Voucher': ['[%(approval_status)s] %(name)s by %(employee_name)s', '#4169E1'], |
| 28 | 'Salary Slip': ['%(employee_name)s for %(month)s %(fiscal_year)s', '#4169E1'], |
| 29 | 'Leave Transaction':['%(leave_type)s for %(employee)s', '#4169E1'], |
| 30 | |
| 31 | # Support |
| 32 | 'Customer Issue': ['[%(status)s] %(description)s by %(customer_name)s', '#000080'], |
| 33 | 'Maintenance Visit':['To %(customer_name)s', '#4169E1'], |
Rushabh Mehta | 8b96b05 | 2012-02-07 11:43:41 +0530 | [diff] [blame] | 34 | 'Support Ticket': ['[%(status)s] %(subject)s', '#000080'], |
| 35 | |
| 36 | # Website |
| 37 | 'Web Page': ['%(title)s', '#00080'], |
| 38 | 'Blog': ['%(title)s', '#00080'] |
nabinhait | 601c196 | 2011-06-14 17:52:03 +0530 | [diff] [blame] | 39 | } |
| 40 | |
Rushabh Mehta | 63d669f | 2012-02-03 12:56:12 +0530 | [diff] [blame] | 41 | def make_feed(feedtype, doctype, name, owner, subject, color): |
nabinhait | 601c196 | 2011-06-14 17:52:03 +0530 | [diff] [blame] | 42 | "makes a new Feed record" |
Ravi Dey | 3333ca1 | 2011-07-04 16:23:19 +0530 | [diff] [blame] | 43 | #msgprint(subject) |
nabinhait | 601c196 | 2011-06-14 17:52:03 +0530 | [diff] [blame] | 44 | from webnotes.model.doc import Document |
Rushabh Mehta | 63d669f | 2012-02-03 12:56:12 +0530 | [diff] [blame] | 45 | |
| 46 | if feedtype in ('Login', 'Comment'): |
| 47 | # delete old login, comment feed |
| 48 | webnotes.conn.sql("""delete from tabFeed where |
| 49 | datediff(curdate(), creation) > 7 and doc_type in ('Comment', 'Login')""") |
| 50 | else: |
| 51 | # one feed per item |
| 52 | webnotes.conn.sql("""delete from tabFeed |
| 53 | where doc_type=%s and doc_name=%s |
| 54 | and ifnull(feed_type,'') != 'Comment'""", (doctype, name)) |
| 55 | |
nabinhait | 601c196 | 2011-06-14 17:52:03 +0530 | [diff] [blame] | 56 | f = Document('Feed') |
Rushabh Mehta | 63d669f | 2012-02-03 12:56:12 +0530 | [diff] [blame] | 57 | f.owner = owner |
| 58 | f.feed_type = feedtype |
| 59 | f.doc_type = doctype |
| 60 | f.doc_name = name |
nabinhait | 601c196 | 2011-06-14 17:52:03 +0530 | [diff] [blame] | 61 | f.subject = subject |
| 62 | f.color = color |
Rushabh Mehta | 63d669f | 2012-02-03 12:56:12 +0530 | [diff] [blame] | 63 | f.save() |
Ravi Dey | 913d7b5 | 2011-07-04 17:18:01 +0530 | [diff] [blame] | 64 | |
Ravi Dey | ffecc71 | 2011-07-07 13:51:46 +0530 | [diff] [blame] | 65 | def update_feed(doc, method=None): |
nabinhait | 601c196 | 2011-06-14 17:52:03 +0530 | [diff] [blame] | 66 | "adds a new feed" |
Rushabh Mehta | 49ebfb6 | 2012-01-20 15:32:18 +0530 | [diff] [blame] | 67 | if method=='on_update': |
| 68 | subject, color = feed_dict.get(doc.doctype, [None, None]) |
Rushabh Mehta | 63d669f | 2012-02-03 12:56:12 +0530 | [diff] [blame] | 69 | if subject: |
| 70 | make_feed('', doc.doctype, doc.name, doc.owner, subject % doc.fields, color) |