blob: 110eb57504b1b561213271c36970178108f1f26c [file] [log] [blame]
Rushabh Mehta156ce602015-09-11 18:49:59 +05301# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
2# License: GNU General Public License v3. See license.txt
3
4from __future__ import unicode_literals
5import frappe
6
7from frappe import _
Charles-Henri Decultot2de1cd32017-05-19 12:34:10 +02008from erpnext.shopping_cart.doctype.shopping_cart_settings.shopping_cart_settings import show_attachments
Rushabh Mehta156ce602015-09-11 18:49:59 +05309
10def get_context(context):
11 context.no_cache = 1
Kanchan Chauhan11638ba2016-04-20 16:20:49 +053012 context.show_sidebar = True
Rushabh Mehta156ce602015-09-11 18:49:59 +053013 context.doc = frappe.get_doc(frappe.form_dict.doctype, frappe.form_dict.name)
Rushabh Mehta3d766862015-09-16 18:52:52 +053014 if hasattr(context.doc, "set_indicator"):
15 context.doc.set_indicator()
16
Charles-Henri Decultot2de1cd32017-05-19 12:34:10 +020017 if show_attachments():
Rushabh Mehtadbb51542017-08-10 21:06:09 +053018 context.attachments = get_attachments(frappe.form_dict.doctype, frappe.form_dict.name)
Charles-Henri Decultot2de1cd32017-05-19 12:34:10 +020019
Rushabh Mehta156ce602015-09-11 18:49:59 +053020 context.parents = frappe.form_dict.parents
Britlog4c7709e2017-07-28 15:24:22 +020021 context.title = frappe.form_dict.name
Rushabh Mehta257bbbe2016-10-12 10:31:08 +053022 context.payment_ref = frappe.db.get_value("Payment Request",
Saurabh0a0c7872016-01-04 17:37:54 +053023 {"reference_name": frappe.form_dict.name}, "name")
Rohit Waghchaure21499e82016-09-21 16:49:58 +053024
Saurabh883cc042016-01-21 15:43:07 +053025 context.enabled_checkout = frappe.get_doc("Shopping Cart Settings").enable_checkout
Rohit Waghchaure21499e82016-09-21 16:49:58 +053026
Rushabh Mehta257bbbe2016-10-12 10:31:08 +053027 if not frappe.has_website_permission(context.doc):
Rushabh Mehta156ce602015-09-11 18:49:59 +053028 frappe.throw(_("Not Permitted"), frappe.PermissionError)
Charles-Henri Decultot2de1cd32017-05-19 12:34:10 +020029
30def get_attachments(dt, dn):
Rushabh Mehtadbb51542017-08-10 21:06:09 +053031 return frappe.get_all("File",
32 fields=["name", "file_name", "file_url", "is_private"],
33 filters = {"attached_to_name": dn, "attached_to_doctype": dt, "is_private":0})