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 |
Rushabh Mehta | 3daa49a | 2014-10-21 16:16:30 +0530 | [diff] [blame] | 5 | |
| 6 | import frappe, json |
| 7 | from frappe import _ |
| 8 | from frappe.utils import cint, formatdate |
Anand Doshi | fb109ad | 2013-09-11 18:58:20 +0530 | [diff] [blame] | 9 | |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 10 | @frappe.whitelist(allow_guest=True) |
Anand Doshi | fb109ad | 2013-09-11 18:58:20 +0530 | [diff] [blame] | 11 | def send_message(subject="Website Query", message="", sender="", status="Open"): |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 12 | from frappe.templates.pages.contact import send_message as website_send_message |
Anand Doshi | 5d591eb | 2014-04-18 16:15:31 +0530 | [diff] [blame] | 13 | |
Rushabh Mehta | 5cdc8e5 | 2014-09-15 16:59:38 +0530 | [diff] [blame] | 14 | website_send_message(subject, message, sender) |
Anand Doshi | 5d591eb | 2014-04-18 16:15:31 +0530 | [diff] [blame] | 15 | |
Rushabh Mehta | 5cdc8e5 | 2014-09-15 16:59:38 +0530 | [diff] [blame] | 16 | 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 Mehta | 3daa49a | 2014-10-21 16:16:30 +0530 | [diff] [blame] | 24 | |
| 25 | def 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 | |
| 51 | def 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 | |
| 59 | def 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 } |