Anand Doshi | 330dae9 | 2013-09-10 13:46:15 +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=True) |
| 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_currency_context(): |
| 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 | def get_transaction_context(doctype, name): |
| 36 | customer = webnotes.conn.get_value("Contact", {"email_id": webnotes.session.user}, |
| 37 | "customer") |
| 38 | |
| 39 | bean = webnotes.bean(doctype, name) |
| 40 | if bean.doc.customer != customer: |
| 41 | return { |
| 42 | "doc": {"name": "Not Allowed"} |
| 43 | } |
| 44 | else: |
| 45 | return { |
| 46 | "doc": bean.doc, |
| 47 | "doclist": bean.doclist, |
| 48 | "webnotes": webnotes, |
| 49 | "utils": webnotes.utils |
| 50 | } |