blob: 3e6d57a02b1c6030ac8f33feb941ae050d5e0d45 [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
Chillar Anand915b3432021-09-02 16:44:59 +05304import frappe
Rushabh Mehta156ce602015-09-11 18:49:59 +05305from frappe import _
Chillar Anand915b3432021-09-02 16:44:59 +05306
marinationeef9cf12021-02-16 18:45:36 +05307from erpnext.e_commerce.doctype.e_commerce_settings.e_commerce_settings import show_attachments
Rushabh Mehta156ce602015-09-11 18:49:59 +05308
marination9fb61ef2022-02-01 00:39:14 +05309
Rushabh Mehta156ce602015-09-11 18:49:59 +053010def 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
Ankush Menat494bd9e2022-03-28 18:52:46 +053022 context.payment_ref = frappe.db.get_value(
23 "Payment Request", {"reference_name": frappe.form_dict.name}, "name"
24 )
Rohit Waghchaure21499e82016-09-21 16:49:58 +053025
marinationeef9cf12021-02-16 18:45:36 +053026 context.enabled_checkout = frappe.get_doc("E Commerce Settings").enable_checkout
Rohit Waghchaure21499e82016-09-21 16:49:58 +053027
Ankush Menat494bd9e2022-03-28 18:52:46 +053028 default_print_format = frappe.db.get_value(
29 "Property Setter",
30 dict(property="default_print_format", doc_type=frappe.form_dict.doctype),
31 "value",
32 )
Charles-Henri Decultote90a1ca2017-12-01 11:49:45 +010033 if default_print_format:
34 context.print_format = default_print_format
35 else:
36 context.print_format = "Standard"
37
Rushabh Mehta257bbbe2016-10-12 10:31:08 +053038 if not frappe.has_website_permission(context.doc):
Rushabh Mehta156ce602015-09-11 18:49:59 +053039 frappe.throw(_("Not Permitted"), frappe.PermissionError)
Ankush Menat4551d7d2021-08-19 13:41:10 +053040
Manas Solankida486ee2018-07-06 12:36:57 +053041 # check for the loyalty program of the customer
Ankush Menat494bd9e2022-03-28 18:52:46 +053042 customer_loyalty_program = frappe.db.get_value(
43 "Customer", context.doc.customer, "loyalty_program"
44 )
Manas Solankida486ee2018-07-06 12:36:57 +053045 if customer_loyalty_program:
Chillar Anand915b3432021-09-02 16:44:59 +053046 from erpnext.accounts.doctype.loyalty_program.loyalty_program import (
47 get_loyalty_program_details_with_points,
48 )
Ankush Menat494bd9e2022-03-28 18:52:46 +053049
50 loyalty_program_details = get_loyalty_program_details_with_points(
51 context.doc.customer, customer_loyalty_program
52 )
Manas Solankida486ee2018-07-06 12:36:57 +053053 context.available_loyalty_points = int(loyalty_program_details.get("loyalty_points"))
Charles-Henri Decultot2de1cd32017-05-19 12:34:10 +020054
Ankush Menat494bd9e2022-03-28 18:52:46 +053055
Charles-Henri Decultot2de1cd32017-05-19 12:34:10 +020056def get_attachments(dt, dn):
Ankush Menat494bd9e2022-03-28 18:52:46 +053057 return frappe.get_all(
58 "File",
59 fields=["name", "file_name", "file_url", "is_private"],
60 filters={"attached_to_name": dn, "attached_to_doctype": dt, "is_private": 0},
61 )