99 lines
3.5 KiB
Python
Raw Normal View History

2012-02-23 12:35:32 +05:30
# ERPNext - web based ERP (http://erpnext.com)
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
#
2012-02-23 12:35:32 +05:30
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
2012-02-23 12:35:32 +05:30
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
2012-02-23 12:35:32 +05:30
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
2014-02-14 15:47:51 +05:30
import frappe
from frappe import msgprint
2011-06-14 17:52:03 +05:30
feed_dict = {
# Project
2014-04-01 12:21:06 +05:30
'Project': ['[%(status)s]', '#000080'],
'Task': ['[%(status)s] %(subject)s', '#000080'],
2011-06-14 17:52:03 +05:30
# Sales
2014-04-01 12:21:06 +05:30
'Lead': ['%(lead_name)s', '#000080'],
'Quotation': ['[%(status)s] To %(customer_name)s worth %(currency)s %(grand_total_export)s', '#4169E1'],
'Sales Order': ['[%(status)s] To %(customer_name)s worth %(currency)s %(grand_total_export)s', '#4169E1'],
2011-06-14 17:52:03 +05:30
# Purchase
2014-04-01 12:21:06 +05:30
'Supplier': ['%(supplier_name)s, %(supplier_type)s', '#6495ED'],
'Purchase Order': ['[%(status)s] %(name)s To %(supplier_name)s for %(currency)s %(grand_total_import)s', '#4169E1'],
2011-06-14 17:52:03 +05:30
# Stock
2014-04-01 12:21:06 +05:30
'Delivery Note': ['[%(status)s] To %(customer_name)s', '#4169E1'],
'Purchase Receipt': ['[%(status)s] From %(supplier)s', '#4169E1'],
2011-06-14 17:52:03 +05:30
# Accounts
2014-04-01 12:21:06 +05:30
'Journal Voucher': ['[%(voucher_type)s] %(name)s', '#4169E1'],
'Purchase Invoice': ['To %(supplier_name)s for %(currency)s %(grand_total_import)s', '#4169E1'],
'Sales Invoice': ['To %(customer_name)s for %(currency)s %(grand_total_export)s', '#4169E1'],
2011-06-14 17:52:03 +05:30
# HR
2014-04-01 12:21:06 +05:30
'Expense Claim': ['[%(approval_status)s] %(name)s by %(employee_name)s', '#4169E1'],
'Salary Slip': ['%(employee_name)s for %(month)s %(fiscal_year)s', '#4169E1'],
'Leave Transaction': ['%(leave_type)s for %(employee)s', '#4169E1'],
2011-06-14 17:52:03 +05:30
# Support
2014-04-01 12:21:06 +05:30
'Customer Issue': ['[%(status)s] %(description)s by %(customer_name)s', '#000080'],
'Maintenance Visit': ['To %(customer_name)s', '#4169E1'],
'Support Ticket': ["[%(status)s] %(subject)s", '#000080'],
2012-02-07 11:43:41 +05:30
# Website
2012-02-07 14:31:49 +05:30
'Web Page': ['%(title)s', '#000080'],
'Blog': ['%(title)s', '#000080']
2011-06-14 17:52:03 +05:30
}
2012-02-03 12:56:12 +05:30
def make_feed(feedtype, doctype, name, owner, subject, color):
2011-06-14 17:52:03 +05:30
"makes a new Feed record"
2011-07-04 16:23:19 +05:30
#msgprint(subject)
2014-04-01 12:21:06 +05:30
from frappe.utils import get_fullname
2012-02-03 12:56:12 +05:30
2012-02-08 12:33:13 +05:30
if feedtype in ('Login', 'Comment', 'Assignment'):
2012-02-03 12:56:12 +05:30
# delete old login, comment feed
frappe.db.sql("""delete from tabFeed where
2012-02-08 12:33:13 +05:30
datediff(curdate(), creation) > 7 and doc_type in ('Comment', 'Login', 'Assignment')""")
2012-02-03 12:56:12 +05:30
else:
# one feed per item
2014-02-26 12:35:33 +05:30
frappe.db.sql("""delete from tabFeed
where doc_type=%s and doc_name=%s
2012-02-03 12:56:12 +05:30
and ifnull(feed_type,'') != 'Comment'""", (doctype, name))
2014-04-01 12:21:06 +05:30
f = frappe.new_doc('Feed')
2012-02-03 12:56:12 +05:30
f.owner = owner
f.feed_type = feedtype
f.doc_type = doctype
f.doc_name = name
2011-06-14 17:52:03 +05:30
f.subject = subject
f.color = color
2012-02-27 18:03:54 +05:30
f.full_name = get_fullname(owner)
f.save(ignore_permissions=True)
2011-07-04 17:18:01 +05:30
def update_feed(doc, method=None):
2011-06-14 17:52:03 +05:30
"adds a new feed"
if frappe.flags.in_patch:
return
2012-02-21 18:15:31 +05:30
if method in ['on_update', 'on_submit']:
2012-01-20 15:32:18 +05:30
subject, color = feed_dict.get(doc.doctype, [None, None])
2012-12-28 13:26:08 +05:30
if subject:
make_feed('', doc.doctype, doc.name, doc.owner, subject % doc.as_dict(), color)
2014-04-01 12:21:06 +05:30
def make_comment_feed(doc, method):
"""add comment to feed"""
make_feed('Comment', doc.comment_doctype, doc.comment_docname, doc.comment_by,
2014-04-01 12:21:06 +05:30
'<i>"' + doc.comment + '"</i>', '#6B24B3')