blob: 9ec542262af56acef7657636b23574cc7567f388 [file] [log] [blame]
Rushabh Mehtaad45e312013-11-20 12:59:58 +05301# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
Anand Doshi330dae92013-09-10 13:46:15 +05302# 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"):
Rushabh Mehta39bb8e22013-12-11 15:32:14 +053062 from webnotes.website.doctype.contact_us_settings.templates.pages.contact \
Anand Doshifb109ad2013-09-11 18:58:20 +053063 import send_message as website_send_message
64
65 if not website_send_message(subject, message, sender):
66 return
Anand Doshidf019802013-12-04 16:27:30 +053067
68 if subject=="Support":
69 # create support ticket
Rushabh Mehta1f847992013-12-12 19:12:19 +053070 from erpnext.support.doctype.support_ticket.get_support_mails import add_support_communication
Anand Doshidf019802013-12-04 16:27:30 +053071 add_support_communication(subject, message, sender, mail=None)
72 else:
73 # make lead / communication
Rushabh Mehta1f847992013-12-12 19:12:19 +053074 from erpnext.selling.doctype.lead.get_leads import add_sales_communication
Anand Doshidf019802013-12-04 16:27:30 +053075 add_sales_communication(subject or "Website Query", message, sender, sender,
76 mail=None, status=status)
Anand Doshi619ed5e2013-09-17 13:46:50 +053077