2013-11-20 07:29:58 +00:00
|
|
|
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
2013-09-10 08:16:15 +00:00
|
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
import webnotes
|
|
|
|
from webnotes.utils import cint, formatdate
|
|
|
|
import json
|
|
|
|
|
2013-09-12 09:55:38 +00:00
|
|
|
def get_transaction_list(doctype, start, additional_fields=None):
|
2013-09-10 08:16:15 +00:00
|
|
|
# find customer id
|
|
|
|
customer = webnotes.conn.get_value("Contact", {"email_id": webnotes.session.user},
|
|
|
|
"customer")
|
2013-09-12 09:55:38 +00:00
|
|
|
|
2013-09-10 08:16:15 +00:00
|
|
|
if customer:
|
2013-09-12 09:55:38 +00:00
|
|
|
if additional_fields:
|
|
|
|
additional_fields = ", " + ", ".join(("`%s`" % f for f in additional_fields))
|
|
|
|
else:
|
|
|
|
additional_fields = ""
|
|
|
|
|
|
|
|
transactions = webnotes.conn.sql("""select name, creation, currency, grand_total_export
|
|
|
|
%s
|
2013-09-10 08:16:15 +00:00
|
|
|
from `tab%s` where customer=%s and docstatus=1
|
|
|
|
order by creation desc
|
2013-09-12 09:55:38 +00:00
|
|
|
limit %s, 20""" % (additional_fields, doctype, "%s", "%s"),
|
|
|
|
(customer, cint(start)), as_dict=True)
|
2013-09-10 08:16:15 +00:00
|
|
|
for doc in transactions:
|
2013-09-12 09:55:38 +00:00
|
|
|
items = webnotes.conn.sql_list("""select item_name
|
|
|
|
from `tab%s Item` where parent=%s limit 6""" % (doctype, "%s"), doc.name)
|
|
|
|
doc.items = ", ".join(items[:5]) + ("..." if (len(items) > 5) else "")
|
2013-09-10 08:16:15 +00:00
|
|
|
doc.creation = formatdate(doc.creation)
|
|
|
|
return transactions
|
|
|
|
else:
|
|
|
|
return []
|
|
|
|
|
|
|
|
def get_currency_context():
|
|
|
|
return {
|
|
|
|
"global_number_format": webnotes.conn.get_default("number_format") or "#,###.##",
|
|
|
|
"currency": webnotes.conn.get_default("currency"),
|
|
|
|
"currency_symbols": json.dumps(dict(webnotes.conn.sql("""select name, symbol
|
|
|
|
from tabCurrency where ifnull(enabled,0)=1""")))
|
|
|
|
}
|
|
|
|
|
|
|
|
def get_transaction_context(doctype, name):
|
|
|
|
customer = webnotes.conn.get_value("Contact", {"email_id": webnotes.session.user},
|
|
|
|
"customer")
|
|
|
|
|
|
|
|
bean = webnotes.bean(doctype, name)
|
|
|
|
if bean.doc.customer != customer:
|
|
|
|
return {
|
|
|
|
"doc": {"name": "Not Allowed"}
|
|
|
|
}
|
|
|
|
else:
|
|
|
|
return {
|
|
|
|
"doc": bean.doc,
|
|
|
|
"doclist": bean.doclist,
|
|
|
|
"webnotes": webnotes,
|
|
|
|
"utils": webnotes.utils
|
2013-09-11 13:28:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@webnotes.whitelist(allow_guest=True)
|
|
|
|
def send_message(subject="Website Query", message="", sender="", status="Open"):
|
|
|
|
from website.doctype.contact_us_settings.templates.pages.contact \
|
|
|
|
import send_message as website_send_message
|
|
|
|
|
|
|
|
if not website_send_message(subject, message, sender):
|
|
|
|
return
|
|
|
|
|
|
|
|
# make lead / communication
|
|
|
|
from selling.doctype.lead.get_leads import add_sales_communication
|
|
|
|
add_sales_communication(subject or "Website Query", message, sender, sender,
|
2013-09-17 08:16:50 +00:00
|
|
|
mail=None, status=status)
|
|
|
|
|