blob: 139e63af30f9e06982107fd24fdc1a68fc4e6dda [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
Rushabh Mehta3daa49a2014-10-21 16:16:30 +05305
6import frappe, json
7from frappe import _
8from frappe.utils import cint, formatdate
Anand Doshifb109ad2013-09-11 18:58:20 +05309
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053010@frappe.whitelist(allow_guest=True)
Anand Doshifb109ad2013-09-11 18:58:20 +053011def send_message(subject="Website Query", message="", sender="", status="Open"):
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053012 from frappe.templates.pages.contact import send_message as website_send_message
Anand Doshi5d591eb2014-04-18 16:15:31 +053013
Rushabh Mehta5cdc8e52014-09-15 16:59:38 +053014 website_send_message(subject, message, sender)
Anand Doshi5d591eb2014-04-18 16:15:31 +053015
Rushabh Mehta5cdc8e52014-09-15 16:59:38 +053016 comm = frappe.get_doc({
17 "doctype":"Communication",
18 "subject": subject,
19 "content": message,
20 "sender": sender,
21 "sent_or_received": "Received"
22 })
23 comm.insert(ignore_permissions=True)
Rushabh Mehta3daa49a2014-10-21 16:16:30 +053024
25def get_transaction_list(doctype, start, additional_fields=None):
26 # find customer id
27 customer = frappe.db.get_value("Contact", {"email_id": frappe.session.user},
28 "customer")
29
30 if customer:
31 if additional_fields:
32 additional_fields = ", " + ", ".join(("`%s`" % f for f in additional_fields))
33 else:
34 additional_fields = ""
35
36 transactions = frappe.db.sql("""select name, creation, currency, grand_total_export
37 %s
38 from `tab%s` where customer=%s and docstatus=1
39 order by creation desc
40 limit %s, 20""" % (additional_fields, doctype, "%s", "%s"),
41 (customer, cint(start)), as_dict=True)
42 for doc in transactions:
43 items = frappe.db.sql_list("""select item_name
44 from `tab%s Item` where parent=%s limit 6""" % (doctype, "%s"), doc.name)
45 doc.items = ", ".join(items[:5]) + ("..." if (len(items) > 5) else "")
46 doc.creation = formatdate(doc.creation)
47 return transactions
48 else:
49 return []
50
51def get_currency_context():
52 return {
53 "global_number_format": frappe.db.get_default("number_format") or "#,###.##",
54 "currency": frappe.db.get_default("currency"),
55 "currency_symbols": json.dumps(dict(frappe.db.sql("""select name, symbol
56 from tabCurrency where ifnull(enabled,0)=1""")))
57 }
58
59def get_transaction_context(doctype, name):
60 customer = frappe.db.get_value("Contact", {"email_id": frappe.session.user},
61 "customer")
62
63 doc = frappe.get_doc(doctype, name)
64 if doc.customer != customer:
65 return { "doc": frappe._dict({"name": _("Not Allowed")}) }
66 else:
67 return { "doc": doc }