2015-09-11 18:49:59 +05:30
|
|
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
|
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
|
2021-09-02 16:44:59 +05:30
|
|
|
import frappe
|
2015-09-11 18:49:59 +05:30
|
|
|
from frappe import _
|
2021-09-02 16:44:59 +05:30
|
|
|
|
2021-02-16 18:45:36 +05:30
|
|
|
from erpnext.e_commerce.doctype.e_commerce_settings.e_commerce_settings import show_attachments
|
2015-09-11 18:49:59 +05:30
|
|
|
|
2022-02-01 00:39:14 +05:30
|
|
|
|
2015-09-11 18:49:59 +05:30
|
|
|
def get_context(context):
|
|
|
|
context.no_cache = 1
|
2016-04-20 16:20:49 +05:30
|
|
|
context.show_sidebar = True
|
2015-09-11 18:49:59 +05:30
|
|
|
context.doc = frappe.get_doc(frappe.form_dict.doctype, frappe.form_dict.name)
|
2015-09-16 18:52:52 +05:30
|
|
|
if hasattr(context.doc, "set_indicator"):
|
|
|
|
context.doc.set_indicator()
|
|
|
|
|
2017-05-19 12:34:10 +02:00
|
|
|
if show_attachments():
|
2017-08-10 21:06:09 +05:30
|
|
|
context.attachments = get_attachments(frappe.form_dict.doctype, frappe.form_dict.name)
|
2017-05-19 12:34:10 +02:00
|
|
|
|
2015-09-11 18:49:59 +05:30
|
|
|
context.parents = frappe.form_dict.parents
|
2017-07-28 15:24:22 +02:00
|
|
|
context.title = frappe.form_dict.name
|
2022-03-28 18:52:46 +05:30
|
|
|
context.payment_ref = frappe.db.get_value(
|
|
|
|
"Payment Request", {"reference_name": frappe.form_dict.name}, "name"
|
|
|
|
)
|
2016-09-21 16:49:58 +05:30
|
|
|
|
2021-02-16 18:45:36 +05:30
|
|
|
context.enabled_checkout = frappe.get_doc("E Commerce Settings").enable_checkout
|
2016-09-21 16:49:58 +05:30
|
|
|
|
2022-03-28 18:52:46 +05:30
|
|
|
default_print_format = frappe.db.get_value(
|
|
|
|
"Property Setter",
|
|
|
|
dict(property="default_print_format", doc_type=frappe.form_dict.doctype),
|
|
|
|
"value",
|
|
|
|
)
|
2017-12-01 11:49:45 +01:00
|
|
|
if default_print_format:
|
|
|
|
context.print_format = default_print_format
|
|
|
|
else:
|
|
|
|
context.print_format = "Standard"
|
|
|
|
|
2016-10-12 10:31:08 +05:30
|
|
|
if not frappe.has_website_permission(context.doc):
|
2015-09-11 18:49:59 +05:30
|
|
|
frappe.throw(_("Not Permitted"), frappe.PermissionError)
|
2021-08-19 13:41:10 +05:30
|
|
|
|
2018-07-06 12:36:57 +05:30
|
|
|
# check for the loyalty program of the customer
|
2022-03-28 18:52:46 +05:30
|
|
|
customer_loyalty_program = frappe.db.get_value(
|
|
|
|
"Customer", context.doc.customer, "loyalty_program"
|
|
|
|
)
|
2018-07-06 12:36:57 +05:30
|
|
|
if customer_loyalty_program:
|
2021-09-02 16:44:59 +05:30
|
|
|
from erpnext.accounts.doctype.loyalty_program.loyalty_program import (
|
|
|
|
get_loyalty_program_details_with_points,
|
|
|
|
)
|
2022-03-28 18:52:46 +05:30
|
|
|
|
|
|
|
loyalty_program_details = get_loyalty_program_details_with_points(
|
|
|
|
context.doc.customer, customer_loyalty_program
|
|
|
|
)
|
2018-07-06 12:36:57 +05:30
|
|
|
context.available_loyalty_points = int(loyalty_program_details.get("loyalty_points"))
|
2017-05-19 12:34:10 +02:00
|
|
|
|
2022-09-28 15:40:07 +05:30
|
|
|
# show Make Purchase Invoice button based on permission
|
|
|
|
context.show_make_pi_button = frappe.has_permission("Purchase Invoice", "create")
|
|
|
|
|
2022-03-28 18:52:46 +05:30
|
|
|
|
2017-05-19 12:34:10 +02:00
|
|
|
def get_attachments(dt, dn):
|
2022-03-28 18:52:46 +05:30
|
|
|
return frappe.get_all(
|
|
|
|
"File",
|
|
|
|
fields=["name", "file_name", "file_url", "is_private"],
|
|
|
|
filters={"attached_to_name": dn, "attached_to_doctype": dt, "is_private": 0},
|
|
|
|
)
|