blob: 9667efd2128091d3c891fea192577ced54a8390d [file] [log] [blame]
Rushabh Mehta3966f1d2012-02-23 12:35:32 +05301# 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 Doshi486f9df2012-07-19 13:40:31 +053017from __future__ import unicode_literals
nabinhait601c1962011-06-14 17:52:03 +053018import webnotes
Ravi Dey3333ca12011-07-04 16:23:19 +053019from webnotes import msgprint
nabinhait601c1962011-06-14 17:52:03 +053020
21feed_dict = {
22 # Project
Rushabh Mehta3a50b342011-07-06 14:50:30 +053023 'Project': ['[%(status)s]', '#000080'],
Rushabh Mehta1b151712012-12-27 16:50:24 +053024 'Task': ['[%(status)s] %(subject)s', '#000080'],
nabinhait601c1962011-06-14 17:52:03 +053025
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 Doshiedb45c62012-01-19 17:12:17 +053037 'Purchase Receipt': ['[%(status)s] From %(supplier)s', '#4169E1'],
nabinhait601c1962011-06-14 17:52:03 +053038
39 # Accounts
40 'Journal Voucher': ['[%(voucher_type)s] %(name)s', '#4169E1'],
Anand Doshifedfd892012-03-30 12:29:06 +053041 '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'],
nabinhait601c1962011-06-14 17:52:03 +053043
44 # HR
Anand Doshifedfd892012-03-30 12:29:06 +053045 'Expense Claim': ['[%(approval_status)s] %(name)s by %(employee_name)s', '#4169E1'],
nabinhait601c1962011-06-14 17:52:03 +053046 '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 Doshia872d812012-03-06 17:09:53 +053052 'Support Ticket': ["[%(status)s] %(subject)s", '#000080'],
Rushabh Mehta8b96b052012-02-07 11:43:41 +053053
54 # Website
Rushabh Mehtaf9620ea2012-02-07 14:31:49 +053055 'Web Page': ['%(title)s', '#000080'],
56 'Blog': ['%(title)s', '#000080']
nabinhait601c1962011-06-14 17:52:03 +053057}
58
Rushabh Mehta63d669f2012-02-03 12:56:12 +053059def make_feed(feedtype, doctype, name, owner, subject, color):
nabinhait601c1962011-06-14 17:52:03 +053060 "makes a new Feed record"
Ravi Dey3333ca12011-07-04 16:23:19 +053061 #msgprint(subject)
nabinhait601c1962011-06-14 17:52:03 +053062 from webnotes.model.doc import Document
Rushabh Mehtafdea9662012-02-27 18:03:54 +053063 from webnotes.utils import get_fullname
Rushabh Mehta63d669f2012-02-03 12:56:12 +053064
Rushabh Mehtab8d64972012-02-08 12:33:13 +053065 if feedtype in ('Login', 'Comment', 'Assignment'):
Rushabh Mehta63d669f2012-02-03 12:56:12 +053066 # delete old login, comment feed
67 webnotes.conn.sql("""delete from tabFeed where
Rushabh Mehtab8d64972012-02-08 12:33:13 +053068 datediff(curdate(), creation) > 7 and doc_type in ('Comment', 'Login', 'Assignment')""")
Rushabh Mehta63d669f2012-02-03 12:56:12 +053069 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
nabinhait601c1962011-06-14 17:52:03 +053075 f = Document('Feed')
Rushabh Mehta63d669f2012-02-03 12:56:12 +053076 f.owner = owner
77 f.feed_type = feedtype
78 f.doc_type = doctype
79 f.doc_name = name
nabinhait601c1962011-06-14 17:52:03 +053080 f.subject = subject
81 f.color = color
Rushabh Mehtafdea9662012-02-27 18:03:54 +053082 f.full_name = get_fullname(owner)
Rushabh Mehta63d669f2012-02-03 12:56:12 +053083 f.save()
Ravi Dey913d7b52011-07-04 17:18:01 +053084
Rushabh Mehta1b151712012-12-27 16:50:24 +053085def update_feed(controller, method=None):
nabinhait601c1962011-06-14 17:52:03 +053086 "adds a new feed"
Rushabh Mehta1b151712012-12-27 16:50:24 +053087 doc = controller.doc
Anand Doshiffbfd2c2012-02-21 18:15:31 +053088 if method in ['on_update', 'on_submit']:
Rushabh Mehta49ebfb62012-01-20 15:32:18 +053089 subject, color = feed_dict.get(doc.doctype, [None, None])
Rushabh Mehta056d1722012-12-28 13:26:08 +053090 if subject:
Rushabh Mehta63d669f2012-02-03 12:56:12 +053091 make_feed('', doc.doctype, doc.name, doc.owner, subject % doc.fields, color)