blob: 336be2a1e2860b62891cf1027563230efb24763d [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
18 limit %s, 20""" % (doctype, "%s", "%s"), (customer, cint(start)), as_dict=1)
19 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 })
63 return args