Skip to content

Commit

Permalink
#18 OK query Journal Entry/Account, OK obtencion data segun parametro…
Browse files Browse the repository at this point in the history
…s, WIP generacion formatos PDF
  • Loading branch information
monroy95 committed Jan 5, 2021
1 parent 683dfbf commit e6a4f3a
Showing 1 changed file with 60 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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

0 comments on commit e6a4f3a

Please sign in to comment.