Rushabh Mehta | 3966f1d | 2012-02-23 12:35:32 +0530 | [diff] [blame] | 1 | # ERPNext - web based ERP (http://erpnext.com) |
| 2 | # Copyright (C) 2012 Web Notes Technologies Pvt Ltd |
| 3 | # |
| 4 | # This program is free software: you can redistribute it and/or modify |
| 5 | # it under the terms of the GNU General Public License as published by |
| 6 | # the Free Software Foundation, either version 3 of the License, or |
| 7 | # (at your option) any later version. |
| 8 | # |
| 9 | # This program is distributed in the hope that it will be useful, |
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | # GNU General Public License for more details. |
| 13 | # |
| 14 | # You should have received a copy of the GNU General Public License |
| 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | |
Anand Doshi | 486f9df | 2012-07-19 13:40:31 +0530 | [diff] [blame] | 17 | from __future__ import unicode_literals |
nabinhait | 601c196 | 2011-06-14 17:52:03 +0530 | [diff] [blame] | 18 | import webnotes |
Ravi Dey | 3333ca1 | 2011-07-04 16:23:19 +0530 | [diff] [blame] | 19 | from webnotes import msgprint |
nabinhait | 601c196 | 2011-06-14 17:52:03 +0530 | [diff] [blame] | 20 | |
| 21 | feed_dict = { |
| 22 | # Project |
Rushabh Mehta | 3a50b34 | 2011-07-06 14:50:30 +0530 | [diff] [blame] | 23 | 'Project': ['[%(status)s]', '#000080'], |
Rushabh Mehta | 1b15171 | 2012-12-27 16:50:24 +0530 | [diff] [blame] | 24 | 'Task': ['[%(status)s] %(subject)s', '#000080'], |
nabinhait | 601c196 | 2011-06-14 17:52:03 +0530 | [diff] [blame] | 25 | |
| 26 | # Sales |
| 27 | 'Lead': ['%(lead_name)s', '#000080'], |
| 28 | 'Quotation': ['[%(status)s] To %(customer_name)s worth %(currency)s %(grand_total_export)s', '#4169E1'], |
| 29 | 'Sales Order': ['[%(status)s] To %(customer_name)s worth %(currency)s %(grand_total_export)s', '#4169E1'], |
| 30 | |
| 31 | # Purchase |
| 32 | 'Supplier': ['%(supplier_name)s, %(supplier_type)s', '#6495ED'], |
| 33 | 'Purchase Order': ['[%(status)s] %(name)s To %(supplier_name)s for %(currency)s %(grand_total_import)s', '#4169E1'], |
| 34 | |
| 35 | # Stock |
| 36 | 'Delivery Note': ['[%(status)s] To %(customer_name)s', '#4169E1'], |
Anand Doshi | edb45c6 | 2012-01-19 17:12:17 +0530 | [diff] [blame] | 37 | 'Purchase Receipt': ['[%(status)s] From %(supplier)s', '#4169E1'], |
nabinhait | 601c196 | 2011-06-14 17:52:03 +0530 | [diff] [blame] | 38 | |
| 39 | # Accounts |
| 40 | 'Journal Voucher': ['[%(voucher_type)s] %(name)s', '#4169E1'], |
Anand Doshi | fedfd89 | 2012-03-30 12:29:06 +0530 | [diff] [blame] | 41 | 'Purchase Invoice': ['To %(supplier_name)s for %(currency)s %(grand_total_import)s', '#4169E1'], |
| 42 | 'Sales Invoice':['To %(customer_name)s for %(currency)s %(grand_total_export)s', '#4169E1'], |
nabinhait | 601c196 | 2011-06-14 17:52:03 +0530 | [diff] [blame] | 43 | |
| 44 | # HR |
Anand Doshi | fedfd89 | 2012-03-30 12:29:06 +0530 | [diff] [blame] | 45 | 'Expense Claim': ['[%(approval_status)s] %(name)s by %(employee_name)s', '#4169E1'], |
nabinhait | 601c196 | 2011-06-14 17:52:03 +0530 | [diff] [blame] | 46 | 'Salary Slip': ['%(employee_name)s for %(month)s %(fiscal_year)s', '#4169E1'], |
| 47 | 'Leave Transaction':['%(leave_type)s for %(employee)s', '#4169E1'], |
| 48 | |
| 49 | # Support |
| 50 | 'Customer Issue': ['[%(status)s] %(description)s by %(customer_name)s', '#000080'], |
| 51 | 'Maintenance Visit':['To %(customer_name)s', '#4169E1'], |
Anand Doshi | a872d81 | 2012-03-06 17:09:53 +0530 | [diff] [blame] | 52 | 'Support Ticket': ["[%(status)s] %(subject)s", '#000080'], |
Rushabh Mehta | 8b96b05 | 2012-02-07 11:43:41 +0530 | [diff] [blame] | 53 | |
| 54 | # Website |
Rushabh Mehta | f9620ea | 2012-02-07 14:31:49 +0530 | [diff] [blame] | 55 | 'Web Page': ['%(title)s', '#000080'], |
| 56 | 'Blog': ['%(title)s', '#000080'] |
nabinhait | 601c196 | 2011-06-14 17:52:03 +0530 | [diff] [blame] | 57 | } |
| 58 | |
Rushabh Mehta | 63d669f | 2012-02-03 12:56:12 +0530 | [diff] [blame] | 59 | def make_feed(feedtype, doctype, name, owner, subject, color): |
nabinhait | 601c196 | 2011-06-14 17:52:03 +0530 | [diff] [blame] | 60 | "makes a new Feed record" |
Ravi Dey | 3333ca1 | 2011-07-04 16:23:19 +0530 | [diff] [blame] | 61 | #msgprint(subject) |
nabinhait | 601c196 | 2011-06-14 17:52:03 +0530 | [diff] [blame] | 62 | from webnotes.model.doc import Document |
Rushabh Mehta | fdea966 | 2012-02-27 18:03:54 +0530 | [diff] [blame] | 63 | from webnotes.utils import get_fullname |
Rushabh Mehta | 63d669f | 2012-02-03 12:56:12 +0530 | [diff] [blame] | 64 | |
Rushabh Mehta | b8d6497 | 2012-02-08 12:33:13 +0530 | [diff] [blame] | 65 | if feedtype in ('Login', 'Comment', 'Assignment'): |
Rushabh Mehta | 63d669f | 2012-02-03 12:56:12 +0530 | [diff] [blame] | 66 | # delete old login, comment feed |
| 67 | webnotes.conn.sql("""delete from tabFeed where |
Rushabh Mehta | b8d6497 | 2012-02-08 12:33:13 +0530 | [diff] [blame] | 68 | datediff(curdate(), creation) > 7 and doc_type in ('Comment', 'Login', 'Assignment')""") |
Rushabh Mehta | 63d669f | 2012-02-03 12:56:12 +0530 | [diff] [blame] | 69 | else: |
| 70 | # one feed per item |
| 71 | webnotes.conn.sql("""delete from tabFeed |
| 72 | where doc_type=%s and doc_name=%s |
| 73 | and ifnull(feed_type,'') != 'Comment'""", (doctype, name)) |
| 74 | |
nabinhait | 601c196 | 2011-06-14 17:52:03 +0530 | [diff] [blame] | 75 | f = Document('Feed') |
Rushabh Mehta | 63d669f | 2012-02-03 12:56:12 +0530 | [diff] [blame] | 76 | f.owner = owner |
| 77 | f.feed_type = feedtype |
| 78 | f.doc_type = doctype |
| 79 | f.doc_name = name |
nabinhait | 601c196 | 2011-06-14 17:52:03 +0530 | [diff] [blame] | 80 | f.subject = subject |
| 81 | f.color = color |
Rushabh Mehta | fdea966 | 2012-02-27 18:03:54 +0530 | [diff] [blame] | 82 | f.full_name = get_fullname(owner) |
Rushabh Mehta | 63d669f | 2012-02-03 12:56:12 +0530 | [diff] [blame] | 83 | f.save() |
Ravi Dey | 913d7b5 | 2011-07-04 17:18:01 +0530 | [diff] [blame] | 84 | |
Rushabh Mehta | 1b15171 | 2012-12-27 16:50:24 +0530 | [diff] [blame] | 85 | def update_feed(controller, method=None): |
nabinhait | 601c196 | 2011-06-14 17:52:03 +0530 | [diff] [blame] | 86 | "adds a new feed" |
Rushabh Mehta | 1b15171 | 2012-12-27 16:50:24 +0530 | [diff] [blame] | 87 | doc = controller.doc |
Anand Doshi | ffbfd2c | 2012-02-21 18:15:31 +0530 | [diff] [blame] | 88 | if method in ['on_update', 'on_submit']: |
Rushabh Mehta | 49ebfb6 | 2012-01-20 15:32:18 +0530 | [diff] [blame] | 89 | subject, color = feed_dict.get(doc.doctype, [None, None]) |
Rushabh Mehta | 056d172 | 2012-12-28 13:26:08 +0530 | [diff] [blame] | 90 | if subject: |
Rushabh Mehta | 090d410 | 2013-09-04 16:20:18 +0530 | [diff] [blame] | 91 | make_feed('', doc.doctype, doc.name, doc.owner, subject % doc.fields, color) |