Skip to content

Commit

Permalink
Mejora en obtencion de datos y boton para factura
Browse files Browse the repository at this point in the history
  • Loading branch information
monroy95 committed Nov 6, 2017
1 parent d715143 commit 3fbc47a
Show file tree
Hide file tree
Showing 10 changed files with 265 additions and 26 deletions.
24 changes: 13 additions & 11 deletions factura_electronica/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ def generar_factura_electronica(serie_factura, nombre_cliente):

frappe.msgprint(_('<b>AVISO:</b> La Factura ya fue generada Anteriormente <b>{}</b>'.format(str(factura_electronica[0]['serie_factura_original']))))

cae_Fac = str(factura_electronica[0]['cae'])
cae_factura = str(factura_electronica[0]['cae'])

return cae_Fac
return cae_factura
except:
# es-GT: Si ocurre un error en la obtencion de datos de la base de datos, retornara un error.
# en-US: If an error occurs in obtaining data from the database, an error will return.
Expand All @@ -50,7 +50,12 @@ def generar_factura_electronica(serie_factura, nombre_cliente):
sales_invoice = frappe.db.get_values('Sales Invoice', filters = {'name': dato_factura},
fieldname = ['name', 'idx', 'territory','grand_total', 'customer_name', 'company',
'naming_series', 'creation', 'status', 'discount_amount', 'docstatus', 'modified', 'conversion_rate',
'total_taxes_and_charges', 'net_total'], as_dict = 1)
'total_taxes_and_charges', 'net_total', 'shipping_address_name'], as_dict = 1)

direccion_cliente = str(sales_invoice[0]['shipping_address_name'])

datos_cliente = frappe.db.get_values('Address', filters = {'name': direccion_cliente},
fieldname = ['email_id', 'country', 'city', 'address_line1', 'state', 'phone', 'address_title', 'name'], as_dict = 1)

