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