Anand Doshi | f7e5648 | 2013-08-29 17:46:40 +0530 | [diff] [blame^] | 1 | # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. |
| 2 | # License: GNU General Public License v3. See license.txt |
| 3 | |
| 4 | from __future__ import unicode_literals |
| 5 | import webnotes |
| 6 | from webnotes.utils import cint, formatdate |
| 7 | import json |
| 8 | |
| 9 | def 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 | |
| 27 | def 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() |
| 36 | def get_orders(start=0): |
| 37 | return get_transaction_list("Sales Order", start) |
| 38 | |
| 39 | def 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() |
| 51 | def get_invoices(start=0): |
| 52 | return get_transaction_list("Sales Invoice", start) |
| 53 | |
| 54 | def 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 |