blob: bec99d48ff877cd543cacd2d3abe6487f53b6f96 [file] [log] [blame]
nabinhait601c1962011-06-14 17:52:03 +05301import webnotes
Ravi Dey3333ca12011-07-04 16:23:19 +05302from webnotes import msgprint
nabinhait601c1962011-06-14 17:52:03 +05303
4feed_dict = {
5 # Project
Rushabh Mehta3a50b342011-07-06 14:50:30 +05306 'Project': ['[%(status)s]', '#000080'],
nabinhait601c1962011-06-14 17:52:03 +05307
8 # Sales
9 'Lead': ['%(lead_name)s', '#000080'],
10 'Quotation': ['[%(status)s] To %(customer_name)s worth %(currency)s %(grand_total_export)s', '#4169E1'],
11 'Sales Order': ['[%(status)s] To %(customer_name)s worth %(currency)s %(grand_total_export)s', '#4169E1'],
12
13 # Purchase
14 'Supplier': ['%(supplier_name)s, %(supplier_type)s', '#6495ED'],
15 'Purchase Order': ['[%(status)s] %(name)s To %(supplier_name)s for %(currency)s %(grand_total_import)s', '#4169E1'],
16
17 # Stock
18 'Delivery Note': ['[%(status)s] To %(customer_name)s', '#4169E1'],
Anand Doshiedb45c62012-01-19 17:12:17 +053019 'Purchase Receipt': ['[%(status)s] From %(supplier)s', '#4169E1'],
nabinhait601c1962011-06-14 17:52:03 +053020
21 # Accounts
22 'Journal Voucher': ['[%(voucher_type)s] %(name)s', '#4169E1'],
23 'Payable Voucher': ['To %(supplier_name)s for %(currency)s %(grand_total_import)s', '#4169E1'],
24 'Receivable Voucher':['To %(customer_name)s for %(currency)s %(grand_total_export)s', '#4169E1'],
25
26 # HR
27 'Expense Voucher': ['[%(approval_status)s] %(name)s by %(employee_name)s', '#4169E1'],
28 'Salary Slip': ['%(employee_name)s for %(month)s %(fiscal_year)s', '#4169E1'],
29 'Leave Transaction':['%(leave_type)s for %(employee)s', '#4169E1'],
30
31 # Support
32 'Customer Issue': ['[%(status)s] %(description)s by %(customer_name)s', '#000080'],
33 'Maintenance Visit':['To %(customer_name)s', '#4169E1'],
Rushabh Mehta8b96b052012-02-07 11:43:41 +053034 'Support Ticket': ['[%(status)s] %(subject)s', '#000080'],
35
36 # Website
Rushabh Mehtaf9620ea2012-02-07 14:31:49 +053037 'Web Page': ['%(title)s', '#000080'],
38 'Blog': ['%(title)s', '#000080']
nabinhait601c1962011-06-14 17:52:03 +053039}
40
Rushabh Mehta63d669f2012-02-03 12:56:12 +053041def make_feed(feedtype, doctype, name, owner, subject, color):
nabinhait601c1962011-06-14 17:52:03 +053042 "makes a new Feed record"
Ravi Dey3333ca12011-07-04 16:23:19 +053043 #msgprint(subject)
nabinhait601c1962011-06-14 17:52:03 +053044 from webnotes.model.doc import Document
Rushabh Mehta63d669f2012-02-03 12:56:12 +053045
46 if feedtype in ('Login', 'Comment'):
47 # delete old login, comment feed
48 webnotes.conn.sql("""delete from tabFeed where
49 datediff(curdate(), creation) > 7 and doc_type in ('Comment', 'Login')""")
50 else:
51 # one feed per item
52 webnotes.conn.sql("""delete from tabFeed
53 where doc_type=%s and doc_name=%s
54 and ifnull(feed_type,'') != 'Comment'""", (doctype, name))
55
nabinhait601c1962011-06-14 17:52:03 +053056 f = Document('Feed')
Rushabh Mehta63d669f2012-02-03 12:56:12 +053057 f.owner = owner
58 f.feed_type = feedtype
59 f.doc_type = doctype
60 f.doc_name = name
nabinhait601c1962011-06-14 17:52:03 +053061 f.subject = subject
62 f.color = color
Rushabh Mehta63d669f2012-02-03 12:56:12 +053063 f.save()
Ravi Dey913d7b52011-07-04 17:18:01 +053064
Ravi Deyffecc712011-07-07 13:51:46 +053065def update_feed(doc, method=None):
nabinhait601c1962011-06-14 17:52:03 +053066 "adds a new feed"
Rushabh Mehta49ebfb62012-01-20 15:32:18 +053067 if method=='on_update':
68 subject, color = feed_dict.get(doc.doctype, [None, None])
Rushabh Mehta63d669f2012-02-03 12:56:12 +053069 if subject:
70 make_feed('', doc.doctype, doc.name, doc.owner, subject % doc.fields, color)