[fixes] Create and manage payment request
This commit is contained in:
parent
db7a56b453
commit
3ba22676bf
@ -21,9 +21,11 @@
|
||||
"in_filter": 0,
|
||||
"in_list_view": 1,
|
||||
"label": "Make Accounting Entry For Every Stock Movement",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
@ -43,9 +45,11 @@
|
||||
"in_filter": 0,
|
||||
"in_list_view": 1,
|
||||
"label": "Accounts Frozen Upto",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
@ -65,10 +69,12 @@
|
||||
"in_filter": 0,
|
||||
"in_list_view": 1,
|
||||
"label": "Role Allowed to Set Frozen Accounts & Edit Frozen Entries",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "Role",
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
@ -88,10 +94,12 @@
|
||||
"in_filter": 0,
|
||||
"in_list_view": 1,
|
||||
"label": "Credit Controller",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "Role",
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
@ -110,10 +118,60 @@
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Check Supplier Invoice Number Uniqueness",
|
||||
"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": "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 Transaction 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,
|
||||
@ -131,7 +189,8 @@
|
||||
"is_submittable": 0,
|
||||
"issingle": 1,
|
||||
"istable": 0,
|
||||
"modified": "2015-07-14 00:51:48.095525",
|
||||
"max_attachments": 0,
|
||||
"modified": "2015-12-17 12:26:28.440728",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Accounts Settings",
|
||||
|
@ -33,32 +33,6 @@
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 1,
|
||||
"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": "\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,
|
||||
@ -181,6 +155,32 @@
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 1,
|
||||
"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,
|
||||
@ -209,6 +209,7 @@
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"default": "",
|
||||
"fieldname": "print_format",
|
||||
"fieldtype": "Select",
|
||||
"hidden": 0,
|
||||
@ -271,7 +272,7 @@
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"read_only": 1,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
@ -302,6 +303,30 @@
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "payment_url",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "payment_url",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"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,
|
||||
@ -410,7 +435,7 @@
|
||||
"issingle": 0,
|
||||
"istable": 0,
|
||||
"max_attachments": 0,
|
||||
"modified": "2015-12-17 10:08:48.333171",
|
||||
"modified": "2015-12-21 10:57:48.107213",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Payment Request",
|
||||
|
@ -11,7 +11,7 @@ from erpnext.accounts.doctype.journal_entry.journal_entry import get_payment_ent
|
||||
from erpnext.accounts.party import get_party_account
|
||||
from erpnext.accounts.utils import get_account_currency, get_balance_on
|
||||
from itertools import chain
|
||||
|
||||
from paypal_integration.express_checkout import set_express_checkout
|
||||
class PaymentRequest(Document):
|
||||
def validate(self):
|
||||
self.validate_payment_request()
|
||||
@ -22,11 +22,8 @@ class PaymentRequest(Document):
|
||||
frappe.throw(_("Payment Request already exist"))
|
||||
|
||||
def on_submit(self):
|
||||
if self.status == "Paid":
|
||||
self.set_paid()
|
||||
|
||||
self.send_email()
|
||||
self.send_payment_request()
|
||||
self.send_email()
|
||||
self.make_communication_entry()
|
||||
|
||||
def on_cancel(self):
|
||||
@ -39,12 +36,17 @@ class PaymentRequest(Document):
|
||||
pass
|
||||
|
||||
def send_payment_request(self):
|
||||
pass
|
||||
|
||||
def make_communication_log_entry(self):
|
||||
pass
|
||||
|
||||
if self.payment_gateway == "PayPal":
|
||||
self.payment_url = set_express_checkout(self.amount, "USD", {"doctype": self.doctype,
|
||||
"docname": self.name})
|
||||
|
||||
if self.payment_url:
|
||||
frappe.db.set_value(self.doctype, self.name, "status", "Initiated")
|
||||
|
||||
def set_paid(self):
|
||||
if frappe.session.user == "Guest":
|
||||
frappe.set_user("Administrator")
|
||||
|
||||
self.create_journal_voucher_entry()
|
||||
|
||||
def create_journal_voucher_entry(self):
|
||||
@ -85,12 +87,15 @@ class PaymentRequest(Document):
|
||||
}
|
||||
|
||||
jv = get_payment_entry(ref_doc, payment_details)
|
||||
|
||||
jv.update({
|
||||
"voucher_type": "Journal Entry",
|
||||
"posting_date": today()
|
||||
})
|
||||
jv.submit()
|
||||
|
||||
|
||||
frappe.db.set_value(self.doctype, self.name, "status", "Paid")
|
||||
|
||||
def send_email(self):
|
||||
"""send email with payment link"""
|
||||
frappe.sendmail(recipients=self.email_to, sender=None, subject=self.subject,
|
||||
@ -99,13 +104,13 @@ class PaymentRequest(Document):
|
||||
|
||||
def get_message(self):
|
||||
"""return message with payment gateway link"""
|
||||
return self.message + "<br> Payment Link <a href='https://www.google.com'> link for payment gateway </a>"
|
||||
return self.message + self.payment_url if self.payment_url else ""
|
||||
|
||||
def set_failed(self):
|
||||
pass
|
||||
|
||||
def set_cancelled(self):
|
||||
pass
|
||||
frappe.db.set_value(self.doctype, self.name, "status", "Cancelled")
|
||||
|
||||
def make_communication_entry(self):
|
||||
"""Make communication entry"""
|
||||
@ -125,18 +130,20 @@ def make_payment_request(dt, dn, recipient_id=None):
|
||||
ref_doc = get_reference_doc_details(dt, dn)
|
||||
payment_gateway, payment_account = get_gateway_details()
|
||||
|
||||
pr = frappe.get_doc({
|
||||
"doctype": "Payment Request",
|
||||
pr = frappe.new_doc("Payment Request")
|
||||
pr.update({
|
||||
"payment_gateway": payment_gateway,
|
||||
"payment_account": payment_account,
|
||||
"currency": ref_doc.currency,
|
||||
"amount": get_amount(ref_doc, dt),
|
||||
"email_to": recipient_id,
|
||||
"subject": "Payment Request for %s"%dn,
|
||||
"message": frappe.get_doc("Accounts Settings").message,
|
||||
"reference_doctype": dt,
|
||||
"reference_name": dn
|
||||
}).insert()
|
||||
})
|
||||
|
||||
return pr.name
|
||||
return pr.as_dict()
|
||||
|
||||
def get_reference_doc_details(dt, dn):
|
||||
""" return reference doc Sales Order/Sales Invoice"""
|
||||
|
@ -32,6 +32,11 @@ def get_data():
|
||||
"name": "Supplier",
|
||||
"description": _("Supplier database.")
|
||||
},
|
||||
{
|
||||
"type": "doctype",
|
||||
"name": "Payment Request",
|
||||
"description": _("Payment Request")
|
||||
},
|
||||
{
|
||||
"type": "page",
|
||||
"name": "Accounts Browser",
|
||||
@ -83,6 +88,11 @@ def get_data():
|
||||
"name": "Fiscal Year",
|
||||
"description": _("Financial / accounting year.")
|
||||
},
|
||||
{
|
||||
"type": "doctype",
|
||||
"name": "Payment Gateway",
|
||||
"description": _("Setup Gateway accounts.")
|
||||
},
|
||||
{
|
||||
"type": "page",
|
||||
"name": "Accounts Browser",
|
||||
|
@ -300,7 +300,9 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
|
||||
},
|
||||
callback: function(r) {
|
||||
if(!r.exc){
|
||||
frappe.msgprint(__("Payment Request generated"))
|
||||
var doc = frappe.model.sync(r.message);
|
||||
console.log(r.message)
|
||||
frappe.set_route("Form", r.message.doctype, r.message.name);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user