blob: aefa3151d61a17cdbc55d61e4d73ebac48db5c37 [file] [log] [blame]
rohitwaghchaurea1064a62016-03-03 14:00:35 +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
6from frappe import _
7
8def get_context(context):
9 context.no_cache = 1
10 context.doc = frappe.get_doc(frappe.form_dict.doctype, frappe.form_dict.name)
11 context.parents = frappe.form_dict.parents
12 context.doc.supplier = get_supplier()
13 unauthrized_user(context.doc.supplier)
14 context["title"] = frappe.form_dict.name
15
16def unauthrized_user(supplier):
17 status = check_supplier_has_docname_access(supplier)
18 if status == False:
19 frappe.throw(_("Not Permitted"), frappe.PermissionError)
20
21def get_supplier():
22 from erpnext.shopping_cart.utils import check_customer_or_supplier
23 key, parties = check_customer_or_supplier()
24 return parties[0] if key == 'Supplier' else ''
25
26def check_supplier_has_docname_access(supplier):
27 status = True
Rushabh Mehta7a1b5da2016-03-29 16:04:25 +053028 if frappe.form_dict.name not in frappe.db.sql_list("""select parent from `tabRequest for Quotation Supplier`
rohitwaghchaurea1064a62016-03-03 14:00:35 +053029 where supplier = '{supplier}'""".format(supplier=supplier)):
30 status = False
31 return status