From e93ac3c9a8eb9b83b7fc5523c775cacdea22e57f Mon Sep 17 00:00:00 2001 From: Dany Robert Date: Mon, 17 Oct 2022 14:29:03 +0200 Subject: [PATCH 1/6] feat: page break in SoA pdf --- .../process_statement_of_accounts.js | 8 +++++--- .../process_statement_of_accounts.json | 10 +++++++++- .../process_statement_of_accounts.py | 9 ++++++--- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.js b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.js index 29f2e98e779..7dd5ef36f29 100644 --- a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.js +++ b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.js @@ -8,7 +8,8 @@ frappe.ui.form.on('Process Statement Of Accounts', { }, refresh: function(frm){ if(!frm.doc.__islocal) { - frm.add_custom_button('Send Emails',function(){ + frm.add_custom_button(__('Send Emails'), function(){ + if (frm.is_dirty()) frappe.throw(__("Please save before proceeding.")) frappe.call({ method: "erpnext.accounts.doctype.process_statement_of_accounts.process_statement_of_accounts.send_emails", args: { @@ -24,8 +25,9 @@ frappe.ui.form.on('Process Statement Of Accounts', { } }); }); - frm.add_custom_button('Download',function(){ - var url = frappe.urllib.get_full_url( + frm.add_custom_button(__('Download'), function(){ + if (frm.is_dirty()) frappe.throw(__("Please save before proceeding.")) + let url = frappe.urllib.get_full_url( '/api/method/erpnext.accounts.doctype.process_statement_of_accounts.process_statement_of_accounts.download_statements?' + 'document_name='+encodeURIComponent(frm.doc.name)) $.ajax({ diff --git a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.json b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.json index a35374c6242..2f62a0295fb 100644 --- a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.json +++ b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.json @@ -27,6 +27,7 @@ "customers", "preferences", "orientation", + "include_break", "include_ageing", "ageing_based_on", "section_break_14", @@ -284,10 +285,16 @@ "fieldtype": "Link", "label": "Terms and Conditions", "options": "Terms and Conditions" + }, + { + "default": "1", + "fieldname": "include_break", + "fieldtype": "Check", + "label": "Page Break After Each SoA" } ], "links": [], - "modified": "2021-09-06 21:00:45.732505", + "modified": "2022-10-17 17:47:08.662475", "modified_by": "Administrator", "module": "Accounts", "name": "Process Statement Of Accounts", @@ -320,5 +327,6 @@ ], "sort_field": "modified", "sort_order": "DESC", + "states": [], "track_changes": 1 } \ No newline at end of file diff --git a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py index 01f716daa21..2256871e423 100644 --- a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py +++ b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py @@ -128,7 +128,8 @@ def get_report_pdf(doc, consolidated=True): if not bool(statement_dict): return False elif consolidated: - result = "".join(list(statement_dict.values())) + delimiter = '
' if doc.include_break else "" + result = delimiter.join(list(statement_dict.values())) return get_pdf(result, {"orientation": doc.orientation}) else: for customer, statement_html in statement_dict.items(): @@ -240,8 +241,8 @@ def fetch_customers(customer_collection, collection_name, primary_mandatory): if int(primary_mandatory): if primary_email == "": continue - elif (billing_email == "") and (primary_email == ""): - continue + # elif (billing_email == "") and (primary_email == ""): + # continue customer_list.append( {"name": customer.name, "primary_email": primary_email, "billing_email": billing_email} @@ -313,6 +314,8 @@ def send_emails(document_name, from_scheduler=False): attachments = [{"fname": customer + ".pdf", "fcontent": report_pdf}] recipients, cc = get_recipients_and_cc(customer, doc) + if not recipients: + continue context = get_context(customer, doc) subject = frappe.render_template(doc.subject, context) message = frappe.render_template(doc.body, context) From 88ce59a1cacb354db8629597a27764409c593c75 Mon Sep 17 00:00:00 2001 From: Dany Robert Date: Mon, 17 Oct 2022 15:54:46 +0200 Subject: [PATCH 2/6] fix: query condition change --- .../process_statement_of_accounts.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py index 2256871e423..48bc3a1bdd2 100644 --- a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py +++ b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py @@ -6,6 +6,7 @@ import copy import frappe from frappe import _ +from frappe.desk.reportview import get_match_cond from frappe.model.document import Document from frappe.utils import add_days, add_months, format_date, getdate, today from frappe.utils.jinja import validate_template @@ -274,8 +275,12 @@ def get_customer_emails(customer_name, primary_mandatory, billing_and_primary=Tr link.link_doctype='Customer' and link.link_name=%s and contact.is_billing_contact=1 + {mcond} ORDER BY - contact.creation desc""", + contact.creation desc + """.format( + mcond=get_match_cond("Contact") + ), customer_name, ) From 95f81d3563bb7f57ff804351e7d977c0528203ae Mon Sep 17 00:00:00 2001 From: Dany Robert Date: Thu, 27 Oct 2022 09:33:49 +0530 Subject: [PATCH 3/6] chore: remove commented line --- .../process_statement_of_accounts.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py index 48bc3a1bdd2..c6b0c57ce5c 100644 --- a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py +++ b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py @@ -242,8 +242,6 @@ def fetch_customers(customer_collection, collection_name, primary_mandatory): if int(primary_mandatory): if primary_email == "": continue - # elif (billing_email == "") and (primary_email == ""): - # continue customer_list.append( {"name": customer.name, "primary_email": primary_email, "billing_email": billing_email} From d6901e51ade7e17f5581be49574bf03729070903 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Sat, 12 Nov 2022 17:32:04 +0530 Subject: [PATCH 4/6] chore: Remove raw SQL query (cherry picked from commit 42a59d5c171da96bccaf657eb87454040a9cc84c) --- .../doctype/bank_guarantee/bank_guarantee.js | 13 ++------- .../doctype/bank_guarantee/bank_guarantee.py | 28 +++++++++---------- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.js b/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.js index febf85ca6c1..99cc0a72fb3 100644 --- a/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.js +++ b/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.js @@ -43,20 +43,13 @@ frappe.ui.form.on('Bank Guarantee', { reference_docname: function(frm) { if (frm.doc.reference_docname && frm.doc.reference_doctype) { - let fields_to_fetch = ["grand_total"]; let party_field = frm.doc.reference_doctype == "Sales Order" ? "customer" : "supplier"; - if (frm.doc.reference_doctype == "Sales Order") { - fields_to_fetch.push("project"); - } - - fields_to_fetch.push(party_field); frappe.call({ - method: "erpnext.accounts.doctype.bank_guarantee.bank_guarantee.get_vouchar_detials", + method: "erpnext.accounts.doctype.bank_guarantee.bank_guarantee.get_voucher_details", args: { - "column_list": fields_to_fetch, - "doctype": frm.doc.reference_doctype, - "docname": frm.doc.reference_docname + "bank_guarantee_type": frm.doc.bg_type, + "reference_name": frm.doc.reference_docname }, callback: function(r) { if (r.message) { diff --git a/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py b/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py index 9144a29c6ef..a57acda680c 100644 --- a/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py +++ b/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py @@ -2,11 +2,8 @@ # For license information, please see license.txt -import json - import frappe from frappe import _ -from frappe.desk.search import sanitize_searchfield from frappe.model.document import Document @@ -25,14 +22,17 @@ class BankGuarantee(Document): @frappe.whitelist() -def get_vouchar_detials(column_list, doctype, docname): - column_list = json.loads(column_list) - for col in column_list: - sanitize_searchfield(col) - return frappe.db.sql( - """ select {columns} from `tab{doctype}` where name=%s""".format( - columns=", ".join(column_list), doctype=doctype - ), - docname, - as_dict=1, - )[0] +def get_voucher_details(bank_guarantee_type, reference_name): + fields_to_fetch = ["grand_total"] + + doctype = "Sales Order" if bank_guarantee_type == "Receiving" else "Purchase Order" + + if doctype == "Sales Order": + fields_to_fetch.append("customer") + fields_to_fetch.append("project") + else: + fields_to_fetch.append("supplier") + + bg_doctype = frappe.qb.DocType("Bank Guarantee") + + return frappe.db.get_value(doctype, reference_name, fields_to_fetch, as_dict=True) From 9c9c6607f83b19e0ecb95ba134190ac1079a7602 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Sun, 13 Nov 2022 18:48:32 +0530 Subject: [PATCH 5/6] chore: Remove qb doc reference (cherry picked from commit 4b9921782b0427ae4882d186d37fdb960671eed7) --- erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py b/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py index a57acda680c..0e3f7d75716 100644 --- a/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py +++ b/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py @@ -33,6 +33,4 @@ def get_voucher_details(bank_guarantee_type, reference_name): else: fields_to_fetch.append("supplier") - bg_doctype = frappe.qb.DocType("Bank Guarantee") - return frappe.db.get_value(doctype, reference_name, fields_to_fetch, as_dict=True) From ad648f313c9adf66dfe841f5dfd0d897e8697ae6 Mon Sep 17 00:00:00 2001 From: Sagar Vora Date: Sun, 13 Nov 2022 19:58:49 +0530 Subject: [PATCH 6/6] fix: check type for reference name (cherry picked from commit b06345af46d8469b46cdf795389a589c58729439) --- .../accounts/doctype/bank_guarantee/bank_guarantee.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py b/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py index 0e3f7d75716..02eb599acc8 100644 --- a/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py +++ b/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py @@ -22,15 +22,18 @@ class BankGuarantee(Document): @frappe.whitelist() -def get_voucher_details(bank_guarantee_type, reference_name): +def get_voucher_details(bank_guarantee_type: str, reference_name: str): + if not isinstance(reference_name, str): + raise TypeError("reference_name must be a string") + fields_to_fetch = ["grand_total"] - doctype = "Sales Order" if bank_guarantee_type == "Receiving" else "Purchase Order" - - if doctype == "Sales Order": + if bank_guarantee_type == "Receiving": + doctype = "Sales Order" fields_to_fetch.append("customer") fields_to_fetch.append("project") else: + doctype = "Purchase Order" fields_to_fetch.append("supplier") return frappe.db.get_value(doctype, reference_name, fields_to_fetch, as_dict=True)