sales_invoice_item = frappe.db.get_values('Sales Invoice Item', filters = {'parent': dato_factura},
fieldname = ['item_name', 'qty', 'item_code', 'description', 'net_amount', 'base_net_amount',
Expand All @@ -59,9 +64,6 @@ def generar_factura_electronica(serie_factura, nombre_cliente):
datos_compania = frappe.db.get_values('Company', filters = {'name': str(sales_invoice[0]['company'])},
fieldname = ['company_name', 'default_currency', 'country', 'nit_face_company'], as_dict = 1)

datos_cliente = frappe.db.get_values('Address', filters = {'address_title': dato_cliente},
fieldname = ['email_id', 'country', 'city', 'address_line1', 'state', 'phone', 'address_title'], as_dict = 1)

nit_cliente = frappe.db.get_values('Customer', filters = {'name': dato_cliente},
fieldname = 'nit_face_customer')

Expand All @@ -79,7 +81,7 @@ def generar_factura_electronica(serie_factura, nombre_cliente):
try:
# es-GT: Si no encuentra datos sobre el cliente, el "try" capturara el error y pondra los campos con valor 'N/A'.
# en-US: If it does not find data about the client, the "try" will capture the error and put the fields with value 'N/A'.
if ((datos_cliente[0]['address_title']) is None): fallo = True
if ((datos_cliente[0]['name']) is None): fallo = True
except:
correoCompradorTag_Value = 'N/A'
departamentoCompradorTag_Value = 'N/A'
Expand All @@ -95,12 +97,12 @@ def generar_factura_electronica(serie_factura, nombre_cliente):
else:
correoCompradorTag_Value = str(datos_cliente[0]['email_id'])

if ((datos_cliente[0]['state']) is None):
if ((datos_cliente[0]['state']) == ''):
departamentoCompradorTag_Value = 'N/A'
else:
departamentoCompradorTag_Value = str(datos_cliente[0]['state'])

if ((datos_cliente[0]['address_line1']) is None):
if ((datos_cliente[0]['address_line1']) == ''):
direccionComercialCompradorTag_Value = 'N/A'
else:
direccionComercialCompradorTag_Value = str((datos_cliente[0]['address_line1']).encode('utf-8'))
Expand All @@ -110,12 +112,12 @@ def generar_factura_electronica(serie_factura, nombre_cliente):
else:
nombreComercialCompradorTag_Value = str(sales_invoice[0]['customer_name'])

if ((datos_cliente[0]['phone']) is None):
if ((datos_cliente[0]['phone']) == ''):
telefonoCompradorTag_Value = 'N/A'
else:
telefonoCompradorTag_Value = str(datos_cliente[0]['phone'])

if ((datos_cliente[0]['state']) is None):
if ((datos_cliente[0]['state']) == ''):
municipioCompradorTag_Value = 'N/A'
else:
municipioCompradorTag_Value = str(datos_cliente[0]['state'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// For license information, please see license.txt

frappe.ui.form.on('Configuracion Factura Electronica', {
refresh: function(frm) {
refresh: function(frm) {

}
});
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,67 @@
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "configuracion_de_series",
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Configuracion de Series",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 1,
"collapsible": 0,
"columns": 0,
"fieldname": "configuracion_series",
"fieldtype": "Table",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Configuracion Series",
"length": 0,
"no_copy": 0,
"options": "Configuracion Series",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
}
],
"has_web_view": 0,
Expand All @@ -719,7 +780,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2017-10-28 01:41:46.867912",
"modified": "2017-11-03 21:42:21.611824",
"modified_by": "Administrator",
"module": "Factura Electronica",
"name": "Configuracion Factura Electronica",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.model.document import Document

class ConfiguracionFacturaElectronica(Document):
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
{
"allow_copy": 0,
"allow_guest_to_view": 0,
"allow_import": 0,
"allow_rename": 0,
"beta": 0,
"creation": "2017-11-03 21:40:51.863162",
"custom": 0,
"docstatus": 0,
"doctype": "DocType",
"document_type": "",
"editable_grid": 1,
"engine": "InnoDB",
"fields": [
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "serie",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Serie",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "tipo_documento",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Tipo Documento",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "secuencia_infile",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Secuencia INFILE",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "numero_resolucion",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Numero Resolucion",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
}
],
"has_web_view": 0,
"hide_heading": 0,
"hide_toolbar": 0,
"idx": 0,
"image_view": 0,
"in_create": 0,
"is_submittable": 0,
"issingle": 0,
"istable": 1,
"max_attachments": 0,
"modified": "2017-11-03 21:40:51.863162",
"modified_by": "Administrator",
"module": "Factura Electronica",
"name": "Configuracion Series",
"name_case": "",
"owner": "Administrator",
"permissions": [],
"quick_entry": 1,
"read_only": 0,
"read_only_onload": 0,
"show_name_in_global_search": 0,
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 1,
"track_seen": 0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2017, Frappe and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
import frappe
from frappe.model.document import Document

class ConfiguracionSeries(Document):
pass
6 changes: 3 additions & 3 deletions factura_electronica/fixtures/custom_field.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"allow_on_submit": 0,
"allow_on_submit": 1,
"bold": 0,
"collapsible": 0,
"collapsible_depends_on": null,
Expand All @@ -12,7 +12,7 @@
"doctype": "Custom Field",
"dt": "Sales Invoice",
"fieldname": "cae_factura_electronica",
"fieldtype": "Read Only",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
Expand All @@ -21,7 +21,7 @@
"in_standard_filter": 0,
"insert_after": "due_date",
"label": "CAE Factura Electronica",
"modified": "2017-10-16 22:06:23.555415",
"modified": "2017-11-05 20:14:52.597107",
"name": "Sales Invoice-cae_factura_electronica",
"no_copy": 0,
"options": null,
Expand Down
11 changes: 6 additions & 5 deletions factura_electronica/public/js/facelec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ frappe.ui.form.on("Sales Invoice", "refresh", function(frm) {
serie_factura: frm.doc.name,
nombre_cliente: frm.doc.customer
},
callback: function(r) {

frm.set_value('cae_factura_electronica', r.message);
//console.log(frm.doc.cae_factura_electronica);
//frm.reload_doc();
callback: function(data) {
//frm.cae_factura_electronica = r.message;
//cur_frm.set_value("cae_factura_electronica", data.message);
//cur_frm.refresh_field('cae_factura_electronica');
cur_frm.set_value("cae_factura_electronica", data.message);
//frm.save();
if (frm.doc.cae_factura_electronica) {
cur_frm.clear_custom_buttons();
pdf_button();
Expand Down
Loading

0 comments on commit 3fbc47a

Please sign in to comment.