Skip to content

Commit 523ded5

Browse files
committed
#157 #169 Generando declaraciones impuestos, con actualizacion de factura haciendo referencia
1 parent 47d7caf commit 523ded5

File tree

1 file changed

+38
-16
lines changed

1 file changed

+38
-16
lines changed

factura_electronica/factura_electronica/report/purchase_and_sales_ledger_tax_declaration/generate_tax_declaration.py

+38-16
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,44 @@ def generate_vat_declaration(company, year, month, declared, report_data):
4141

4242
# 4.1 - Verificamos que no existan un registro duplicado
4343
if not frappe.db.exists('VAT Declaration', {'name': f"VAT Declaration {date.today()}"}):
44-
vat_dec = frappe.get_doc({
45-
"doctype": "VAT Declaration",
46-
"title": f"VAT Declaration {date.today()}",
47-
"company": company,
48-
"posting_date": date.today(),
49-
"declaration_year": year,
50-
"declaration_month": MONTHS_MAP.get(str(month)),
51-
"declaration_items": declaration_invoices,
52-
"docstatus": 1
53-
})
54-
55-
# for validated documents: status_journal = vat_dec.insert(ignore_permissions=True)
56-
# status_declaration = vat_dec.save(ignore_permissions=True)
57-
status_declaration = vat_dec.insert(ignore_permissions=True)
58-
59-
# 5 - Actualizamos las facturas con su nueva Referencia en campo de tipo data,
44+
# CREAMOS EL REGISTRO COMO VALIDADO
45+
try:
46+
vat_dec = frappe.get_doc({
47+
"doctype": "VAT Declaration",
48+
"title": f"VAT Declaration {date.today()}",
49+
"company": company,
50+
"posting_date": date.today(),
51+
"declaration_year": year,
52+
"declaration_month": MONTHS_MAP.get(str(month)),
53+
"declaration_items": declaration_invoices,
54+
"docstatus": 1
55+
})
56+
57+
# for validated documents: status_journal = vat_dec.insert(ignore_permissions=True)
58+
# status_declaration = vat_dec.save(ignore_permissions=True)
59+
status_declaration = vat_dec.insert(ignore_permissions=True)
60+
61+
# SI OCURRE ALGUN ERROR
62+
except:
63+
frappe.msgprint(msg=_(f'More details in the following log \n {frappe.get_traceback()}'),
64+
title=_('Sorry, a problem occurred while trying to generate the VAT declaration'), indicator='red')
65+
return
66+
67+
# SI LA CREACION ES EXITOSA, ACTUALIZAMOS LAS FACTURAS CON LA REFERENCIA
68+
else:
69+
# Por cada factura venta, compra
70+
for record in records:
71+
if record.get('compras_ventas') == 'V': # si es venta
72+
frappe.db.sql('''UPDATE `tabSales Invoice`
73+
SET facelec_s_vat_declaration=%(declaration)s
74+
WHERE name=%(name_inv)s
75+
''', {'declaration': status_declaration.name, 'name_inv': str(record.get('invoice_name'))})
76+
77+
else: # si es compra
78+
frappe.db.sql('''UPDATE `tabPurchase Invoice`
79+
SET facelec_p_vat_declaration=%(declaration)s
80+
WHERE name=%(name_inv)s
81+
''', {'declaration': status_declaration.name, 'name_inv': str(record.get('invoice_name'))})
6082

6183
else:
6284
nme_reg = f'VAT Declaration {date.today()}'

0 commit comments

Comments
 (0)