From e6a4f3a668b7186329166194121660348d6b486b Mon Sep 17 00:00:00 2001 From: monroy95 Date: Tue, 5 Jan 2021 00:47:03 +0000 Subject: [PATCH] #18 OK query Journal Entry/Account, OK obtencion data segun parametros, WIP generacion formatos PDF --- .../cambiare_cheque_print_set.py | 67 +++++++++++++++++-- 1 file changed, 60 insertions(+), 7 deletions(-) diff --git a/cambiare_gtq/cambiare_gtq/doctype/cambiare_cheque_print_set/cambiare_cheque_print_set.py b/cambiare_gtq/cambiare_gtq/doctype/cambiare_cheque_print_set/cambiare_cheque_print_set.py index 681090a..f9201c2 100755 --- a/cambiare_gtq/cambiare_gtq/doctype/cambiare_cheque_print_set/cambiare_cheque_print_set.py +++ b/cambiare_gtq/cambiare_gtq/doctype/cambiare_cheque_print_set/cambiare_cheque_print_set.py @@ -16,31 +16,36 @@ class CambiareChequePrintSet(Document): @frappe.whitelist() def get_data(params): - """[summary] + """ + Recolector/procesador de datos para generar formatos de impresion para cheques, + de Payment Entry Journal Entry, en funcion a acc bank, company, y fechas seleccionadas + en params Args: - params ([type]): [description] + params (dict): Parametros doctype Returns: - [type]: [description] + list: Lista diccionarios con misma estrucutra para tabla hija """ all_data = [] filters = frappe._dict(json.loads(params)) all_data.extend(get_data_of_payment_entry(filters)) + all_data.extend(get_data_of_journal_entry(filters)) return all_data def get_data_of_payment_entry(filters): - """[summary] + """ + Obtiene datos de Payment Entry, donde sean cheques (ver condicionales de query) Args: - filters ([type]): [description] + filters (dict): parametros user Returns: - [type]: [description] + list: lista diccionarios """ data = frappe.db.sql( @@ -50,8 +55,56 @@ def get_data_of_payment_entry(filters): FROM `tabPayment Entry` WHERE mode_of_payment='Cheque' AND company='{filters.company}' AND posting_date BETWEEN '{filters.start_date}' AND '{filters.end_date}' - AND bank_account='{filters.source_bank_acc}' + AND bank_account='{filters.source_bank_acc}' AND docstatus=1 """, as_dict=True ) or [] return data + + +def get_data_of_journal_entry(filters): + """ + Obtiene datos de Journal Entry/Account, donde sean cheques (ver condicionales de query) + + Args: + filters (dict): parametros user + + Returns: + list: lista diccionarios + """ + + data = frappe.db.sql( + f""" + SELECT JE.name AS id + FROM `tabJournal Entry` AS JE + JOIN `tabJournal Entry Account` AS JEA + WHERE JEA.parent=JE.name + AND JE.mode_of_payment='Cheque' + AND JE.company='{filters.company}' + AND (JE.posting_date BETWEEN '{filters.start_date}' AND '{filters.end_date}') + AND JEA.bank_account='{filters.source_bank_acc}' AND JE.docstatus=1 + """, as_dict=True + ) or [] + + # RE-Construccion datos desde Journal Entry/Accounts + all_data = [] + for data_je in data: + cheque_no = frappe.db.get_value('Journal Entry', {'name': data_je.get('id')}, 'cheque_no') + + amount = frappe.db.get_value('Journal Entry Account', + {'parent': data_je.get('id'), 'bank_account': filters.source_bank_acc}, + 'credit_in_account_currency') + + party_type = frappe.db.get_values('Journal Entry Account', + filters={'parent': data_je.get('id'), + 'party_type': ['!=', '']}, + fieldname=['party_type', 'party'], as_dict=1)[0] + all_data.append({ + 'transaction_id': 'Journal Entry', + 'cheque_no': cheque_no, + 'amount': amount, + 'party_type': party_type.get('party_type', ''), + 'third_party': party_type.get('party', '') + }) + + return all_data