blob: 1aded2efc51dfad9e4da0cf6273e149c2a0c02ca [file] [log] [blame]
Anand Doshif7e56482013-08-29 17:46:40 +05301# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
2# License: GNU General Public License v3. See license.txt
3
4from __future__ import unicode_literals
5import webnotes
6from webnotes.utils import cint, formatdate
7import json
8
9def get_transaction_list(doctype, start):
10 # find customer id
11 customer = webnotes.conn.get_value("Contact", {"email_id": webnotes.session.user},
12 "customer")
13
14 if customer:
15 transactions = webnotes.conn.sql("""select name, creation, currency, grand_total_export
16 from `tab%s` where customer=%s and docstatus=1
17 order by creation desc
Anand Doshi6c8ef772013-08-30 18:23:50 +053018 limit %s, 20""" % (doctype, "%s", "%s"), (customer, cint(start)), as_dict=True)
Anand Doshif7e56482013-08-29 17:46:40 +053019 for doc in transactions:
20 doc.items = ", ".join(webnotes.conn.sql_list("""select item_name
21 from `tab%s Item` where parent=%s limit 5""" % (doctype, "%s"), doc.name))
22 doc.creation = formatdate(doc.creation)
23 return transactions
24 else:
25 return []
26
27def get_common_args():
28 return {
29 "global_number_format": webnotes.conn.get_default("number_format") or "#,###.##",
30 "currency": webnotes.conn.get_default("currency"),
31 "currency_symbols": json.dumps(dict(webnotes.conn.sql("""select name, symbol
32 from tabCurrency where ifnull(enabled,0)=1""")))
33 }
34
35@webnotes.whitelist()
36def get_orders(start=0):
37 return get_transaction_list("Sales Order", start)
38
39def order_list_args():
40 args = get_common_args()
41 args.update({
42 "title": "My Orders",
43 "method": "website.helpers.transaction.get_orders",
44 "icon": "icon-list",
45 "empty_list_message": "No Orders Yet",
46 "page": "order",
47 })
48 return args
49
50@webnotes.whitelist()
51def get_invoices(start=0):
52 return get_transaction_list("Sales Invoice", start)
53
54def invoice_list_args():
55 args = get_common_args()
56 args.update({
57 "title": "Invoices",
58 "method": "website.helpers.transaction.get_invoices",
59 "icon": "icon-file-text",
60 "empty_list_message": "No Invoices Found",
61 "page": "invoice"
62 })
Anand Doshi6c8ef772013-08-30 18:23:50 +053063 return args
64
65@webnotes.whitelist()
66def get_shipments(start=0):
67 return get_transaction_list("Delivery Note", start)
68
69def shipment_list_args():
70 args = get_common_args()
71 args.update({
72 "title": "Shipments",
73 "method": "website.helpers.transaction.get_shipments",
74 "icon": "icon-truck",
75 "empty_list_message": "No Shipments Found",
76 "page": "shipment"
77 })
78 return args
79
80@webnotes.whitelist()
81def get_tickets(start=0):
82 tickets = webnotes.conn.sql("""select name, subject, status, creation
83 from `tabSupport Ticket` where raised_by=%s
84 order by modified desc
85 limit %s, 20""", (webnotes.session.user, cint(start)), as_dict=True)
86 for t in tickets:
87 t.creation = formatdate(t.creation)
88
89 return tickets
90
91def ticket_list_args():
92 return {
93 "title": "My Tickets",
94 "method": "website.helpers.transaction.get_tickets",
95 "icon": "icon-ticket",
96 "empty_list_message": "No Tickets Raised",
97 "page": "ticket"
98 }
99
100@webnotes.whitelist()
101def get_messages(start=0):
102 search_term = "%%%s%%" % webnotes.session.user
103 messages = webnotes.conn.sql("""select name, subject, creation,
104 sender, recipients, content
105 from `tabCommunication` where sender like %s or recipients like %s
106 order by creation desc
107 limit %s, 20""", (search_term, search_term, cint(start)), as_dict=True)
108 for m in messages:
109 m.creation = formatdate(m.creation)
110
111 return messages
112
113def message_list_args():
114 return {
115 "title": "Messages",
116 "method": "website.helpers.transaction.get_messages",
117 "icon": "icon-comments",
118 "empty_list_message": "No Messages Found",
119 }