blob: 25da39cfde43ea06f2ea6b0e5fe206617b05501a [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
9def 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
27def 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
35def 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
Anand Doshifb109ad2013-09-11 18:58:20 +053050 }
51
52@webnotes.whitelist(allow_guest=True)
53def send_message(subject="Website Query", message="", sender="", status="Open"):
54 from website.doctype.contact_us_settings.templates.pages.contact \
55 import send_message as website_send_message
56
57 if not website_send_message(subject, message, sender):
58 return
59
60 # make lead / communication
61 from selling.doctype.lead.get_leads import add_sales_communication
62 add_sales_communication(subject or "Website Query", message, sender, sender,
63 mail=None, status=status)