[fix] make payment request without payment gateway

This commit is contained in:
Saurabh 2016-07-21 20:26:46 +05:30
parent 38035c252a
commit e4e8954a19
4 changed files with 54 additions and 50 deletions

View File

@ -31,5 +31,21 @@ frappe.ui.form.on("Payment Request", "refresh", function(frm) {
});
});
}
if(!frm.doc.payment_gateway_account && frm.doc.status == "Initiated") {
frm.add_custom_button(__('Mark Payment Entry'), function(){
frappe.call({
method: "erpnext.accounts.doctype.payment_request.payment_request.make_payment_entry",
args: {"docname": frm.doc.name},
freeze: true,
callback: function(r){
if(!r.exc) {
var doc = frappe.model.sync(r.message);
frappe.set_route("Form", r.message.doctype, r.message.name);
}
}
});
}).addClass("btn-primary");
}
});

View File

@ -3,11 +3,13 @@
"allow_import": 0,
"allow_rename": 0,
"autoname": "PR.######",
"beta": 0,
"creation": "2015-12-15 22:23:24.745065",
"custom": 0,
"docstatus": 0,
"doctype": "DocType",
"document_type": "",
"editable_grid": 0,
"fields": [
{
"allow_on_submit": 0,
@ -156,7 +158,7 @@
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 1,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
@ -404,30 +406,7 @@
"ignore_xss_filter": 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": "column_break_16",
"fieldtype": "Column Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Payment Gateway Details",
"length": 0,
"no_copy": 0,
"permlevel": 0,
@ -599,13 +578,14 @@
"hide_heading": 0,
"hide_toolbar": 0,
"idx": 0,
"image_view": 0,
"in_create": 1,
"in_dialog": 0,
"is_submittable": 1,
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2016-05-03 10:31:45.692016",
"modified": "2016-07-21 19:11:57.517964",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Payment Request",

View File

@ -13,7 +13,6 @@ from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_ent
class PaymentRequest(Document):
def validate(self):
self.validate_payment_gateway_account()
self.validate_payment_request()
self.validate_currency()
@ -24,19 +23,9 @@ class PaymentRequest(Document):
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"):
if self.payment_account and ref_doc.currency != frappe.db.get_value("Account", self.payment_account, "account_currency"):
frappe.throw(_("Transaction currency must be same as Payment 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.payment_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):
send_mail = True
self.make_communication_entry()
@ -66,9 +55,13 @@ class PaymentRequest(Document):
si.submit()
def send_payment_request(self):
if self.payment_account:
self.payment_url = get_url("/api/method/erpnext.accounts.doctype.payment_request.payment_request.generate_payment_request?name={0}".format(self.name))
if self.payment_url:
self.db_set('payment_url', self.payment_url)
if self.payment_url or not self.payment_gateway_account:
self.db_set('status', 'Initiated')
def set_as_paid(self):
@ -118,12 +111,11 @@ class PaymentRequest(Document):
"cost_center": company_details.cost_center,
"amount": payment_entry.difference_amount
})
if not self.flags.make_draft_payment_entry:
payment_entry.insert(ignore_permissions=True)
payment_entry.submit()
#set status as paid for Payment Request
self.db_set('status', 'Paid')
return payment_entry
def send_email(self):
@ -171,7 +163,7 @@ def make_payment_request(**args):
ref_doc = frappe.get_doc(args.dt, args.dn)
gateway_account = get_gateway_details(args)
gateway_account = get_gateway_details(args) or frappe._dict()
grand_total = get_amount(ref_doc, args.dt)
@ -184,9 +176,9 @@ def make_payment_request(**args):
else:
pr = frappe.new_doc("Payment Request")
pr.update({
"payment_gateway_account": gateway_account.name,
"payment_gateway": gateway_account.payment_gateway,
"payment_account": gateway_account.payment_account,
"payment_gateway_account": gateway_account.get("name"),
"payment_gateway": gateway_account.get("payment_gateway"),
"payment_account": gateway_account.get("payment_account"),
"currency": ref_doc.currency,
"grand_total": grand_total,
"email_to": args.recipient_id or "",
@ -239,9 +231,6 @@ def get_gateway_details(args):
gateway_account = get_payment_gateway_account({"is_default": 1})
if not gateway_account:
frappe.throw(_("Payment Gateway Account is not configured"))
return gateway_account
def get_payment_gateway_account(args):
@ -267,3 +256,19 @@ def generate_payment_request(name):
@frappe.whitelist(allow_guest=True)
def resend_payment_email(docname):
return frappe.get_doc("Payment Request", docname).send_email()
@frappe.whitelist()
def make_payment_entry(docname):
doc = frappe.get_doc("Payment Request", docname)
doc.flags.make_draft_payment_entry = True
return doc.set_as_paid().as_dict()
def make_status_as_paid(doc, method):
for ref in doc.references:
payment_request_name = frappe.db.get_value("Payment Request",
{"reference_doctype": ref.reference_doctype, "reference_name": ref.reference_name,
"docstatus": 1})
doc = frappe.get_doc("Payment Request", payment_request_name)
if doc.status != "Paid":
doc.db_set('status', 'Paid')

View File

@ -158,6 +158,9 @@ doc_events = {
"Website Settings": {
"validate": "erpnext.portal.doctype.products_settings.products_settings.home_page_is_products"
},
"Payment Entry": {
"on_submit": "erpnext.accounts.doctype.payment_request.payment_request.make_status_as_paid"
}
}