From df2783dbb03212146727486e3d3abf03df440d0b Mon Sep 17 00:00:00 2001 From: Saurabh Date: Wed, 6 Jan 2016 15:21:21 +0530 Subject: [PATCH] [enhance] i. facility to send PR email; ii. update cart, item view and order view; --- .../payment_request/payment_request.js | 33 ++++- .../payment_request/payment_request.json | 120 ++++++++++++------ .../payment_request/payment_request.py | 45 +++++-- .../payment_request/payment_request_list.js | 17 +++ erpnext/public/js/shopping_cart.js | 21 ++- .../doctype/sales_order/sales_order.js | 53 ++++---- .../doctype/sales_order/sales_order.py | 15 +++ erpnext/shopping_cart/utils.py | 12 +- erpnext/templates/generators/item.html | 14 +- erpnext/templates/pages/order.html | 17 +-- 10 files changed, 231 insertions(+), 116 deletions(-) create mode 100644 erpnext/accounts/doctype/payment_request/payment_request_list.js diff --git a/erpnext/accounts/doctype/payment_request/payment_request.js b/erpnext/accounts/doctype/payment_request/payment_request.js index 5d11fb5d9f..2665a13c0b 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.js +++ b/erpnext/accounts/doctype/payment_request/payment_request.js @@ -3,11 +3,30 @@ cur_frm.add_fetch("payment_gateway", "gateway", "gateway") cur_frm.add_fetch("payment_gateway", "message", "message") frappe.ui.form.on("Payment Request", "onload", function(frm, dt, dn){ - frappe.call({ - method:"erpnext.accounts.doctype.payment_request.payment_request.get_print_format_list", - args: {"ref_doctype": frm.doc.reference_doctype}, - callback:function(r){ - set_field_options("print_format", r.message["print_format"]) - } + if (frm.doc.reference_doctype) { + frappe.call({ + method:"erpnext.accounts.doctype.payment_request.payment_request.get_print_format_list", + args: {"ref_doctype": frm.doc.reference_doctype}, + callback:function(r){ + set_field_options("print_format", r.message["print_format"]) + } + }) + } +}) + +frappe.ui.form.on("Payment Request", "refresh", function(frm) { + frm.add_custom_button(__('Resend Payment Email'), function(){ + frappe.call({ + method:"erpnext.accounts.doctype.payment_request.payment_request.resend_payment_email", + args: {"docname": frm.doc.name}, + freeze: true, + freeze_message: __("Sending"), + callback:function(r){ + if(!r.exc) { + frappe.msgprint(__("Message Sent")) + } + } + }) }) -}) \ No newline at end of file +}) + diff --git a/erpnext/accounts/doctype/payment_request/payment_request.json b/erpnext/accounts/doctype/payment_request/payment_request.json index d69454cb0d..64d38b3c33 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.json +++ b/erpnext/accounts/doctype/payment_request/payment_request.json @@ -37,18 +37,17 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, - "fieldname": "currency", - "fieldtype": "Link", + "fieldname": "amount", + "fieldtype": "Currency", "hidden": 0, "ignore_user_permissions": 0, "in_filter": 0, "in_list_view": 0, - "label": "Currency", + "label": "Amount", "length": 0, "no_copy": 0, - "options": "Currency", "permlevel": 0, - "precision": "", + "precision": "2", "print_hide": 0, "print_hide_if_no_value": 0, "read_only": 0, @@ -62,17 +61,18 @@ "allow_on_submit": 0, "bold": 0, "collapsible": 0, - "fieldname": "amount", - "fieldtype": "Currency", + "fieldname": "currency", + "fieldtype": "Link", "hidden": 0, "ignore_user_permissions": 0, "in_filter": 0, "in_list_view": 0, - "label": "Amount", + "label": "Currency", "length": 0, "no_copy": 0, + "options": "Currency", "permlevel": 0, - "precision": "2", + "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, "read_only": 0, @@ -130,6 +130,55 @@ "set_only_once": 0, "unique": 0 }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "default": "Draft", + "fieldname": "status", + "fieldtype": "Select", + "hidden": 0, + "ignore_user_permissions": 0, + "in_filter": 0, + "in_list_view": 0, + "label": "Status", + "length": 0, + "no_copy": 0, + "options": "\nDraft\nInitiated\nPaid\nFailed\nCancelled", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 1, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "fieldname": "section_break_7", + "fieldtype": "Section Break", + "hidden": 0, + "ignore_user_permissions": 0, + "in_filter": 0, + "in_list_view": 0, + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, { "allow_on_submit": 0, "bold": 0, @@ -155,6 +204,29 @@ "set_only_once": 0, "unique": 0 }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "fieldname": "column_break_9", + "fieldtype": "Column Break", + "hidden": 0, + "ignore_user_permissions": 0, + "in_filter": 0, + "in_list_view": 0, + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, { "allow_on_submit": 0, "bold": 0, @@ -205,32 +277,6 @@ "set_only_once": 0, "unique": 0 }, - { - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "default": "", - "fieldname": "status", - "fieldtype": "Select", - "hidden": 0, - "ignore_user_permissions": 0, - "in_filter": 0, - "in_list_view": 0, - "label": "Status", - "length": 0, - "no_copy": 0, - "options": "\nInitiated\nPaid\nFailed\nCancelled", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, { "allow_on_submit": 0, "bold": 0, @@ -383,7 +429,7 @@ "collapsible": 0, "fieldname": "payment_url", "fieldtype": "Data", - "hidden": 0, + "hidden": 1, "ignore_user_permissions": 0, "in_filter": 0, "in_list_view": 0, @@ -509,7 +555,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2015-12-30 17:43:10.626907", + "modified": "2016-01-06 03:53:19.686537", "modified_by": "Administrator", "module": "Accounts", "name": "Payment Request", diff --git a/erpnext/accounts/doctype/payment_request/payment_request.py b/erpnext/accounts/doctype/payment_request/payment_request.py index 6d1ea97eb8..e45525ce60 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.py +++ b/erpnext/accounts/doctype/payment_request/payment_request.py @@ -15,6 +15,7 @@ from itertools import chain class PaymentRequest(Document): def validate(self): + self.validate_payment_gateway_account() self.validate_payment_request() self.validate_currency() @@ -27,6 +28,17 @@ class PaymentRequest(Document): ref_doc = frappe.get_doc(self.reference_doctype, self.reference_name) if ref_doc.currency != frappe.db.get_value("Account", self.payment_account, "account_currency"): frappe.throw(_("Transaction currency is not similar to Gateway Currency")) + + def validate_payment_gateway_account(self): + if not self.payment_gateway: + frappe.throw(_("Payment Gateway Account is not configured")) + + def validate_payment_gateway(self): + if self.gateway == "PayPal": + if not frappe.db.get_value("PayPal Settings", None, "api_username"): + if not frappe.conf.paypal_username: + frappe.throw(_("PayPal Settings missing")) + def on_submit(self): if not self.mute_email: @@ -36,8 +48,8 @@ class PaymentRequest(Document): self.make_communication_entry() def on_cancel(self): - pass - + self.set_cancelled() + def on_update_after_submit(self): pass @@ -127,20 +139,20 @@ def make_payment_request(**args): args = frappe._dict(args) ref_doc = get_reference_doc_details(args.dt, args.dn) - name, gateway, payment_account, message = get_gateway_details(args) + gateway_account = get_gateway_details(args) pr = frappe.new_doc("Payment Request") pr.update({ - "payment_gateway": name, - "gateway": gateway, - "payment_account": payment_account, + "payment_gateway": gateway_account.name, + "gateway": gateway_account.gateway, + "payment_account": gateway_account.payment_account, "currency": ref_doc.currency, "make_sales_invoice": args.cart or 0, "amount": get_amount(ref_doc, args.dt), "mute_email": args.mute_email or 0, "email_to": args.recipient_id or "", "subject": "Payment Request for %s"%args.dn, - "message": message, + "message": gateway_account.message, "reference_doctype": args.dt, "reference_name": args.dn }) @@ -181,11 +193,16 @@ def get_amount(ref_doc, dt): def get_gateway_details(args): """return gateway and payment account of default payment gateway""" if args.payemnt_gateway: - return frappe.db.get_value("Payment Gateway Account", args.payemnt_gateway, - ["name", "gateway", "payment_account", "message"]) - - return frappe.db.get_value("Payment Gateway Account", {"is_default": 1}, - ["name", "gateway", "payment_account", "message"]) + gateway_account = frappe.db.get_value("Payment Gateway Account", args.payemnt_gateway, + ["name", "gateway", "payment_account", "message"], as_dict=1) + + gateway_account = frappe.db.get_value("Payment Gateway Account", {"is_default": 1}, + ["name", "gateway", "payment_account", "message"], as_dict=1) + + if not gateway_account: + frappe.throw(_("Payment Gateway Account is not configured")) + + return gateway_account @frappe.whitelist() def get_print_format_list(ref_doctype): @@ -213,4 +230,8 @@ def generate_payment_request(name): frappe.respond_as_web_page(_("Invalid Payment Request"), _("Payment Request has been canceled by vendor"), success=False, http_status_code=frappe.ValidationError.http_status_code) + +@frappe.whitelist(allow_guest=True) +def resend_payment_email(docname): + return frappe.get_doc("Payment Request", docname).send_email() \ No newline at end of file diff --git a/erpnext/accounts/doctype/payment_request/payment_request_list.js b/erpnext/accounts/doctype/payment_request/payment_request_list.js new file mode 100644 index 0000000000..0caf1c2f7f --- /dev/null +++ b/erpnext/accounts/doctype/payment_request/payment_request_list.js @@ -0,0 +1,17 @@ +frappe.listview_settings['Payment Request'] = { + add_fields: ["status"], + get_indicator: function(doc) { + if(doc.status == "Draft") { + return [__("Draft"), "darkgrey", "status,=,Draft"]; + } + else if(doc.status == "Initiated") { + return [__("Initiated"), "green", "status,=,Initiated"]; + } + else if(doc.status == "Paid") { + return [__("Paid"), "blue", "status,=,Paid"]; + } + else if(doc.status == "Cancelled") { + return [__("Cancelled"), "orange", "status,=,Cancelled"]; + } + } +} diff --git a/erpnext/public/js/shopping_cart.js b/erpnext/public/js/shopping_cart.js index d437d74e96..63231d96d6 100644 --- a/erpnext/public/js/shopping_cart.js +++ b/erpnext/public/js/shopping_cart.js @@ -44,13 +44,22 @@ $.extend(shopping_cart, { set_cart_count: function() { var cart_count = getCookie("cart_count"); - var $cart = $('.dropdown [data-label="Cart"]'); - var $badge = $cart.find(".badge"); + var $cart = $('.cart-icon'); + var $badge = $cart.find("#cart-count"); + + if(cart_count === "0") { + $cart.css("display", "none"); + } + else { + $cart.css("display", "inline"); + } + + if(cart_count) { - if($badge.length === 0) { - var $badge = $('') - .prependTo($cart.find("a").addClass("badge-hover")); - } + // if($badge.length === 0) { +// var $badge = $('') +// .appendTo($cart.find("a").addClass("badge-hover")); +// } $badge.html(cart_count); } else { $badge.remove(); diff --git a/erpnext/selling/doctype/sales_order/sales_order.js b/erpnext/selling/doctype/sales_order/sales_order.js index b7213745b8..a6ec617646 100644 --- a/erpnext/selling/doctype/sales_order/sales_order.js +++ b/erpnext/selling/doctype/sales_order/sales_order.js @@ -41,46 +41,47 @@ erpnext.selling.SalesOrderController = erpnext.selling.SellingController.extend( } } - // material request - if(!doc.order_type || ["Sales", "Shopping Cart"].indexOf(doc.order_type)!==-1 - && flt(doc.per_delivered, 2) < 100) { - cur_frm.add_custom_button(__('Material Request'), this.make_material_request); - } - - // make purchase order - if(flt(doc.per_delivered, 2) < 100 && allow_purchase) { - cur_frm.add_custom_button(__('Purchase Order'), cur_frm.cscript.make_purchase_order); - } - - if(flt(doc.per_billed)==0) { - cur_frm.add_custom_button(__('Payment'), cur_frm.cscript.make_bank_entry); - cur_frm.add_custom_button(__('Make Payment Request'), this.make_payment_request); - } - if (this.frm.has_perm("submit")) { // stop if(flt(doc.per_delivered, 2) < 100 || flt(doc.per_billed) < 100) { - cur_frm.add_custom_button(__('Stop'), this.stop_sales_order) + cur_frm.add_custom_button(__('Stop'), this.stop_sales_order, __("Status")) } - cur_frm.add_custom_button(__('Close'), this.close_sales_order) - } - - // maintenance - if(flt(doc.per_delivered, 2) < 100 && ["Sales", "Shopping Cart"].indexOf(doc.order_type)===-1) { - cur_frm.add_custom_button(__('Maint. Visit'), this.make_maintenance_visit); - cur_frm.add_custom_button(__('Maint. Schedule'), this.make_maintenance_schedule); + cur_frm.add_custom_button(__('Close'), this.close_sales_order, __("Status")) } // delivery note if(flt(doc.per_delivered, 2) < 100 && ["Sales", "Shopping Cart"].indexOf(doc.order_type)!==-1 && allow_delivery) { - cur_frm.add_custom_button(__('Delivery'), this.make_delivery_note).addClass("btn-primary"); + cur_frm.add_custom_button(__('Delivery'), this.make_delivery_note, __("Make")); + cur_frm.page.set_inner_btn_group_as_primary(__("Make")); } // sales invoice if(flt(doc.per_billed, 2) < 100) { - cur_frm.add_custom_button(__('Invoice'), this.make_sales_invoice).addClass("btn-primary"); + cur_frm.add_custom_button(__('Invoice'), this.make_sales_invoice, __("Make")); + } + + // material request + if(!doc.order_type || ["Sales", "Shopping Cart"].indexOf(doc.order_type)!==-1 + && flt(doc.per_delivered, 2) < 100) { + cur_frm.add_custom_button(__('Material Request'), this.make_material_request, __("Make")); + } + + // make purchase order + if(flt(doc.per_delivered, 2) < 100 && allow_purchase) { + cur_frm.add_custom_button(__('Purchase Order'), cur_frm.cscript.make_purchase_order, __("Make")); + } + + if(flt(doc.per_billed)==0) { + cur_frm.add_custom_button(__('Payment Request'), this.make_payment_request, __("Make")); + cur_frm.add_custom_button(__('Payment'), cur_frm.cscript.make_bank_entry, __("Make")); + } + + // maintenance + if(flt(doc.per_delivered, 2) < 100 && ["Sales", "Shopping Cart"].indexOf(doc.order_type)===-1) { + cur_frm.add_custom_button(__('Maintenance Visit'), this.make_maintenance_visit, __("Make")); + cur_frm.add_custom_button(__('Maintenance Schedule'), this.make_maintenance_schedule, __("Make")); } diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py index dc21bd58f0..8bc96e666b 100644 --- a/erpnext/selling/doctype/sales_order/sales_order.py +++ b/erpnext/selling/doctype/sales_order/sales_order.py @@ -288,11 +288,26 @@ class SalesOrder(SellingController): frappe.db.set_value("Sales Order", self.name, "per_delivered", flt(delivered_qty/tot_qty) * 100, update_modified=False) + + def set_indicator(self): + """Set indicator for portal""" + if self.per_billed < 100 and self.per_delivered < 100: + self.indicator_color = "orange" + self.indicator_title = _("Not Paid and Not Delivered") + + elif self.per_billed == 100 and self.per_delivered < 100: + self.indicator_color = "orange" + self.indicator_title = _("Paid and Not Delivered") + else: + self.indicator_color = "green" + self.indicator_title = _("Paid") + def get_list_context(context=None): from erpnext.controllers.website_list_for_contact import get_list_context list_context = get_list_context(context) list_context["title"] = _("My Orders") + list_context["parents"] = [{"title": _("My Account"), "name": "me"}] return list_context @frappe.whitelist() diff --git a/erpnext/shopping_cart/utils.py b/erpnext/shopping_cart/utils.py index 7794a8fb9f..79c67392f8 100644 --- a/erpnext/shopping_cart/utils.py +++ b/erpnext/shopping_cart/utils.py @@ -28,12 +28,12 @@ def update_website_context(context): cart_enabled = is_cart_enabled() context["shopping_cart_enabled"] = cart_enabled - if cart_enabled: - post_login = [ - {"label": _("Cart"), "url": "cart", "class": "cart-count"}, - {"class": "divider"} - ] - context["post_login"] = post_login + context.get("post_login", []) + # if cart_enabled: +# post_login = [ +# {"label": _("Cart"), "url": "cart", "class": "cart-count"}, +# {"class": "divider"} +# ] +# context["post_login"] = post_login + context.get("post_login", []) def update_my_account_context(context): if is_cart_enabled(): diff --git a/erpnext/templates/generators/item.html b/erpnext/templates/generators/item.html index dc48e0df12..b62f30640a 100644 --- a/erpnext/templates/generators/item.html +++ b/erpnext/templates/generators/item.html @@ -71,18 +71,8 @@ style="display: none; padding-left: 0px; padding-right: 0px; padding-top: 10px;"> -
- -
-
- -
-
- - {{ _("View Cart") }} -
+
+ {{ _("Item added to cart") }}
diff --git a/erpnext/templates/pages/order.html b/erpnext/templates/pages/order.html index 36e23a5d3a..3bd6ad30d0 100644 --- a/erpnext/templates/pages/order.html +++ b/erpnext/templates/pages/order.html @@ -1,12 +1,14 @@ {% extends "templates/web.html" %} {% block header %} -

- {{ doc.name }} -

+

{{ doc.name }}

{% endblock %} +{% block breadcrumbs %} + {% include "templates/includes/breadcrumbs.html" %} +{% endblock %} + {% block style %}