blob: 8943575c6c89acf270c2bdd88470f57f9c2355eb [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 }
Anand Doshid5c18d42013-09-04 15:07:00 +053099
100def get_transaction_args(doctype, name):
101 customer = webnotes.conn.get_value("Contact", {"email_id": webnotes.session.user},
102 "customer")
103
104 bean = webnotes.bean(doctype, name)
105 if bean.doc.customer != customer:
106 return {
107 "doc": {"name": "Not Allowed"}
108 }
109 else:
110 return {
111 "doc": bean.doc,
112 "doclist": bean.doclist,
113 "webnotes": webnotes,
114 "utils": webnotes.utils
115 }
116
117def get_order_args():
Anand Doshi85ef5022013-09-04 16:46:08 +0530118 args = get_transaction_args("Sales Order", webnotes.form_dict.name)
119 args.update({
120 "parent_link": "orders",
121 "parent_title": "My Orders"
122 })
123 return args
Anand Doshid5c18d42013-09-04 15:07:00 +0530124
125def get_invoice_args():
Anand Doshi85ef5022013-09-04 16:46:08 +0530126 args = get_transaction_args("Sales Invoice", webnotes.form_dict.name)
127 args.update({
128 "parent_link": "invoices",
129 "parent_title": "Invoices"
130 })
131 return args
Anand Doshid5c18d42013-09-04 15:07:00 +0530132
133def get_shipment_args():
Anand Doshi85ef5022013-09-04 16:46:08 +0530134 args = get_transaction_args("Delivery Note", webnotes.form_dict.name)
135 args.update({
136 "parent_link": "shipments",
137 "parent_title": "Shipments"
138 })
139 return args