[fixes] conmify account details and validate gateway currency

This commit is contained in:
Saurabh 2015-12-28 12:41:37 +05:30
parent ed0723c6fe
commit 6fc408e974
7 changed files with 210 additions and 88 deletions

View File

@ -130,54 +130,6 @@
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "payment_gateway_settings",
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Payment Gateway Settings",
"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,
"collapsible": 0,
"fieldname": "message",
"fieldtype": "Text Editor",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Payment Request Message",
"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
}
],
"hide_heading": 0,
@ -190,7 +142,7 @@
"issingle": 1,
"istable": 0,
"max_attachments": 0,
"modified": "2015-12-24 17:31:52.014492",
"modified": "2015-12-24 21:42:01.274459",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Accounts Settings",

View File

@ -508,7 +508,7 @@ class JournalEntry(AccountsController):
d.party_balance = party_balance[(d.party_type, d.party)]
@frappe.whitelist()
def get_default_bank_cash_account(company, voucher_type, mode_of_payment=None):
def get_default_bank_cash_account(company, voucher_type, mode_of_payment=None, account=None):
from erpnext.accounts.doctype.sales_invoice.sales_invoice import get_bank_cash_account
if mode_of_payment:
account = get_bank_cash_account(mode_of_payment, company)
@ -516,16 +516,18 @@ def get_default_bank_cash_account(company, voucher_type, mode_of_payment=None):
account.update({"balance": get_balance_on(account.get("account"))})
return account
if voucher_type=="Bank Entry":
account = frappe.db.get_value("Company", company, "default_bank_account")
if not account:
account = frappe.db.get_value("Account",
{"company": company, "account_type": "Bank", "is_group": 0})
elif voucher_type=="Cash Entry":
account = frappe.db.get_value("Company", company, "default_cash_account")
if not account:
account = frappe.db.get_value("Account",
{"company": company, "account_type": "Cash", "is_group": 0})
if not account:
if voucher_type=="Bank Entry":
account = frappe.db.get_value("Company", company, "default_bank_account")
if not account:
account = frappe.db.get_value("Account",
{"company": company, "account_type": "Bank", "is_group": 0})
elif voucher_type=="Cash Entry":
account = frappe.db.get_value("Company", company, "default_cash_account")
if not account:
account = frappe.db.get_value("Account",
{"company": company, "account_type": "Cash", "is_group": 0})
if account:
account_details = frappe.db.get_value("Account", account,
@ -640,7 +642,8 @@ def get_payment_entry(ref_doc, args):
bank_row = jv.append("accounts")
bank_account = args.get("bank_account", get_default_bank_cash_account(ref_doc.company, "Bank Entry"))
#make it bank_details
bank_account = get_default_bank_cash_account(ref_doc.company, "Bank Entry", account=args.get("bank_account"))
if bank_account:
bank_row.update(bank_account)
bank_row.exchange_rate = get_exchange_rate(bank_account["account"],

View File

@ -43,7 +43,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2015-12-23 22:32:32.690126",
"modified": "2015-12-29 12:04:17.371619",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Payment Gateway",
@ -69,6 +69,46 @@
"share": 1,
"submit": 0,
"write": 1
},
{
"amend": 0,
"apply_user_permissions": 0,
"cancel": 0,
"create": 0,
"delete": 0,
"email": 0,
"export": 0,
"if_owner": 0,
"import": 0,
"permlevel": 0,
"print": 0,
"read": 1,
"report": 0,
"role": "System Manager",
"set_user_permissions": 0,
"share": 0,
"submit": 0,
"write": 0
},
{
"amend": 0,
"apply_user_permissions": 0,
"cancel": 0,
"create": 0,
"delete": 0,
"email": 0,
"export": 0,
"if_owner": 0,
"import": 0,
"permlevel": 0,
"print": 0,
"read": 1,
"report": 0,
"role": "Accounts Manager",
"set_user_permissions": 0,
"share": 0,
"submit": 0,
"write": 0
}
],
"read_only": 0,

View File

@ -8,6 +8,30 @@
"doctype": "DocType",
"document_type": "",
"fields": [
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "gateway_acount_details",
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Gateway Acount Details",
"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,
@ -106,6 +130,102 @@
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "payment_request_message",
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Payment Request Message",
"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,
"collapsible": 0,
"fieldname": "message",
"fieldtype": "Text Editor",
"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,
"collapsible": 0,
"fieldname": "reminder_settings",
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Reminder Settings",
"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,
"collapsible": 0,
"description": "In Days",
"fieldname": "reminder_after",
"fieldtype": "Int",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Reminder After",
"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
}
],
"hide_heading": 0,
@ -117,7 +237,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2015-12-24 17:02:34.520800",
"modified": "2015-12-24 21:41:05.123141",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Payment Gateway Account",

