blob: 25e92aa5f9186747580736918a2a4ae5a516e9a8 [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
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053018import frappe
19from frappe import msgprint
nabinhait601c1962011-06-14 17:52:03 +053020
21feed_dict = {
22 # Project
Anand Doshidd32d6e2014-04-01 12:21:06 +053023 'Project': ['[%(status)s]', '#000080'],
24 'Task': ['[%(status)s] %(subject)s', '#000080'],
25
nabinhait601c1962011-06-14 17:52:03 +053026 # Sales
Anand Doshidd32d6e2014-04-01 12:21:06 +053027 '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
nabinhait601c1962011-06-14 17:52:03 +053031 # Purchase
Anand Doshidd32d6e2014-04-01 12:21:06 +053032 '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
nabinhait601c1962011-06-14 17:52:03 +053035 # Stock
Anand Doshidd32d6e2014-04-01 12:21:06 +053036 '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'],
Anand Doshidd32d6e2014-04-01 12:21:06 +053038
nabinhait601c1962011-06-14 17:52:03 +053039 # Accounts
Anand Doshidd32d6e2014-04-01 12:21:06 +053040 'Journal Voucher': ['[%(voucher_type)s] %(name)s', '#4169E1'],
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'],
43
nabinhait601c1962011-06-14 17:52:03 +053044 # HR
Anand Doshidd32d6e2014-04-01 12:21:06 +053045 'Expense Claim': ['[%(approval_status)s] %(name)s by %(employee_name)s', '#4169E1'],
46 'Salary Slip': ['%(employee_name)s for %(month)s %(fiscal_year)s', '#4169E1'],
47 'Leave Transaction': ['%(leave_type)s for %(employee)s', '#4169E1'],
48
nabinhait601c1962011-06-14 17:52:03 +053049 # Support
Anand Doshidd32d6e2014-04-01 12:21:06 +053050 'Customer Issue': ['[%(status)s] %(description)s by %(customer_name)s', '#000080'],
51 'Maintenance Visit': ['To %(customer_name)s', '#4169E1'],
52 '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)
Anand Doshidd32d6e2014-04-01 12:21:06 +053062 from frappe.utils import get_fullname
Rushabh Mehta63d669f2012-02-03 12:56:12 +053063
Rushabh Mehtab8d64972012-02-08 12:33:13 +053064 if feedtype in ('Login', 'Comment', 'Assignment'):
Rushabh Mehta63d669f2012-02-03 12:56:12 +053065 # delete old login, comment feed
Anand Doshie9baaa62014-02-26 12:35:33 +053066 frappe.db.sql("""delete from tabFeed where
Rushabh Mehtab8d64972012-02-08 12:33:13 +053067 datediff(curdate(), creation) > 7 and doc_type in ('Comment', 'Login', 'Assignment')""")
Rushabh Mehta63d669f2012-02-03 12:56:12 +053068 else:
69 # one feed per item
Anand Doshie9baaa62014-02-26 12:35:33 +053070 frappe.db.sql("""delete from tabFeed
Rushabh Mehta63d669f2012-02-03 12:56:12 +053071 where doc_type=%s and doc_name=%s
72 and ifnull(feed_type,'') != 'Comment'""", (doctype, name))
73
Anand Doshidd32d6e2014-04-01 12:21:06 +053074 f = frappe.new_doc('Feed')
Rushabh Mehta63d669f2012-02-03 12:56:12 +053075 f.owner = owner
76 f.feed_type = feedtype
77 f.doc_type = doctype
78 f.doc_name = name
nabinhait601c1962011-06-14 17:52:03 +053079 f.subject = subject
80 f.color = color
Rushabh Mehtafdea9662012-02-27 18:03:54 +053081 f.full_name = get_fullname(owner)
Rushabh Mehta63d669f2012-02-03 12:56:12 +053082 f.save()
Ravi Dey913d7b52011-07-04 17:18:01 +053083
Anand Doshidd32d6e2014-04-01 12:21:06 +053084def update_feed(doc, method=None):
nabinhait601c1962011-06-14 17:52:03 +053085 "adds a new feed"
Anand Doshiffbfd2c2012-02-21 18:15:31 +053086 if method in ['on_update', 'on_submit']:
Rushabh Mehta49ebfb62012-01-20 15:32:18 +053087 subject, color = feed_dict.get(doc.doctype, [None, None])
Rushabh Mehta056d1722012-12-28 13:26:08 +053088 if subject:
Rushabh Mehta090d4102013-09-04 16:20:18 +053089 make_feed('', doc.doctype, doc.name, doc.owner, subject % doc.fields, color)
Rushabh Mehtac652a622013-12-16 12:48:22 +053090
Anand Doshidd32d6e2014-04-01 12:21:06 +053091def make_comment_feed(doc, method):
Rushabh Mehtac652a622013-12-16 12:48:22 +053092 """add comment to feed"""
Rushabh Mehtac652a622013-12-16 12:48:22 +053093 make_feed('Comment', doc.comment_doctype, doc.comment_docname, doc.comment_by,
Anand Doshidd32d6e2014-04-01 12:21:06 +053094 '<i>"' + doc.comment + '"</i>', '#6B24B3')
95