def get_report_pdf(doc, consolidated=True): statement_dict = {} ageing = '' base_template_path = "frappe/www/printview.html" template_path = "erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.html" for entry in doc.customers: if doc.include_ageing: ageing_filters = frappe._dict({ 'company': doc.company, 'report_date': doc.to_date, 'ageing_based_on': doc.ageing_based_on, 'range1': 30, 'range2': 60, 'range3': 90, 'range4': 120, 'customer': entry.customer }) col1, ageing = get_ageing(ageing_filters) if ageing: ageing[0]['ageing_based_on'] = doc.ageing_based_on tax_id = frappe.get_doc('Customer', entry.customer).tax_id presentation_currency = get_party_account_currency('Customer', entry.customer, doc.company) \ or doc.currency or get_company_currency(doc.company) filters = frappe._dict({ 'from_date': doc.from_date, 'to_date': doc.to_date, 'company': doc.company, 'finance_book': doc.finance_book if doc.finance_book else None, 'account': doc.account if doc.account else None, 'party_type': 'Customer', 'party': [entry.customer], 'presentation_currency': presentation_currency, 'group_by': doc.group_by, 'currency': doc.currency, 'cost_center': [cc.cost_center_name for cc in doc.cost_center], 'project': [p.project_name for p in doc.project], 'show_opening_entries': 0, 'include_default_book_entries': 0, 'tax_id': tax_id if tax_id else None }) col, res = get_soa(filters) for x in [0, -2, -1]: res[x]['account'] = res[x]['account'].replace("'", "") if len(res) == 3: continue html = frappe.render_template(template_path, \ {"filters": filters, "data": res, "ageing": ageing[0] if (doc.include_ageing and ageing) else None}) html = frappe.render_template(base_template_path, {"body": html, \ "css": get_print_style(), "title": "Statement For " + entry.customer}) statement_dict[entry.customer] = html if not bool(statement_dict): return False elif consolidated: result = ''.join(list(statement_dict.values())) return get_pdf(result, {'orientation': doc.orientation}) else: for customer, statement_html in statement_dict.items(): statement_dict[customer] = get_pdf( statement_html, {'orientation': doc.orientation}) return statement_dict
def get_report_pdf(doc, consolidated=True): statement_dict = {} ageing = "" base_template_path = "frappe/www/printview.html" template_path = ( "erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.html" ) for entry in doc.customers: if doc.include_ageing: ageing_filters = frappe._dict({ "company": doc.company, "report_date": doc.to_date, "ageing_based_on": doc.ageing_based_on, "range1": 30, "range2": 60, "range3": 90, "range4": 120, "customer": entry.customer, }) col1, ageing = get_ageing(ageing_filters) if ageing: ageing[0]["ageing_based_on"] = doc.ageing_based_on tax_id = frappe.get_doc("Customer", entry.customer).tax_id presentation_currency = (get_party_account_currency( "Customer", entry.customer, doc.company) or doc.currency or get_company_currency(doc.company)) if doc.letter_head: from frappe.www.printview import get_letter_head letter_head = get_letter_head(doc, 0) filters = frappe._dict({ "from_date": doc.from_date, "to_date": doc.to_date, "company": doc.company, "finance_book": doc.finance_book if doc.finance_book else None, "account": [doc.account] if doc.account else None, "party_type": "Customer", "party": [entry.customer], "presentation_currency": presentation_currency, "group_by": doc.group_by, "currency": doc.currency, "cost_center": [cc.cost_center_name for cc in doc.cost_center], "project": [p.project_name for p in doc.project], "show_opening_entries": 0, "include_default_book_entries": 0, "tax_id": tax_id if tax_id else None, }) col, res = get_soa(filters) for x in [0, -2, -1]: res[x]["account"] = res[x]["account"].replace("'", "") if len(res) == 3: continue html = frappe.render_template( template_path, { "filters": filters, "data": res, "ageing": ageing[0] if (doc.include_ageing and ageing) else None, "letter_head": letter_head if doc.letter_head else None, "terms_and_conditions": frappe.db.get_value("Terms and Conditions", doc.terms_and_conditions, "terms") if doc.terms_and_conditions else None, }, ) html = frappe.render_template( base_template_path, { "body": html, "css": get_print_style(), "title": "Statement For " + entry.customer }, ) statement_dict[entry.customer] = html if not bool(statement_dict): return False elif consolidated: result = "".join(list(statement_dict.values())) return get_pdf(result, {"orientation": doc.orientation}) else: for customer, statement_html in statement_dict.items(): statement_dict[customer] = get_pdf( statement_html, {"orientation": doc.orientation}) return statement_dict