[fixes] Create and manage payment request

This commit is contained in:
Saurabh 2015-12-21 18:24:49 +05:30
parent db7a56b453
commit 3ba22676bf
5 changed files with 150 additions and 47 deletions

View File

@ -21,9 +21,11 @@
"in_filter": 0, "in_filter": 0,
"in_list_view": 1, "in_list_view": 1,
"label": "Make Accounting Entry For Every Stock Movement", "label": "Make Accounting Entry For Every Stock Movement",
"length": 0,
"no_copy": 0, "no_copy": 0,
"permlevel": 0, "permlevel": 0,
"print_hide": 0, "print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0, "read_only": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 0, "reqd": 0,
@ -43,9 +45,11 @@
"in_filter": 0, "in_filter": 0,
"in_list_view": 1, "in_list_view": 1,
"label": "Accounts Frozen Upto", "label": "Accounts Frozen Upto",
"length": 0,
"no_copy": 0, "no_copy": 0,
"permlevel": 0, "permlevel": 0,
"print_hide": 0, "print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0, "read_only": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 0, "reqd": 0,
@ -65,10 +69,12 @@
"in_filter": 0, "in_filter": 0,
"in_list_view": 1, "in_list_view": 1,
"label": "Role Allowed to Set Frozen Accounts & Edit Frozen Entries", "label": "Role Allowed to Set Frozen Accounts & Edit Frozen Entries",
"length": 0,
"no_copy": 0, "no_copy": 0,
"options": "Role", "options": "Role",
"permlevel": 0, "permlevel": 0,
"print_hide": 0, "print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0, "read_only": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 0, "reqd": 0,
@ -88,10 +94,12 @@
"in_filter": 0, "in_filter": 0,
"in_list_view": 1, "in_list_view": 1,
"label": "Credit Controller", "label": "Credit Controller",
"length": 0,
"no_copy": 0, "no_copy": 0,
"options": "Role", "options": "Role",
"permlevel": 0, "permlevel": 0,
"print_hide": 0, "print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0, "read_only": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 0, "reqd": 0,
@ -110,10 +118,60 @@
"in_filter": 0, "in_filter": 0,
"in_list_view": 0, "in_list_view": 0,
"label": "Check Supplier Invoice Number Uniqueness", "label": "Check Supplier Invoice Number Uniqueness",
"length": 0,
"no_copy": 0, "no_copy": 0,
"permlevel": 0, "permlevel": 0,
"precision": "", "precision": "",
"print_hide": 0, "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, "read_only": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 0, "reqd": 0,
@ -131,7 +189,8 @@
"is_submittable": 0, "is_submittable": 0,
"issingle": 1, "issingle": 1,
"istable": 0, "istable": 0,
"modified": "2015-07-14 00:51:48.095525", "max_attachments": 0,
"modified": "2015-12-17 12:26:28.440728",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Accounts Settings", "name": "Accounts Settings",

View File

@ -33,32 +33,6 @@
"set_only_once": 0, "set_only_once": 0,
"unique": 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, "allow_on_submit": 0,
"bold": 0, "bold": 0,
@ -181,6 +155,32 @@
"set_only_once": 0, "set_only_once": 0,
"unique": 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, "allow_on_submit": 0,
"bold": 0, "bold": 0,
@ -209,6 +209,7 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"default": "",
"fieldname": "print_format", "fieldname": "print_format",
"fieldtype": "Select", "fieldtype": "Select",
"hidden": 0, "hidden": 0,
@ -271,7 +272,7 @@
"precision": "", "precision": "",
"print_hide": 0, "print_hide": 0,
"print_hide_if_no_value": 0, "print_hide_if_no_value": 0,
"read_only": 0, "read_only": 1,
"report_hide": 0, "report_hide": 0,
"reqd": 0, "reqd": 0,
"search_index": 0, "search_index": 0,
@ -302,6 +303,30 @@
"set_only_once": 0, "set_only_once": 0,
"unique": 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, "allow_on_submit": 0,
"bold": 0, "bold": 0,
@ -410,7 +435,7 @@
"issingle": 0, "issingle": 0,
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2015-12-17 10:08:48.333171", "modified": "2015-12-21 10:57:48.107213",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Payment Request", "name": "Payment Request",

View File

