Revert "[cleanup] PayPal payment UX and moved related methods to hooks of respective apps"

This commit is contained in:
Anand Doshi 2016-03-23 11:59:24 +05:30
parent eec21d041c
commit a75fe1a4c3
5 changed files with 14 additions and 120 deletions

View File

@ -1,62 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
from __future__ import unicode_literals
import frappe
from frappe import _
from erpnext.setup.setup_wizard.setup_wizard import create_bank_account
def create_payment_gateway_and_account(doc, method):
"""Called via hook on saving Paypal Settings of Paypal Integration app"""
create_payment_gateway()
create_payment_gateway_account()
def create_payment_gateway():
# NOTE: we don't translate Payment Gateway name because it is an internal doctype
if not frappe.db.exists("Payment Gateway", "PayPal"):
payment_gateway = frappe.get_doc({
"doctype": "Payment Gateway",
"gateway": "PayPal"
})
payment_gateway.insert(ignore_permissions=True)
def create_payment_gateway_account():
company = frappe.db.get_value("Global Defaults", None, "default_company")
if not company:
return
# NOTE: we translate Payment Gateway account name because that is going to be used by the end user
bank_account = frappe.db.get_value("Account", {"account_name": _("PayPal"), "company": company},
["name", 'account_currency'], as_dict=1)
if not bank_account:
# check for untranslated one
bank_account = frappe.db.get_value("Account", {"account_name": "PayPal", "company": company},
["name", 'account_currency'], as_dict=1)
if not bank_account:
# try creating one
bank_account = create_bank_account({"company_name": company, "bank_account": _("PayPal")})
if not bank_account:
frappe.msgprint(_("Payment Gateway Account not created, please create one manually."))
return
# if payment gateway account exists, return
if frappe.db.exists("Payment Gateway Account",
{"payment_gateway": "PayPal", "currency": bank_account.account_currency}):
return
try:
frappe.get_doc({
"doctype": "Payment Gateway Account",
"is_default": 1,
"payment_gateway": "PayPal",
"payment_account": bank_account.name,
"currency": bank_account.account_currency
}).insert(ignore_permissions=True)
except frappe.DuplicateEntryError:
# already exists, due to a reinstall?
pass

View File

@ -117,15 +117,6 @@ doc_events = {
},
"Address": {
"validate": "erpnext.shopping_cart.cart.set_customer_in_address"
},
# From Paypal Integration app
"PayPal Settings": {
"on_update": "erpnext.accounts.doctype.payment_gateway.fixtures.paypal.create_payment_gateway_and_account"
},
"Paypal Express Payment": {
"on_update": "erpnext.shopping_cart.cart.set_redirect"
}
}

View File

@ -5,7 +5,7 @@ from __future__ import unicode_literals
import frappe
from frappe import throw, _
import frappe.defaults
from frappe.utils import cint, flt, get_fullname, cstr, get_url
from frappe.utils import cint, flt, get_fullname, cstr
from erpnext.utilities.doctype.address.address import get_address_display
from erpnext.shopping_cart.doctype.shopping_cart_settings.shopping_cart_settings import get_shopping_cart_settings
from frappe.utils.nestedset import get_root_of
@ -437,38 +437,3 @@ def get_address_territory(address_name):
break
return territory
def set_redirect(paypal_express_payment, method):
"""Set Paypal Express Payment.flags.redirect_to on status change. Called via hooks."""
if not paypal_express_payment.flags.status_changed_to:
return
reference_doctype = paypal_express_payment.reference_doctype
reference_docname = paypal_express_payment.reference_docname
if not (reference_doctype and reference_docname):
return
reference_doc = frappe.get_doc(reference_doctype, reference_docname)
shopping_cart_settings = frappe.get_doc("Shopping Cart Settings")
if paypal_express_payment.flags.status_changed_to == "Completed":
reference_doc.run_method("set_as_paid")
# if shopping cart enabled and in session
if (shopping_cart_settings.enabled
and hasattr(frappe.local, "session")
and frappe.local.session.user != "Guest"):
success_url = shopping_cart_settings.payment_success_url
if success_url:
paypal_express_payment.flags.redirect_to = ({
"Orders": "orders",
"Invoices": "invoices",
"My Account": "me"
}).get(success_url, "me")
else:
paypal_express_payment.flags.redirect_to = get_url("/orders/{0}".format(reference_doc.reference_name))
elif paypal_express_payment.flags.status_changed_to == "Cancelled":
reference_doc.run_method("set_as_cancelled")

View File

@ -1,4 +1,4 @@
{% extends "templates/web.html" %}
t{% extends "templates/web.html" %}
{% block header %}
<h1>{{ doc.name }}</h1>