[enhance] pay via cart
diff --git a/erpnext/accounts/doctype/payment_request/payment_request.json b/erpnext/accounts/doctype/payment_request/payment_request.json
index 0c0afdc..d69454c 100644
--- a/erpnext/accounts/doctype/payment_request/payment_request.json
+++ b/erpnext/accounts/doctype/payment_request/payment_request.json
@@ -86,6 +86,31 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
+ "depends_on": "eval:doc.reference_doctype==\"Sales Order\"",
+ "fieldname": "make_sales_invoice",
+ "fieldtype": "Check",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "in_filter": 0,
+ "in_list_view": 0,
+ "label": "Make Sales Invoice",
+ "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_5",
"fieldtype": "Column Break",
"hidden": 0,
@@ -484,7 +509,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
- "modified": "2015-12-29 12:56:45.456546",
+ "modified": "2015-12-30 17:43:10.626907",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Payment Request",
diff --git a/erpnext/accounts/doctype/payment_request/payment_request.py b/erpnext/accounts/doctype/payment_request/payment_request.py
index 4086a3c..df431b2 100644
--- a/erpnext/accounts/doctype/payment_request/payment_request.py
+++ b/erpnext/accounts/doctype/payment_request/payment_request.py
@@ -44,6 +44,13 @@
def set_status(self):
pass
+ def make_invoice(self):
+ if self.make_sales_invoice:
+ from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice
+ si = make_sales_invoice(self.reference_name, ignore_permissions=True)
+ si = frappe.get_doc(si).insert(ignore_permissions=True)
+ si.submit()
+
def send_payment_request(self):
self.payment_url = get_url("/api/method/erpnext.accounts.doctype.payment_request.payment_request.gererate_payemnt_request?name={0}".format(self.name))
if self.payment_url:
@@ -53,8 +60,11 @@
if frappe.session.user == "Guest":
frappe.set_user("Administrator")
- return self.create_journal_entry()
-
+ jv = self.create_journal_entry()
+ self.make_invoice()
+
+ return jv
+
def create_journal_entry(self):
"""create entry"""
payment_details = {
@@ -62,6 +72,8 @@
"return_obj": True,
"bank_account": self.payment_account
}
+
+ frappe.flags.ignore_account_permission = True
if self.reference_doctype == "Sales Order":
jv = get_payment_entry_against_order(self.reference_doctype, self.reference_name, payment_details)
@@ -73,7 +85,7 @@
"voucher_type": "Journal Entry",
"posting_date": nowdate()
})
-
+ jv.insert(ignore_permissions=True)
jv.submit()
#set status as paid for Payment Request
@@ -109,9 +121,10 @@
})
comm.insert(ignore_permissions=True)
-@frappe.whitelist()
+@frappe.whitelist(allow_guest=True)
def make_payment_request(**args):
"""Make payment request"""
+
args = frappe._dict(args)
ref_doc = get_reference_doc_details(args.dt, args.dn)
name, gateway, payment_account, message = get_gateway_details(args)
@@ -122,6 +135,7 @@
"gateway": gateway,
"payment_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 "",
@@ -137,8 +151,14 @@
if args.submit_doc:
pr.insert(ignore_permissions=True)
pr.submit()
- return pr
-
+
+ if args.cart:
+ gererate_payemnt_request(pr.name)
+ frappe.db.commit()
+
+ if not args.cart:
+ return pr
+
return pr.as_dict()
def get_reference_doc_details(dt, dn):
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index e7f2b8a..6f02a54 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -247,7 +247,7 @@
# will work as update after submit
jv_obj.flags.ignore_validate_update_after_submit = True
- jv_obj.save()
+ jv_obj.save(ignore_permissions=True)
def remove_against_link_from_jv(ref_type, ref_no):
linked_jv = frappe.db.sql_list("""select parent from `tabJournal Entry Account`
diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py
index 99e708d..dc21bd5 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.py
+++ b/erpnext/selling/doctype/sales_order/sales_order.py
@@ -401,7 +401,7 @@
return target_doc
@frappe.whitelist()
-def make_sales_invoice(source_name, target_doc=None):
+def make_sales_invoice(source_name, target_doc=None, ignore_permissions=False):
def postprocess(source, target):
set_missing_values(source, target)
#Get the advance paid Journal Entries in Sales Invoice Advance
@@ -410,6 +410,7 @@
def set_missing_values(source, target):
target.is_pos = 0
target.ignore_pricing_rule = 1
+ target.flags.ignore_permissions = True
target.run_method("set_missing_values")
target.run_method("calculate_taxes_and_totals")
@@ -442,7 +443,7 @@
"doctype": "Sales Team",
"add_if_empty": True
}
- }, target_doc, postprocess)
+ }, target_doc, postprocess, ignore_permissions=ignore_permissions)
return doclist
diff --git a/erpnext/templates/pages/order.html b/erpnext/templates/pages/order.html
index 26dbed6..f3c91b1 100644
--- a/erpnext/templates/pages/order.html
+++ b/erpnext/templates/pages/order.html
@@ -58,7 +58,7 @@
{% endif %}
</div>
<div class="col-sm-2 col-xs-3 text-right">
- {{ d.get_formatted("amount") }}
+ {{ d.get_formatted("amount") }}
{# output of get_formatted("rate") is unicode, to replace unicode use _("text {0}").decode("utf8").format(val) #}
<p class="text-muted small">{{
_("Rate: {0}").decode("utf8").format(d.get_formatted("rate")) }}</p>
@@ -76,4 +76,18 @@
</div>
</div>
+<div class="cart-taxes row small">
+ <div class="col-sm-8"><!-- empty --></div>
+ <div class="col-sm-4">
+ {% if doc.per_billed <= 0 %}
+ <div class="page-header-actions-block" data-html-block="header-actions">
+ <p>
+ <a href="/api/method/erpnext.accounts.doctype.payment_request.payment_request.make_payment_request?dn={{ doc.name }}&dt={{ doc.doctype }}&submit_doc=1&mute_email=1&cart=1"
+ class="btn btn-primary btn-sm">Pay {{ doc.get_formatted("grand_total") }} </a>
+ </p>
+ </div>
+ {% endif %}
+ </div>
+</div>
+
{% endblock %}