Rushabh Mehta | ad45e31 | 2013-11-20 12:59:58 +0530 | [diff] [blame] | 1 | # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors |
Anand Doshi | 330dae9 | 2013-09-10 13:46:15 +0530 | [diff] [blame] | 2 | # License: GNU General Public License v3. See license.txt |
| 3 | |
| 4 | from __future__ import unicode_literals |
| 5 | import webnotes |
| 6 | from webnotes.utils import cint, formatdate |
| 7 | import json |
| 8 | |
Anand Doshi | 1be5bb7 | 2013-09-12 15:25:38 +0530 | [diff] [blame] | 9 | def get_transaction_list(doctype, start, additional_fields=None): |
Anand Doshi | 330dae9 | 2013-09-10 13:46:15 +0530 | [diff] [blame] | 10 | # find customer id |
| 11 | customer = webnotes.conn.get_value("Contact", {"email_id": webnotes.session.user}, |
| 12 | "customer") |
Anand Doshi | 1be5bb7 | 2013-09-12 15:25:38 +0530 | [diff] [blame] | 13 | |
Anand Doshi | 330dae9 | 2013-09-10 13:46:15 +0530 | [diff] [blame] | 14 | if customer: |
Anand Doshi | 1be5bb7 | 2013-09-12 15:25:38 +0530 | [diff] [blame] | 15 | 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 Doshi | 330dae9 | 2013-09-10 13:46:15 +0530 | [diff] [blame] | 22 | from `tab%s` where customer=%s and docstatus=1 |
| 23 | order by creation desc |
Anand Doshi | 1be5bb7 | 2013-09-12 15:25:38 +0530 | [diff] [blame] | 24 | limit %s, 20""" % (additional_fields, doctype, "%s", "%s"), |
| 25 | (customer, cint(start)), as_dict=True) |
Anand Doshi | 330dae9 | 2013-09-10 13:46:15 +0530 | [diff] [blame] | 26 | for doc in transactions: |
Anand Doshi | 1be5bb7 | 2013-09-12 15:25:38 +0530 | [diff] [blame] | 27 | 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 Doshi | 330dae9 | 2013-09-10 13:46:15 +0530 | [diff] [blame] | 30 | doc.creation = formatdate(doc.creation) |
| 31 | return transactions |
| 32 | else: |
| 33 | return [] |
| 34 | |
| 35 | def 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 | |
| 43 | def 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 Doshi | fb109ad | 2013-09-11 18:58:20 +0530 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | @webnotes.whitelist(allow_guest=True) |
| 61 | def 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 |
Anand Doshi | df01980 | 2013-12-04 16:27:30 +0530 | [diff] [blame] | 67 | |
| 68 | if subject=="Support": |
| 69 | # create support ticket |
| 70 | from support.doctype.support_ticket.get_support_mails import add_support_communication |
| 71 | add_support_communication(subject, message, sender, mail=None) |
| 72 | else: |
| 73 | # make lead / communication |
| 74 | from selling.doctype.lead.get_leads import add_sales_communication |
| 75 | add_sales_communication(subject or "Website Query", message, sender, sender, |
| 76 | mail=None, status=status) |
Anand Doshi | 619ed5e | 2013-09-17 13:46:50 +0530 | [diff] [blame] | 77 | |