2016-03-03 08:30:35 +00:00
|
|
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
|
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2016-03-03 08:30:35 +00:00
|
|
|
import frappe
|
|
|
|
from frappe import _
|
2016-10-03 13:35:18 +00:00
|
|
|
from frappe.utils import formatdate
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2019-08-12 06:21:27 +00:00
|
|
|
from erpnext.controllers.website_list_for_contact import get_customers_suppliers
|
2016-03-03 08:30:35 +00:00
|
|
|
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2016-03-03 08:30:35 +00:00
|
|
|
def get_context(context):
|
|
|
|
context.no_cache = 1
|
2016-06-28 11:41:32 +00:00
|
|
|
context.show_sidebar = True
|
2016-03-03 08:30:35 +00:00
|
|
|
context.doc = frappe.get_doc(frappe.form_dict.doctype, frappe.form_dict.name)
|
|
|
|
context.parents = frappe.form_dict.parents
|
|
|
|
context.doc.supplier = get_supplier()
|
2016-10-03 13:35:18 +00:00
|
|
|
context.doc.rfq_links = get_link_quotation(context.doc.supplier, context.doc.name)
|
2016-03-30 07:54:42 +00:00
|
|
|
unauthorized_user(context.doc.supplier)
|
2016-04-04 13:19:26 +00:00
|
|
|
update_supplier_details(context)
|
2016-03-03 08:30:35 +00:00
|
|
|
context["title"] = frappe.form_dict.name
|
|
|
|
|
2022-03-28 13:22:46 +00:00
|
|
|
|
2016-03-03 08:30:35 +00:00
|
|
|
def get_supplier():
|
2016-03-30 07:54:42 +00:00
|
|
|
doctype = frappe.form_dict.doctype
|
2022-03-28 13:22:46 +00:00
|
|
|
parties_doctype = (
|
|
|
|
"Request for Quotation Supplier" if doctype == "Request for Quotation" else doctype
|
|
|
|
)
|
2016-03-30 07:54:42 +00:00
|
|
|
customers, suppliers = get_customers_suppliers(parties_doctype, frappe.session.user)
|
2019-08-12 06:21:27 +00:00
|
|
|
|
2022-03-28 13:22:46 +00:00
|
|
|
return suppliers[0] if suppliers else ""
|
|
|
|
|
2016-03-03 08:30:35 +00:00
|
|
|
|
|
|
|
def check_supplier_has_docname_access(supplier):
|
|
|
|
status = True
|
2022-03-28 13:22:46 +00:00
|
|
|
if frappe.form_dict.name not in frappe.db.sql_list(
|
|
|
|
"""select parent from `tabRequest for Quotation Supplier`
|
|
|
|
where supplier = %s""",
|
|
|
|
(supplier,),
|
|
|
|
):
|
2016-03-03 08:30:35 +00:00
|
|
|
status = False
|
|
|
|
return status
|
2016-03-30 07:54:42 +00:00
|
|
|
|
2022-03-28 13:22:46 +00:00
|
|
|
|
2016-03-30 07:54:42 +00:00
|
|
|
def unauthorized_user(supplier):
|
2016-04-04 13:19:26 +00:00
|
|
|
status = check_supplier_has_docname_access(supplier) or False
|
2016-03-30 07:54:42 +00:00
|
|
|
if status == False:
|
|
|
|
frappe.throw(_("Not Permitted"), frappe.PermissionError)
|
|
|
|
|
2022-03-28 13:22:46 +00:00
|
|
|
|
2016-03-30 07:54:42 +00:00
|
|
|
def update_supplier_details(context):
|
|
|
|
supplier_doc = frappe.get_doc("Supplier", context.doc.supplier)
|
2022-03-28 13:22:46 +00:00
|
|
|
context.doc.currency = supplier_doc.default_currency or frappe.get_cached_value(
|
|
|
|
"Company", context.doc.company, "default_currency"
|
|
|
|
)
|
|
|
|
context.doc.currency_symbol = frappe.db.get_value(
|
|
|
|
"Currency", context.doc.currency, "symbol", cache=True
|
|
|
|
)
|
|
|
|
context.doc.number_format = frappe.db.get_value(
|
|
|
|
"Currency", context.doc.currency, "number_format", cache=True
|
|
|
|
)
|
|
|
|
context.doc.buying_price_list = supplier_doc.default_price_list or ""
|
|
|
|
|
2016-10-03 13:35:18 +00:00
|
|
|
|
|
|
|
def get_link_quotation(supplier, rfq):
|
2022-03-28 13:22:46 +00:00
|
|
|
quotation = frappe.db.sql(
|
|
|
|
""" select distinct `tabSupplier Quotation Item`.parent as name,
|
2016-10-03 13:35:18 +00:00
|
|
|
`tabSupplier Quotation`.status, `tabSupplier Quotation`.transaction_date from
|
|
|
|
`tabSupplier Quotation Item`, `tabSupplier Quotation` where `tabSupplier Quotation`.docstatus < 2 and
|
|
|
|
`tabSupplier Quotation Item`.request_for_quotation =%(name)s and
|
|
|
|
`tabSupplier Quotation Item`.parent = `tabSupplier Quotation`.name and
|
|
|
|
`tabSupplier Quotation`.supplier = %(supplier)s order by `tabSupplier Quotation`.creation desc""",
|
2022-03-28 13:22:46 +00:00
|
|
|
{"name": rfq, "supplier": supplier},
|
|
|
|
as_dict=1,
|
|
|
|
)
|
2016-10-03 13:35:18 +00:00
|
|
|
|
|
|
|
for data in quotation:
|
|
|
|
data.transaction_date = formatdate(data.transaction_date)
|
|
|
|
|
|
|
|
return quotation or None
|