From 6e0a00b5374a3171a445cf84836733dd6c646e93 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Fri, 22 Jul 2016 15:17:17 +0530 Subject: [PATCH] [minor][fix] flag fix for payment entry creation via payment request --- .../accounts/doctype/payment_request/payment_request.js | 2 +- .../accounts/doctype/payment_request/payment_request.py | 9 ++++----- erpnext/demo/user/accounts.py | 6 ++++-- erpnext/demo/user/sales.py | 6 ++++-- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/erpnext/accounts/doctype/payment_request/payment_request.js b/erpnext/accounts/doctype/payment_request/payment_request.js index d57045fea7..afc3804ff7 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.js +++ b/erpnext/accounts/doctype/payment_request/payment_request.js @@ -33,7 +33,7 @@ frappe.ui.form.on("Payment Request", "refresh", function(frm) { } if(!frm.doc.payment_gateway_account && frm.doc.status == "Initiated") { - frm.add_custom_button(__('Mark Payment Entry'), function(){ + frm.add_custom_button(__('Make Payment Entry'), function(){ frappe.call({ method: "erpnext.accounts.doctype.payment_request.payment_request.make_payment_entry", args: {"docname": frm.doc.name}, diff --git a/erpnext/accounts/doctype/payment_request/payment_request.py b/erpnext/accounts/doctype/payment_request/payment_request.py index 665fc9064a..30d043f729 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.py +++ b/erpnext/accounts/doctype/payment_request/payment_request.py @@ -73,7 +73,7 @@ class PaymentRequest(Document): return payment_entry - def create_payment_entry(self): + def create_payment_entry(self, submit=True): """create entry""" frappe.flags.ignore_account_permission = True @@ -113,7 +113,7 @@ class PaymentRequest(Document): "amount": payment_entry.difference_amount }) - if not self.flags.make_draft_payment_entry: + if submit: payment_entry.insert(ignore_permissions=True) payment_entry.submit() @@ -264,10 +264,9 @@ def resend_payment_email(docname): return frappe.get_doc("Payment Request", docname).send_email() @frappe.whitelist() -def make_payment_entry(docname, make_draft_payment_entry=True): +def make_payment_entry(docname): doc = frappe.get_doc("Payment Request", docname) - doc.flags.make_draft_payment_entry = make_draft_payment_entry - return doc.set_as_paid().as_dict() + return doc.create_payment_entry(submit=False).as_dict() def make_status_as_paid(doc, method): for ref in doc.references: diff --git a/erpnext/demo/user/accounts.py b/erpnext/demo/user/accounts.py index 36a79f621d..052d4560ef 100644 --- a/erpnext/demo/user/accounts.py +++ b/erpnext/demo/user/accounts.py @@ -57,12 +57,14 @@ def work(): payment_request = make_payment_request(dt="Sales Invoice", dn=si.name, recipient_id=si.contact_email, submit_doc=True, mute_email=True, use_dummy_message=True) - make_payment_entry(payment_request.name, make_draft_payment_entry=False) + payment_entry = frappe.get_doc(make_payment_entry(payment_request.name)) + payment_entry.posting_date = frappe.flags.current_date + payment_entry.submit() def make_payment_entries(ref_doctype, report): outstanding_invoices = list(set([r[3] for r in query_report.run(report, {"report_date": frappe.flags.current_date })["result"] if r[2]==ref_doctype])) - + # make Payment Entry for inv in outstanding_invoices[:random.randint(1, 2)]: pe = get_payment_entry(ref_doctype, inv) diff --git a/erpnext/demo/user/sales.py b/erpnext/demo/user/sales.py index cd008a93c0..10df14334f 100644 --- a/erpnext/demo/user/sales.py +++ b/erpnext/demo/user/sales.py @@ -41,11 +41,13 @@ def work(): sales_order_name = get_random("Sales Order", filters={"docstatus": 1}) if sales_order_name: so = frappe.get_doc("Sales Order", sales_order_name) - if (flt(so.grand_total) - flt(so.advance_paid)) > 0: + if flt(so.per_billed) != 100: payment_request = make_payment_request(dt="Sales Order", dn=so.name, recipient_id=so.contact_email, submit_doc=True, mute_email=True, use_dummy_message=True) - make_payment_entry(payment_request.name, make_draft_payment_entry=False) + payment_entry = frappe.get_doc(make_payment_entry(payment_request.name)) + payment_entry.posting_date = frappe.flags.current_date + payment_entry.submit() def make_opportunity(): b = frappe.get_doc({