[fixes] Create payment gateway account
This commit is contained in:
parent
766f6a43d5
commit
ed0723c6fe
@ -165,7 +165,7 @@
|
||||
"ignore_user_permissions": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Payment Transaction Message",
|
||||
"label": "Payment Request Message",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
@ -190,7 +190,7 @@
|
||||
"issingle": 1,
|
||||
"istable": 0,
|
||||
"max_attachments": 0,
|
||||
"modified": "2015-12-17 12:26:28.440728",
|
||||
"modified": "2015-12-24 17:31:52.014492",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Accounts Settings",
|
||||
|
@ -538,7 +538,7 @@ def get_default_bank_cash_account(company, voucher_type, mode_of_payment=None):
|
||||
}
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_payment_entry_against_order(dt, dn):
|
||||
def get_payment_entry_against_order(dt, dn, args=None):
|
||||
ref_doc = frappe.get_doc(dt, dn)
|
||||
|
||||
if flt(ref_doc.per_billed, 2) > 0:
|
||||
@ -556,10 +556,13 @@ def get_payment_entry_against_order(dt, dn):
|
||||
party_account = get_party_account(party_type, ref_doc.get(party_type.lower()), ref_doc.company)
|
||||
party_account_currency = get_account_currency(party_account)
|
||||
|
||||
if party_account_currency == ref_doc.company_currency:
|
||||
amount = flt(ref_doc.base_grand_total) - flt(ref_doc.advance_paid)
|
||||
if not args or not args["amount"]:
|
||||
if party_account_currency == ref_doc.company_currency:
|
||||
amount = flt(ref_doc.base_grand_total) - flt(ref_doc.advance_paid)
|
||||
else:
|
||||
amount = flt(ref_doc.grand_total) - flt(ref_doc.advance_paid)
|
||||
else:
|
||||
amount = flt(ref_doc.grand_total) - flt(ref_doc.advance_paid)
|
||||
amount = args["amount"]
|
||||
|
||||
return get_payment_entry(ref_doc, {
|
||||
"party_type": party_type,
|
||||
@ -569,11 +572,13 @@ def get_payment_entry_against_order(dt, dn):
|
||||
"amount_field_bank": amount_field_bank,
|
||||
"amount": amount,
|
||||
"remarks": 'Advance Payment received against {0} {1}'.format(dt, dn),
|
||||
"is_advance": "Yes"
|
||||
"is_advance": "Yes",
|
||||
"bank_account": args["bank_account"] if args else None,
|
||||
"return_obj": args["return_obj"] if args else None
|
||||
})
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_payment_entry_against_invoice(dt, dn):
|
||||
def get_payment_entry_against_invoice(dt, dn, args=None):
|
||||
ref_doc = frappe.get_doc(dt, dn)
|
||||
if dt == "Sales Invoice":
|
||||
party_type = "Customer"
|
||||
@ -597,9 +602,11 @@ def get_payment_entry_against_invoice(dt, dn):
|
||||
"party_account_currency": ref_doc.party_account_currency,
|
||||
"amount_field_party": amount_field_party,
|
||||
"amount_field_bank": amount_field_bank,
|
||||
"amount": abs(ref_doc.outstanding_amount),
|
||||
"amount": args["amount"] if args else abs(ref_doc.outstanding_amount),
|
||||
"remarks": 'Payment received against {0} {1}. {2}'.format(dt, dn, ref_doc.remarks),
|
||||
"is_advance": "No"
|
||||
"is_advance": "No",
|
||||
"bank_account": args["bank_account"] if args else None,
|
||||
"return_obj": args["return_obj"] if args else None
|
||||
})
|
||||
|
||||
def get_payment_entry(ref_doc, args):
|
||||
@ -653,7 +660,7 @@ def get_payment_entry(ref_doc, args):
|
||||
|
||||
jv.set_amounts_in_company_currency()
|
||||
jv.set_total_debit_credit()
|
||||
|
||||
|
||||
return jv if args.get("return_obj") else jv.as_dict()
|
||||
|
||||
@frappe.whitelist()
|
||||
|
@ -9,54 +9,6 @@
|
||||
"doctype": "DocType",
|
||||
"document_type": "",
|
||||
"fields": [
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "payment_gateway_details",
|
||||
"fieldtype": "Section Break",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Payment Gateway 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,
|
||||
"collapsible": 0,
|
||||
"fieldname": "is_default",
|
||||
"fieldtype": "Check",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Is Default",
|
||||
"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,
|
||||
@ -80,56 +32,6 @@
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "payment_account",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Payment Account",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "Account",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 1,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "currency",
|
||||
"fieldtype": "Read Only",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Currency",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "payment_account.account_currency",
|
||||
"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,
|
||||
@ -141,7 +43,7 @@
|
||||
"issingle": 0,
|
||||
"istable": 0,
|
||||
"max_attachments": 0,
|
||||
"modified": "2015-12-22 19:07:36.491109",
|
||||
"modified": "2015-12-23 22:32:32.690126",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Payment Gateway",
|
||||
@ -167,46 +69,6 @@
|
||||
"share": 1,
|
||||
"submit": 0,
|
||||
"write": 1
|
||||
},
|
||||
{
|
||||
"amend": 0,
|
||||
"apply_user_permissions": 0,
|
||||
"cancel": 0,
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 1,
|
||||
"if_owner": 0,
|
||||
"import": 0,
|
||||
"permlevel": 0,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "System Manager",
|
||||
"set_user_permissions": 0,
|
||||
"share": 1,
|
||||
"submit": 0,
|
||||
"write": 1
|
||||
},
|
||||
{
|
||||
"amend": 0,
|
||||
"apply_user_permissions": 0,
|
||||
"cancel": 0,
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 1,
|
||||
"if_owner": 0,
|
||||
"import": 0,
|
||||
"permlevel": 0,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "Accounts Manager",
|
||||
"set_user_permissions": 0,
|
||||
"share": 1,
|
||||
"submit": 0,
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"read_only": 0,
|
||||
|
@ -7,15 +7,5 @@ import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
class PaymentGateway(Document):
|
||||
def validate(self):
|
||||
self.update_default_payment_gateway()
|
||||
self.set_as_default()
|
||||
|
||||
def update_default_payment_gateway(self):
|
||||
if self.is_default:
|
||||
frappe.db.sql("""update `tabPayment Gateway` set is_default = 0
|
||||
where is_default = 1 """)
|
||||
|
||||
def set_as_default(self):
|
||||
if not frappe.db.get_value("Payment Gateway", {"is_default": 1, "name": ("!=", self.name)}, "name"):
|
||||
self.is_default = 1
|
||||
pass
|
||||
|
@ -0,0 +1,6 @@
|
||||
cur_frm.cscript.refresh = function(doc, dt, dn){
|
||||
if(!doc.__islocal){
|
||||
var df = frappe.meta.get_docfield(doc.doctype, "gateway", doc.name);
|
||||
df.read_only = 1;
|
||||
}
|
||||
}
|
@ -0,0 +1,172 @@
|
||||
{
|
||||
"allow_copy": 0,
|
||||
"allow_import": 0,
|
||||
"allow_rename": 0,
|
||||
"creation": "2015-12-23 21:31:52.699821",
|
||||
"custom": 0,
|
||||
"docstatus": 0,
|
||||
"doctype": "DocType",
|
||||
"document_type": "",
|
||||
"fields": [
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "is_default",
|
||||
"fieldtype": "Check",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Is Default",
|
||||
"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": "gateway",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Gateway",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "Payment Gateway",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 1,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "payment_account",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Payment Account",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "Account",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 1,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "currency",
|
||||
"fieldtype": "Read Only",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Currency",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "payment_account.account_currency",
|
||||
"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,
|
||||
"hide_toolbar": 0,
|
||||
"idx": 0,
|
||||
"in_create": 0,
|
||||
"in_dialog": 0,
|
||||
"is_submittable": 0,
|
||||
"issingle": 0,
|
||||
"istable": 0,
|
||||
"max_attachments": 0,
|
||||
"modified": "2015-12-24 17:02:34.520800",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Payment Gateway Account",
|
||||
"name_case": "",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
"amend": 0,
|
||||
"apply_user_permissions": 0,
|
||||
"cancel": 0,
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 1,
|
||||
"if_owner": 0,
|
||||
"import": 0,
|
||||
"permlevel": 0,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "Administrator",
|
||||
"set_user_permissions": 0,
|
||||
"share": 1,
|
||||
"submit": 0,
|
||||
"write": 1
|
||||
},
|
||||
{
|
||||
"amend": 0,
|
||||
"apply_user_permissions": 0,
|
||||
"cancel": 0,
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 1,
|
||||
"if_owner": 0,
|
||||
"import": 0,
|
||||
"permlevel": 0,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "Accounts Manager",
|
||||
"set_user_permissions": 0,
|
||||
"share": 1,
|
||||
"submit": 0,
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"read_only": 0,
|
||||
"read_only_onload": 0,
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC"
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
# -*- 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.model.document import Document
|
||||
|
||||
class PaymentGatewayAccount(Document):
|
||||
def autoname(self):
|
||||
self.name = self.gateway + " - " + self.currency
|
||||
|
||||
def validate(self):
|
||||
self.update_default_payment_gateway()
|
||||
self.set_as_default()
|
||||
|
||||
def update_default_payment_gateway(self):
|
||||
if self.is_default:
|
||||
frappe.db.sql("""update `tabPayment Gateway Account` set is_default = 0
|
||||
where is_default = 1 """)
|
||||
|
||||
def set_as_default(self):
|
||||
if not frappe.db.get_value("Payment Gateway Account", {"is_default": 1, "name": ("!=", self.name)}, "name"):
|
||||
self.is_default = 1
|
@ -0,0 +1,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# See license.txt
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import frappe
|
||||
import unittest
|
||||
|
||||
# test_records = frappe.get_test_records('Payment Gateway Account')
|
||||
|
||||
class TestPaymentGatewayAccount(unittest.TestCase):
|
||||
pass
|
@ -1,4 +1,5 @@
|
||||
cur_frm.add_fetch("payment_gateway", "payment_account", "payment_account")
|
||||
cur_frm.add_fetch("payment_gateway", "gateway", "gateway")
|
||||
|
||||
frappe.ui.form.on("Payment Request", "onload", function(frm, dt, dn){
|
||||
frappe.call({
|
||||
|
@ -118,7 +118,32 @@
|
||||
"label": "Payment Gateway",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "Payment Gateway",
|
||||
"options": "Payment Gateway Account",
|
||||
"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": "gateway",
|
||||
"fieldtype": "Read Only",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Gateway",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "payment_gateway.gateway",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
@ -135,7 +160,7 @@
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "payment_account",
|
||||
"fieldtype": "Link",
|
||||
"fieldtype": "Read Only",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"in_filter": 0,
|
||||
@ -143,7 +168,7 @@
|
||||
"label": "Payment Account",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "Account",
|
||||
"options": "payment_gateway.payment_account",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
@ -459,7 +484,7 @@
|
||||
"issingle": 0,
|
||||
"istable": 0,
|
||||
"max_attachments": 0,
|
||||
"modified": "2015-12-22 20:18:08.853333",
|
||||
"modified": "2015-12-23 23:49:22.755235",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Payment Request",
|
||||
|
@ -7,7 +7,8 @@ import frappe
|
||||
from frappe.model.document import Document
|
||||
from frappe.utils import flt, today
|
||||
from frappe import _
|
||||
from erpnext.accounts.doctype.journal_entry.journal_entry import get_payment_entry
|
||||
from erpnext.accounts.doctype.journal_entry.journal_entry import (get_payment_entry_against_invoice,
|
||||
get_payment_entry_against_order)
|
||||
from erpnext.accounts.party import get_party_account
|
||||
from erpnext.accounts.utils import get_account_currency, get_balance_on
|
||||
from itertools import chain
|
||||
@ -18,14 +19,14 @@ class PaymentRequest(Document):
|
||||
|
||||
def validate_payment_request(self):
|
||||
if frappe.db.get_value("Payment Request", {"reference_name": self.reference_name,
|
||||
"name": ("!=", self.name), "status": "Paid", "docstatus": 1}, "name"):
|
||||
"name": ("!=", self.name), "status": ("not in", ["Initiated", "Paid"]), "docstatus": 1}, "name"):
|
||||
frappe.throw(_("Payment Request already exist"))
|
||||
|
||||
def on_submit(self):
|
||||
if not self.mute_email:
|
||||
self.send_payment_request()
|
||||
self.send_email()
|
||||
|
||||
|
||||
self.make_communication_entry()
|
||||
|
||||
def on_cancel(self):
|
||||
@ -38,7 +39,7 @@ class PaymentRequest(Document):
|
||||
pass
|
||||
|
||||
def send_payment_request(self):
|
||||
if self.payment_gateway == "PayPal":
|
||||
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})
|
||||
@ -50,52 +51,36 @@ class PaymentRequest(Document):
|
||||
if frappe.session.user == "Guest":
|
||||
frappe.set_user("Administrator")
|
||||
|
||||
return self.create_journal_voucher_entry()
|
||||
return self.create_journal_entry()
|
||||
|
||||
def create_journal_voucher_entry(self):
|
||||
"""create voucher entry"""
|
||||
def create_journal_entry(self):
|
||||
"""create entry"""
|
||||
payment_details = {
|
||||
"party_type": "Customer",
|
||||
"amount_field_party": "credit_in_account_currency",
|
||||
"amount_field_bank": "debit_in_account_currency",
|
||||
"amount": self.amount,
|
||||
"return_obj": True
|
||||
}
|
||||
|
||||
ref_doc = frappe.get_doc(self.reference_doctype, self.reference_name)
|
||||
|
||||
if self.reference_doctype == "Sales Order":
|
||||
party_account = get_party_account("Customer", ref_doc.get('customer'), ref_doc.company)
|
||||
payment_details.update({
|
||||
"party_account": party_account,
|
||||
"party_account_currency": get_account_currency(party_account),
|
||||
"remarks": 'Advance Payment received against {0} {1}'.format(self.reference_doctype, self.reference_name),
|
||||
"is_advance": "Yes"
|
||||
})
|
||||
if self.reference_doctype == "Sales Invoice":
|
||||
payment_details.update({
|
||||
"party_account": ref_doc.debit_to,
|
||||
"party_account_currency": ref_doc.party_account_currency,
|
||||
"remarks": 'Payment received against {0} {1}. {2}'.format(self.reference_doctype, self.reference_name, ref_doc.remarks),
|
||||
"is_advance": "No"
|
||||
})
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
#create voucher entry
|
||||
jv = get_payment_entry(ref_doc, payment_details)
|
||||
|
||||
if self.reference_doctype == "Sales Order":
|
||||
jv = get_payment_entry_against_order(self.reference_doctype, self.reference_name, payment_details)
|
||||
|
||||
if self.reference_doctype == "Sales Invoice":
|
||||
jv = get_payment_entry_against_invoice(self.reference_doctype, self.reference_name, payment_details)
|
||||
|
||||
jv.update({
|
||||
"voucher_type": "Journal Entry",
|
||||
"posting_date": today()
|
||||
})
|
||||
})
|
||||
|
||||
jv.submit()
|
||||
|
||||
#set status as paid for Payment Request
|
||||
@ -136,11 +121,12 @@ def make_payment_request(**args):
|
||||
"""Make payment request"""
|
||||
args = frappe._dict(args)
|
||||
ref_doc = get_reference_doc_details(args.dt, args.dn)
|
||||
payment_gateway, payment_account = get_gateway_details(args)
|
||||
name, gateway, payment_account = get_gateway_details(args)
|
||||
|
||||
pr = frappe.new_doc("Payment Request")
|
||||
pr.update({
|
||||
"payment_gateway": payment_gateway,
|
||||
"payment_gateway": name,
|
||||
"gateway": gateway,
|
||||
"payment_account": payment_account,
|
||||
"currency": ref_doc.currency,
|
||||
"amount": get_amount(ref_doc, args.dt),
|
||||
@ -185,9 +171,9 @@ def get_amount(ref_doc, dt):
|
||||
def get_gateway_details(args):
|
||||
"""return gateway and payment account of default payment gateway"""
|
||||
if args.payemnt_gateway:
|
||||
frappe.db.get_value("Payment Gateway", args.payemnt_gateway, ["gateway", "payment_account"])
|
||||
return frappe.db.get_value("Payment Gateway Account", args.payemnt_gateway, ["name", "gateway", "payment_account"])
|
||||
|
||||
return frappe.db.get_value("Payment Gateway", {"is_default": 1}, ["gateway", "payment_account"])
|
||||
return frappe.db.get_value("Payment Gateway Account", {"is_default": 1}, ["name", "gateway", "payment_account"])
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_print_format_list(ref_doctype):
|
||||
|
@ -12,17 +12,22 @@ from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sal
|
||||
|
||||
test_dependencies = ["Currency Exchange", "Journal Entry", "Contact", "Address"]
|
||||
|
||||
payment_gateway = {
|
||||
"doctype": "Payment Gateway",
|
||||
"gateway": "_Test Gateway"
|
||||
}
|
||||
|
||||
payment_method = [
|
||||
{
|
||||
"doctype": "Payment Gateway",
|
||||
"doctype": "Payment Gateway Account",
|
||||
"is_default": 1,
|
||||
"gateway": "_Test Gateway INR",
|
||||
"gateway": "_Test Gateway",
|
||||
"payment_account": "_Test Bank - _TC",
|
||||
"currency": "INR"
|
||||
},
|
||||
{
|
||||
"doctype": "Payment Gateway",
|
||||
"gateway": "_Test Gateway USD",
|
||||
"doctype": "Payment Gateway Account",
|
||||
"gateway": "_Test Gateway",
|
||||
"payment_account": "_Test Bank - _TC",
|
||||
"currency": "USD"
|
||||
}
|
||||
@ -30,9 +35,13 @@ payment_method = [
|
||||
|
||||
class TestPaymentRequest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
for gateway in payment_method:
|
||||
if not frappe.db.get_value("Payment Gateway", gateway["gateway"], "name"):
|
||||
frappe.get_doc(gateway).insert(ignore_permissions=True)
|
||||
if not frappe.db.get_value("Payment Gateway", payment_gateway["gateway"], "name"):
|
||||
frappe.get_doc(payment_gateway).insert(ignore_permissions=True)
|
||||
|
||||
for method in payment_method:
|
||||
if not frappe.db.get_value("Payment Gateway Account", {"gateway": method["gateway"],
|
||||
"currency": method["currency"]}, "name"):
|
||||
frappe.get_doc(method).insert(ignore_permissions=True)
|
||||
|
||||
def test_payment_request_linkings(self):
|
||||
SO_INR = make_sales_order(currency="INR")
|
||||
@ -63,7 +72,7 @@ class TestPaymentRequest(unittest.TestCase):
|
||||
currency="USD", conversion_rate=50)
|
||||
|
||||
pr = make_payment_request(dt="Sales Invoice", dn=SI_USD.name, recipient_id="saurabh@erpnext.com",
|
||||
mute_email=1, submit_doc=1, payemnt_gateway="_Test Gateway USD")
|
||||
mute_email=1, submit_doc=1, payemnt_gateway="_Test Gateway - USD")
|
||||
jv = pr.set_paid()
|
||||
|
||||
self.assertEquals(jv.accounts[0].account, "_Test Receivable USD - _TC")
|
||||
|
Loading…
Reference in New Issue
Block a user