Rushabh Mehta | 156ce60 | 2015-09-11 18:49:59 +0530 | [diff] [blame] | 1 | # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors |
| 2 | # License: GNU General Public License v3. See license.txt |
| 3 | |
Rushabh Mehta | 156ce60 | 2015-09-11 18:49:59 +0530 | [diff] [blame] | 4 | |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 5 | import frappe |
Rushabh Mehta | 156ce60 | 2015-09-11 18:49:59 +0530 | [diff] [blame] | 6 | from frappe import _ |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 7 | |
| 8 | from erpnext.shopping_cart.doctype.shopping_cart_settings.shopping_cart_settings import ( |
| 9 | show_attachments, |
| 10 | ) |
| 11 | |
Rushabh Mehta | 156ce60 | 2015-09-11 18:49:59 +0530 | [diff] [blame] | 12 | |
| 13 | def get_context(context): |
| 14 | context.no_cache = 1 |
Kanchan Chauhan | 11638ba | 2016-04-20 16:20:49 +0530 | [diff] [blame] | 15 | context.show_sidebar = True |
Rushabh Mehta | 156ce60 | 2015-09-11 18:49:59 +0530 | [diff] [blame] | 16 | context.doc = frappe.get_doc(frappe.form_dict.doctype, frappe.form_dict.name) |
Rushabh Mehta | 3d76686 | 2015-09-16 18:52:52 +0530 | [diff] [blame] | 17 | if hasattr(context.doc, "set_indicator"): |
| 18 | context.doc.set_indicator() |
| 19 | |
Charles-Henri Decultot | 2de1cd3 | 2017-05-19 12:34:10 +0200 | [diff] [blame] | 20 | if show_attachments(): |
Rushabh Mehta | dbb5154 | 2017-08-10 21:06:09 +0530 | [diff] [blame] | 21 | context.attachments = get_attachments(frappe.form_dict.doctype, frappe.form_dict.name) |
Charles-Henri Decultot | 2de1cd3 | 2017-05-19 12:34:10 +0200 | [diff] [blame] | 22 | |
Rushabh Mehta | 156ce60 | 2015-09-11 18:49:59 +0530 | [diff] [blame] | 23 | context.parents = frappe.form_dict.parents |
Britlog | 4c7709e | 2017-07-28 15:24:22 +0200 | [diff] [blame] | 24 | context.title = frappe.form_dict.name |
Rushabh Mehta | 257bbbe | 2016-10-12 10:31:08 +0530 | [diff] [blame] | 25 | context.payment_ref = frappe.db.get_value("Payment Request", |
Saurabh | 0a0c787 | 2016-01-04 17:37:54 +0530 | [diff] [blame] | 26 | {"reference_name": frappe.form_dict.name}, "name") |
Rohit Waghchaure | 21499e8 | 2016-09-21 16:49:58 +0530 | [diff] [blame] | 27 | |
Saurabh | 883cc04 | 2016-01-21 15:43:07 +0530 | [diff] [blame] | 28 | context.enabled_checkout = frappe.get_doc("Shopping Cart Settings").enable_checkout |
Rohit Waghchaure | 21499e8 | 2016-09-21 16:49:58 +0530 | [diff] [blame] | 29 | |
Charles-Henri Decultot | e90a1ca | 2017-12-01 11:49:45 +0100 | [diff] [blame] | 30 | default_print_format = frappe.db.get_value('Property Setter', dict(property='default_print_format', doc_type=frappe.form_dict.doctype), "value") |
| 31 | if default_print_format: |
| 32 | context.print_format = default_print_format |
| 33 | else: |
| 34 | context.print_format = "Standard" |
| 35 | |
Rushabh Mehta | 257bbbe | 2016-10-12 10:31:08 +0530 | [diff] [blame] | 36 | if not frappe.has_website_permission(context.doc): |
Rushabh Mehta | 156ce60 | 2015-09-11 18:49:59 +0530 | [diff] [blame] | 37 | frappe.throw(_("Not Permitted"), frappe.PermissionError) |
Ankush Menat | 4551d7d | 2021-08-19 13:41:10 +0530 | [diff] [blame] | 38 | |
Manas Solanki | da486ee | 2018-07-06 12:36:57 +0530 | [diff] [blame] | 39 | # check for the loyalty program of the customer |
Ankush Menat | 4551d7d | 2021-08-19 13:41:10 +0530 | [diff] [blame] | 40 | customer_loyalty_program = frappe.db.get_value("Customer", context.doc.customer, "loyalty_program") |
Manas Solanki | da486ee | 2018-07-06 12:36:57 +0530 | [diff] [blame] | 41 | if customer_loyalty_program: |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 42 | from erpnext.accounts.doctype.loyalty_program.loyalty_program import ( |
| 43 | get_loyalty_program_details_with_points, |
| 44 | ) |
Zarrar | 7f8024c | 2018-08-01 17:45:05 +0530 | [diff] [blame] | 45 | loyalty_program_details = get_loyalty_program_details_with_points(context.doc.customer, customer_loyalty_program) |
Manas Solanki | da486ee | 2018-07-06 12:36:57 +0530 | [diff] [blame] | 46 | context.available_loyalty_points = int(loyalty_program_details.get("loyalty_points")) |
Charles-Henri Decultot | 2de1cd3 | 2017-05-19 12:34:10 +0200 | [diff] [blame] | 47 | |
| 48 | def get_attachments(dt, dn): |
Rushabh Mehta | dbb5154 | 2017-08-10 21:06:09 +0530 | [diff] [blame] | 49 | return frappe.get_all("File", |
| 50 | fields=["name", "file_name", "file_url", "is_private"], |
| 51 | filters = {"attached_to_name": dn, "attached_to_doctype": dt, "is_private":0}) |