Skip to content

Commit 9a26362

Browse files
#169 saving a new vat declaration
1 parent 1980017 commit 9a26362

File tree

4 files changed

+3230
-3201
lines changed

4 files changed

+3230
-3201
lines changed

factura_electronica/factura_electronica/report/purchase_and_sales_ledger_tax_declaration/generate_tax_declaration.py

+30-20
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,49 @@
77
import os
88

99
@frappe.whitelist()
10-
def generate_vat_declaration(filters, report_data):
10+
def generate_vat_declaration(company, year, month, declared):
1111
try:
12+
# Cargar report_data con json load.
13+
# en_US: Loads the received data as if it was a json into a dictionary
14+
# es: Carga como json-diccionario la data recibida
15+
# documents = json.loads(report_data)
1216
# TODO
1317
# Crear Vat declaration
1418
# Opcion 1:
1519
# CON JS: si se desea obtener la data desde el report, se obtiene como argumento report.data
1620
# CON PY: De lo contrario, obviamos lo de arriba y solo trabajamos lo de abajo:
1721
# Necesitamos filters del report, pasados como argumentos desde el frappe.call: declared , company, month, year, []
1822
# validaciones:
19-
if filters.declared == 'Not Declared':
20-
# Generate doctype for vat declaration
21-
this_dec = frappe.get_doc("VAT Declaration")
22-
this_dec.title = "Hello VAT Declaration"
23-
this_dec.company = filters.company
24-
this_dec.declaration_year = filters.year
25-
this_dec.declaration_month = filters.month
26-
this_dec.declaration_month = filters.month
27-
this_dec.posting_date = "2020-07-17"
28-
this_dec.declaration_items = [
29-
{
30-
"link_doctype": "Purchase Invoice",
31-
"link_name": "ACC-PINV-2020-00001"
32-
}
33-
]
34-
this_dec.save()
23+
# frappe.msgprint((str(company) + str(year) + str(month) + str(declared)))
24+
if declared == 'Not Declared':
25+
vat_dec = frappe.get_doc({
26+
"doctype": "VAT Declaration",
27+
"title": "Hello VAT Declaration",
28+
"company": company,
29+
"posting_date": "2020-07-17",
30+
"declaration_year": year,
31+
"declaration_month": 7,
32+
"declaration_items": [
33+
{
34+
"link_doctype": "Purchase Invoice",
35+
"link_name": "ACC-PINV-2020-00001"
36+
}
37+
],
38+
"docstatus": 0
39+
})
40+
# for validated documents: status_journal = vat_dec.insert(ignore_permissions=True)
41+
status_declaration = vat_dec.save(ignore_permissions=True)
42+
3543
# Se agrega al vat declararion el item de cada factura presente en esta declaracion
3644
# Al guardar se agrega a cada una de las facturas el Doctype, Doctype ID o title en el campo de child table Dynamic Link
3745
# A cada factura de las que tocamos, le agregamos al campo custom field, el titulo de ESTA VAT Declaration que creamos.
3846
else:
3947
# We somehow tried to send the declared or all non declared and declared documents. This is not allowed for our purpose!
40-
pass
48+
pass
4149
except:
42-
frappe.msgprint("algo salio mal")
50+
frappe.msgprint("algo salio mal" + str(frappe.get_traceback()))
51+
4352
else:
44-
frappe.msgprint("estas fregado")
53+
frappe.msgprint("no estas fregado")
54+
4555

factura_electronica/factura_electronica/report/purchase_and_sales_ledger_tax_declaration/purchase_and_sales_ledger_tax_declaration.js

+22-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ frappe.query_reports["Purchase and Sales Ledger Tax Declaration"] = {
99
label: __("Company"),
1010
fieldtype: "Link",
1111
options: "Company",
12-
default: "",
12+
default: "SHS",
1313
reqd: 1,
1414
on_change: function () {
1515
frappe.db
@@ -92,13 +92,32 @@ frappe.query_reports["Purchase and Sales Ledger Tax Declaration"] = {
9292
if (frappe.query_report.get_filter_value('declared') == "Not Declared") {
9393
report.page.add_inner_button(__("Generate Declaration"), function () {
9494
//window.open("/api/method/factura_electronica.api_erp.download_asl_files");
95-
window.open("sihaysistema.com", "_blank");
95+
// window.open("sihaysistema.com", "_blank");
96+
//console.log(report.filters);
97+
//console.log(report.data);
98+
frappe.call({
99+
method: "factura_electronica.factura_electronica.report.purchase_and_sales_ledger_tax_declaration.generate_tax_declaration.generate_vat_declaration",
100+
args: {
101+
// Dummy Data
102+
company: frappe.query_report.get_filter_value('company'),
103+
year: frappe.query_report.get_filter_value('year'),
104+
month: frappe.query_report.get_filter_value('month'),
105+
declared: frappe.query_report.get_filter_value('declared')
106+
107+
},
108+
callback: function (r) {
109+
// We show an alert that the vat declaration was generated.
110+
frappe.show_alert({
111+
indicator: 'orange',
112+
message: __("Declaration created") //r.message
113+
});
114+
}
115+
});
96116
}).addClass("btn-danger");
97117
}
98118
else {
99119
report.page.remove_inner_button(__("Generate Declaration"));
100120
}
101-
console.log(report);
102121
},
103122
}
104123
],

factura_electronica/fixtures/custom_field.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -10365,7 +10365,7 @@
1036510365
"fetch_from": null,
1036610366
"fetch_if_empty": 0,
1036710367
"fieldname": "facelec_p_vat_declaration",
10368-
"fieldtype": "Link",
10368+
"fieldtype": "Data",
1036910369
"hidden": 0,
1037010370
"ignore_user_permissions": 0,
1037110371
"ignore_xss_filter": 0,
@@ -10375,10 +10375,10 @@
1037510375
"insert_after": "facelec_p_total_iva",
1037610376
"label": "VAT Declaration",
1037710377
"length": 0,
10378-
"modified": "2020-07-17 16:23:11.672931",
10378+
"modified": "2020-07-17 18:55:34.807972",
1037910379
"name": "Purchase Invoice-facelec_p_vat_declaration",
1038010380
"no_copy": 0,
10381-
"options": "VAT Declaration",
10381+
"options": "",
1038210382
"parent": null,
1038310383
"parentfield": null,
1038410384
"parenttype": null,
@@ -11745,7 +11745,7 @@
1174511745
"fetch_from": null,
1174611746
"fetch_if_empty": 0,
1174711747
"fieldname": "facelec_s_vat_declaration",
11748-
"fieldtype": "Link",
11748+
"fieldtype": "Data",
1174911749
"hidden": 0,
1175011750
"ignore_user_permissions": 0,
1175111751
"ignore_xss_filter": 0,
@@ -11755,10 +11755,10 @@
1175511755
"insert_after": "taxes_section",
1175611756
"label": "VAT Declaration",
1175711757
"length": 0,
11758-
"modified": "2020-07-17 16:28:04.942076",
11758+
"modified": "2020-07-17 18:55:44.143736",
1175911759
"name": "Sales Invoice-facelec_s_vat_declaration",
1176011760
"no_copy": 0,
11761-
"options": "VAT Declaration",
11761+
"options": "",
1176211762
"parent": null,
1176311763
"parentfield": null,
1176411764
"parenttype": null,

0 commit comments

Comments
 (0)