@ -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.party import get_party_account
from erpnext.accounts.utils import get_account_currency, get_balance_on from erpnext.accounts.utils import get_account_currency, get_balance_on
from itertools import chain from itertools import chain
from paypal_integration.express_checkout import set_express_checkout
class PaymentRequest(Document): class PaymentRequest(Document):
def validate(self): def validate(self):
self.validate_payment_request() self.validate_payment_request()
@ -22,11 +22,8 @@ class PaymentRequest(Document):
frappe.throw(_("Payment Request already exist")) frappe.throw(_("Payment Request already exist"))
def on_submit(self): def on_submit(self):
if self.status == "Paid":
self.set_paid()
self.send_email()
self.send_payment_request() self.send_payment_request()
self.send_email()
self.make_communication_entry() self.make_communication_entry()
def on_cancel(self): def on_cancel(self):
@ -39,12 +36,17 @@ class PaymentRequest(Document):
pass pass
def send_payment_request(self): def send_payment_request(self):
pass if self.payment_gateway == "PayPal":
self.payment_url = set_express_checkout(self.amount, "USD", {"doctype": self.doctype,
def make_communication_log_entry(self): "docname": self.name})
pass
if self.payment_url:
frappe.db.set_value(self.doctype, self.name, "status", "Initiated")
def set_paid(self): def set_paid(self):
if frappe.session.user == "Guest":
frappe.set_user("Administrator")
self.create_journal_voucher_entry() self.create_journal_voucher_entry()
def create_journal_voucher_entry(self): def create_journal_voucher_entry(self):
@ -85,12 +87,15 @@ class PaymentRequest(Document):
} }
jv = get_payment_entry(ref_doc, payment_details) jv = get_payment_entry(ref_doc, payment_details)
jv.update({ jv.update({
"voucher_type": "Journal Entry", "voucher_type": "Journal Entry",
"posting_date": today() "posting_date": today()
}) })
jv.submit() jv.submit()
frappe.db.set_value(self.doctype, self.name, "status", "Paid")
def send_email(self): def send_email(self):
"""send email with payment link""" """send email with payment link"""
frappe.sendmail(recipients=self.email_to, sender=None, subject=self.subject, frappe.sendmail(recipients=self.email_to, sender=None, subject=self.subject,
@ -99,13 +104,13 @@ class PaymentRequest(Document):
def get_message(self): def get_message(self):
"""return message with payment gateway link""" """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): def set_failed(self):
pass pass
def set_cancelled(self): def set_cancelled(self):
pass frappe.db.set_value(self.doctype, self.name, "status", "Cancelled")
def make_communication_entry(self): def make_communication_entry(self):
"""Make communication entry""" """Make communication entry"""
@ -125,18 +130,20 @@ def make_payment_request(dt, dn, recipient_id=None):
ref_doc = get_reference_doc_details(dt, dn) ref_doc = get_reference_doc_details(dt, dn)
payment_gateway, payment_account = get_gateway_details() payment_gateway, payment_account = get_gateway_details()
pr = frappe.get_doc({ pr = frappe.new_doc("Payment Request")
"doctype": "Payment Request", pr.update({
"payment_gateway": payment_gateway, "payment_gateway": payment_gateway,
"payment_account": payment_account, "payment_account": payment_account,
"currency": ref_doc.currency, "currency": ref_doc.currency,
"amount": get_amount(ref_doc, dt), "amount": get_amount(ref_doc, dt),
"email_to": recipient_id, "email_to": recipient_id,
"subject": "Payment Request for %s"%dn,
"message": frappe.get_doc("Accounts Settings").message,
"reference_doctype": dt, "reference_doctype": dt,
"reference_name": dn "reference_name": dn
}).insert() })
return pr.name return pr.as_dict()
def get_reference_doc_details(dt, dn): def get_reference_doc_details(dt, dn):
""" return reference doc Sales Order/Sales Invoice""" """ return reference doc Sales Order/Sales Invoice"""

View File

@ -32,6 +32,11 @@ def get_data():
"name": "Supplier", "name": "Supplier",
"description": _("Supplier database.") "description": _("Supplier database.")
}, },
{
"type": "doctype",
"name": "Payment Request",
"description": _("Payment Request")
},
{ {
"type": "page", "type": "page",
"name": "Accounts Browser", "name": "Accounts Browser",
@ -83,6 +88,11 @@ def get_data():
"name": "Fiscal Year", "name": "Fiscal Year",
"description": _("Financial / accounting year.") "description": _("Financial / accounting year.")
}, },
{
"type": "doctype",
"name": "Payment Gateway",
"description": _("Setup Gateway accounts.")
},
{ {
"type": "page", "type": "page",
"name": "Accounts Browser", "name": "Accounts Browser",

View File

@ -300,7 +300,9 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
}, },
callback: function(r) { callback: function(r) {
if(!r.exc){ 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);
} }
} }
}) })