[enhance] pay via cart

This commit is contained in:
Saurabh 2015-12-31 13:26:36 +05:30
parent c22e525a14
commit 276d3e60bd
5 changed files with 71 additions and 11 deletions

View File

@ -82,6 +82,31 @@
"set_only_once": 0,
"unique": 0
},
{
"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,
@ -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",

View File

@ -44,6 +44,13 @@ class PaymentRequest(Document):
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 @@ class PaymentRequest(Document):
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 @@ class PaymentRequest(Document):
"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 @@ class PaymentRequest(Document):
"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 @@ class PaymentRequest(Document):
})
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 @@ def make_payment_request(**args):
"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 @@ def make_payment_request(**args):
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):

View File

@ -247,7 +247,7 @@ def update_against_doc(d, jv_obj):
# 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`

View File

@ -401,7 +401,7 @@ def make_delivery_note(source_name, target_doc=None):
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 make_sales_invoice(source_name, target_doc=None):
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 @@ def make_sales_invoice(source_name, target_doc=None):
"doctype": "Sales Team",
"add_if_empty": True
}
}, target_doc, postprocess)
}, target_doc, postprocess, ignore_permissions=ignore_permissions)
return doclist

View File

@ -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 %}