View File

@ -1,5 +1,6 @@
cur_frm.add_fetch("payment_gateway", "payment_account", "payment_account")
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({

View File

@ -5,7 +5,7 @@
from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
from frappe.utils import flt, today
from frappe.utils import flt, nowdate, get_url
from frappe import _
from erpnext.accounts.doctype.journal_entry.journal_entry import (get_payment_entry_against_invoice,
get_payment_entry_against_order)
@ -15,12 +15,18 @@ from itertools import chain
class PaymentRequest(Document):
def validate(self):
self.validate_payment_request()
self.validate_payment_request()
self.validate_currency()
def validate_payment_request(self):
if frappe.db.get_value("Payment Request", {"reference_name": self.reference_name,
"name": ("!=", self.name), "status": ("not in", ["Initiated", "Paid"]), "docstatus": 1}, "name"):
frappe.throw(_("Payment Request already exist"))
def validate_currency(self):
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 simillar to Gateway Currency"))
def on_submit(self):
if not self.mute_email:
@ -39,10 +45,7 @@ class PaymentRequest(Document):
pass
def send_payment_request(self):
if self.gateway == "PayPal":
from paypal_integration.express_checkout import set_express_checkout
self.payment_url = set_express_checkout(self.amount, self.currency, {"doctype": self.doctype,
"docname": self.name})
self.payment_url = get_url("/api/method/erpnext.accounts.doctype.payment_request.payment_request.gererate_payemnt_request?name={0}".format(self.name))
if self.payment_url:
frappe.db.set_value(self.doctype, self.name, "status", "Initiated")
@ -57,17 +60,8 @@ class PaymentRequest(Document):
"""create entry"""
payment_details = {
"amount": self.amount,
"return_obj": True
}
account_details = frappe.db.get_value("Account", self.payment_account,
["account_currency", "account_type"], as_dict=1)
payment_details["bank_account"] = {
"account": self.payment_account,
"balance": get_balance_on(self.payment_account),
"account_currency": account_details.account_currency,
"account_type": account_details.account_type
"return_obj": True,
"bank_account": self.payment_account
}
if self.reference_doctype == "Sales Order":
@ -78,7 +72,7 @@ class PaymentRequest(Document):
jv.update({
"voucher_type": "Journal Entry",
"posting_date": today()
"posting_date": nowdate()
})
jv.submit()
@ -121,7 +115,7 @@ def make_payment_request(**args):
"""Make payment request"""
args = frappe._dict(args)
ref_doc = get_reference_doc_details(args.dt, args.dn)
name, gateway, payment_account = get_gateway_details(args)
name, gateway, payment_account, message = get_gateway_details(args)
pr = frappe.new_doc("Payment Request")
pr.update({
@ -133,7 +127,7 @@ def make_payment_request(**args):
"mute_email": args.mute_email or 0,
"email_to": args.recipient_id or "",
"subject": "Payment Request for %s"%args.dn,
"message": frappe.get_doc("Accounts Settings").message,
"message": message,
"reference_doctype": args.dt,
"reference_name": args.dn
})
@ -171,9 +165,11 @@ 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"])
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"])
return frappe.db.get_value("Payment Gateway Account", {"is_default": 1},
["name", "gateway", "payment_account", "message"])
@frappe.whitelist()
def get_print_format_list(ref_doctype):
@ -185,4 +181,14 @@ def get_print_format_list(ref_doctype):
return {
"print_format": print_format_list
}
@frappe.whitelist(allow_guest=True)
def gererate_payemnt_request(name):
doc = frappe.get_doc("Payment Request", name)
if doc.gateway == "PayPal":
from paypal_integration.express_checkout import set_express_checkout
payment_url = set_express_checkout(doc.amount, doc.currency, {"doctype": doc.doctype,
"docname": doc.name})
frappe.local.response["type"] = "redirect"
frappe.local.response["location"] = payment_url

View File

@ -90,7 +90,7 @@ def get_data():
},
{
"type": "doctype",
"name": "Payment Gateway",
"name": "Payment Gateway Account",
"description": _("Setup Gateway accounts.")
},
{