blob: 8f42d9b5fff26fdce98a2a6738850763cccbbee0 [file] [log] [blame]
Anand Doshi330dae92013-09-10 13:46:15 +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
Anand Doshi1be5bb72013-09-12 15:25:38 +05309def get_transaction_list(doctype, start, additional_fields=None):
Anand Doshi330dae92013-09-10 13:46:15 +053010 # find customer id
11 customer = webnotes.conn.get_value("Contact", {"email_id": webnotes.session.user},
12 "customer")
Anand Doshi1be5bb72013-09-12 15:25:38 +053013
Anand Doshi330dae92013-09-10 13:46:15 +053014 if customer:
Anand Doshi1be5bb72013-09-12 15:25:38 +053015 if additional_fields:
16 additional_fields = ", " + ", ".join(("`%s`" % f for f in additional_fields))
17 else:
18 additional_fields = ""
19
20 transactions = webnotes.conn.sql("""select name, creation, currency, grand_total_export
21 %s
Anand Doshi330dae92013-09-10 13:46:15 +053022 from `tab%s` where customer=%s and docstatus=1
23 order by creation desc
Anand Doshi1be5bb72013-09-12 15:25:38 +053024 limit %s, 20""" % (additional_fields, doctype, "%s", "%s"),
25 (customer, cint(start)), as_dict=True)
Anand Doshi330dae92013-09-10 13:46:15 +053026 for doc in transactions:
Anand Doshi1be5bb72013-09-12 15:25:38 +053027 items = webnotes.conn.sql_list("""select item_name
28 from `tab%s Item` where parent=%s limit 6""" % (doctype, "%s"), doc.name)
29 doc.items = ", ".join(items[:5]) + ("..." if (len(items) > 5) else "")
Anand Doshi330dae92013-09-10 13:46:15 +053030 doc.creation = formatdate(doc.creation)
31 return transactions
32 else:
33 return []
34
35def get_currency_context():
36 return {
37 "global_number_format": webnotes.conn.get_default("number_format") or "#,###.##",
38 "currency": webnotes.conn.get_default("currency"),
39 "currency_symbols": json.dumps(dict(webnotes.conn.sql("""select name, symbol
40 from tabCurrency where ifnull(enabled,0)=1""")))
41 }
42
43def get_transaction_context(doctype, name):
44 customer = webnotes.conn.get_value("Contact", {"email_id": webnotes.session.user},
45 "customer")
46
47 bean = webnotes.bean(doctype, name)
48 if bean.doc.customer != customer:
49 return {
50 "doc": {"name": "Not Allowed"}
51 }
52 else:
53 return {
54 "doc": bean.doc,
55 "doclist": bean.doclist,
56 "webnotes": webnotes,
57 "utils": webnotes.utils
Anand Doshifb109ad2013-09-11 18:58:20 +053058 }
59
60@webnotes.whitelist(allow_guest=True)
61def send_message(subject="Website Query", message="", sender="", status="Open"):
62 from website.doctype.contact_us_settings.templates.pages.contact \
63 import send_message as website_send_message
64
65 if not website_send_message(subject, message, sender):
66 return
67
68 # make lead / communication
69 from selling.doctype.lead.get_leads import add_sales_communication
70 add_sales_communication(subject or "Website Query", message, sender, sender,
71 mail=None, status=status)