blob: 59df433804cf2946d8d91c5e61e71e6b68438cc0 [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
Rushabh Mehta156ce602015-09-11 18:49:59 +05305
Chillar Anand915b3432021-09-02 16:44:59 +05306import frappe
Rushabh Mehta156ce602015-09-11 18:49:59 +05307from frappe import _
Chillar Anand915b3432021-09-02 16:44:59 +05308
marinationeef9cf12021-02-16 18:45:36 +05309from erpnext.e_commerce.doctype.e_commerce_settings.e_commerce_settings import show_attachments
Rushabh Mehta156ce602015-09-11 18:49:59 +053010
11def get_context(context):
12 context.no_cache = 1
Kanchan Chauhan11638ba2016-04-20 16:20:49 +053013 context.show_sidebar = True
Rushabh Mehta156ce602015-09-11 18:49:59 +053014 context.doc = frappe.get_doc(frappe.form_dict.doctype, frappe.form_dict.name)
Rushabh Mehta3d766862015-09-16 18:52:52 +053015 if hasattr(context.doc, "set_indicator"):
16 context.doc.set_indicator()
17
Charles-Henri Decultot2de1cd32017-05-19 12:34:10 +020018 if show_attachments():
Rushabh Mehtadbb51542017-08-10 21:06:09 +053019 context.attachments = get_attachments(frappe.form_dict.doctype, frappe.form_dict.name)
Charles-Henri Decultot2de1cd32017-05-19 12:34:10 +020020
Rushabh Mehta156ce602015-09-11 18:49:59 +053021 context.parents = frappe.form_dict.parents
Britlog4c7709e2017-07-28 15:24:22 +020022 context.title = frappe.form_dict.name
Rushabh Mehta257bbbe2016-10-12 10:31:08 +053023 context.payment_ref = frappe.db.get_value("Payment Request",
Saurabh0a0c7872016-01-04 17:37:54 +053024 {"reference_name": frappe.form_dict.name}, "name")
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
Charles-Henri Decultote90a1ca2017-12-01 11:49:45 +010028 default_print_format = frappe.db.get_value('Property Setter', dict(property='default_print_format', doc_type=frappe.form_dict.doctype), "value")
29 if default_print_format:
30 context.print_format = default_print_format
31 else:
32 context.print_format = "Standard"
33
Rushabh Mehta257bbbe2016-10-12 10:31:08 +053034 if not frappe.has_website_permission(context.doc):
Rushabh Mehta156ce602015-09-11 18:49:59 +053035 frappe.throw(_("Not Permitted"), frappe.PermissionError)
Ankush Menat4551d7d2021-08-19 13:41:10 +053036
Manas Solankida486ee2018-07-06 12:36:57 +053037 # check for the loyalty program of the customer
Ankush Menat4551d7d2021-08-19 13:41:10 +053038 customer_loyalty_program = frappe.db.get_value("Customer", context.doc.customer, "loyalty_program")
Manas Solankida486ee2018-07-06 12:36:57 +053039 if customer_loyalty_program:
Chillar Anand915b3432021-09-02 16:44:59 +053040 from erpnext.accounts.doctype.loyalty_program.loyalty_program import (
41 get_loyalty_program_details_with_points,
42 )
Zarrar7f8024c2018-08-01 17:45:05 +053043 loyalty_program_details = get_loyalty_program_details_with_points(context.doc.customer, customer_loyalty_program)
Manas Solankida486ee2018-07-06 12:36:57 +053044 context.available_loyalty_points = int(loyalty_program_details.get("loyalty_points"))
Charles-Henri Decultot2de1cd32017-05-19 12:34:10 +020045
46def get_attachments(dt, dn):
Rushabh Mehtadbb51542017-08-10 21:06:09 +053047 return frappe.get_all("File",
48 fields=["name", "file_name", "file_url", "is_private"],
49 filters = {"attached_to_name": dn, "attached_to_doctype": dt, "is_private":0})