Merge pull request #4781 from nabinhait/develop

Payment Request Fixes
This commit is contained in:
Rushabh Mehta 2016-02-10 13:13:27 +05:30
commit cc35f62514
3 changed files with 172 additions and 58 deletions

View File

@ -11,6 +11,8 @@ class PaymentGatewayAccount(Document):
self.name = self.gateway + " - " + self.currency
def validate(self):
self.currency = frappe.db.get_value("Account", self.payment_account, "account_currency")
self.update_default_payment_gateway()
self.set_as_default_if_not_set()
@ -20,5 +22,6 @@ class PaymentGatewayAccount(Document):
where is_default = 1 """)
def set_as_default_if_not_set(self):
if not frappe.db.get_value("Payment Gateway Account", {"is_default": 1, "name": ("!=", self.name)}, "name"):
self.is_default = 1
if not frappe.db.get_value("Payment Gateway Account",
{"is_default": 1, "name": ("!=", self.name)}, "name"):
self.is_default = 1

View File

@ -23,7 +23,7 @@ class PaymentRequest(Document):
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 exists {0}".fomart(self.reference_name)))
frappe.throw(_("Payment Request already exists {0}".format(self.reference_name)))
def validate_currency(self):
ref_doc = frappe.get_doc(self.reference_doctype, self.reference_name)
@ -150,37 +150,43 @@ def make_payment_request(**args):
ref_doc = frappe.get_doc(args.dt, args.dn)
gateway_account = get_gateway_details(args)
pr = frappe.new_doc("Payment Request")
pr.update({
"payment_gateway": gateway_account.name,
"gateway": gateway_account.gateway,
"payment_account": gateway_account.payment_account,
"currency": ref_doc.currency,
"make_sales_invoice": args.cart or 0,
"amount": get_amount(ref_doc, args.dt),
"mute_email": args.mute_email or 0,
"email_to": args.recipient_id or "",
"subject": "Payment Request for %s"%args.dn,
"message": gateway_account.message,
"payment_url_message": gateway_account.payment_url_message,
"payment_success_url": gateway_account.payment_success_url,
"reference_doctype": args.dt,
"reference_name": args.dn
})
existing_payment_request = frappe.db.get_value("Payment Request",
{"reference_doctype": args.dt, "reference_name": args.dn})
if existing_payment_request:
pr = frappe.get_doc("Payment Request", existing_payment_request)
else:
pr = frappe.new_doc("Payment Request")
pr.update({
"payment_gateway": gateway_account.name,
"gateway": gateway_account.gateway,
"payment_account": gateway_account.payment_account,
"currency": ref_doc.currency,
"make_sales_invoice": args.cart or 0,
"amount": get_amount(ref_doc, args.dt),
"mute_email": args.mute_email or 0,
"email_to": args.recipient_id or "",
"subject": "Payment Request for %s"%args.dn,
"message": gateway_account.message,
"payment_url_message": gateway_account.payment_url_message,
"payment_success_url": gateway_account.payment_success_url,
"reference_doctype": args.dt,
"reference_name": args.dn
})
if args.return_doc:
return pr
if args.submit_doc:
pr.insert(ignore_permissions=True)
pr.submit()
if args.cart:
generate_payment_request(pr.name)
frappe.db.commit()
if not args.cart:
if args.return_doc:
return pr
if args.submit_doc:
pr.insert(ignore_permissions=True)
pr.submit()
if args.cart:
generate_payment_request(pr.name)
frappe.db.commit()
if not args.cart:
return pr
return pr.as_dict()

View File

@ -7,6 +7,7 @@
"custom": 0,
"docstatus": 0,
"doctype": "DocType",
"document_type": "Document",
"fields": [
{
"allow_on_submit": 0,
@ -24,6 +25,7 @@
"options": "Item",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"print_width": "100px",
"read_only": 0,
"report_hide": 0,
@ -33,6 +35,29 @@
"unique": 0,
"width": "100px"
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "column_break_2",
"fieldtype": "Column Break",
"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,
@ -48,6 +73,7 @@
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"print_width": "200px",
"read_only": 1,
"report_hide": 0,
@ -74,6 +100,31 @@
"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": 1,
"fieldname": "desc_section",
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Description",
"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,
@ -97,6 +148,31 @@
"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": "quantity_section",
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Quantity",
"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,
@ -119,6 +195,7 @@
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"print_width": "100px",
"read_only": 0,
"report_hide": 0,
@ -128,31 +205,6 @@
"unique": 0,
"width": "100px"
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "stock_uom",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "UOM",
"length": 0,
"no_copy": 0,
"options": "UOM",
"permlevel": 0,
"print_hide": 0,
"print_width": "100px",
"read_only": 1,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0,
"width": "100px"
},
{
"allow_on_submit": 0,
"bold": 0,
@ -168,6 +220,7 @@
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"print_width": "100px",
"read_only": 0,
"report_hide": 0,
@ -177,6 +230,55 @@
"unique": 0,
"width": "100px"
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "column_break_10",
"fieldtype": "Column Break",
"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": "stock_uom",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "UOM",
"length": 0,
"no_copy": 0,
"options": "UOM",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"print_width": "100px",
"read_only": 1,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0,
"width": "100px"
},
{
"allow_on_submit": 0,
"bold": 0,
@ -193,6 +295,7 @@
"options": "UOM",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"print_width": "100px",
"read_only": 0,
"report_hide": 0,
@ -217,6 +320,7 @@
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
@ -239,6 +343,7 @@
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
@ -256,7 +361,7 @@
"issingle": 0,
"istable": 1,
"max_attachments": 0,
"modified": "2015-11-16 06:29:51.313759",
"modified": "2016-02-09 14:46:32.332667",
"modified_by": "Administrator",
"module": "Stock",
"name": "Packing Slip Item",