From 3fbc47a74b6668928cb25ce80b5e6f3a5f6a60ed Mon Sep 17 00:00:00 2001 From: monroy95 Date: Mon, 6 Nov 2017 12:39:44 -0600 Subject: [PATCH] Mejora en obtencion de datos y boton para factura --- factura_electronica/api.py | 24 +-- .../configuracion_factura_electronica.js | 6 +- .../configuracion_factura_electronica.json | 63 ++++++- .../configuracion_factura_electronica.py | 1 + .../doctype/configuracion_series/__init__.py | 0 .../configuracion_series.json | 161 ++++++++++++++++++ .../configuracion_series.py | 10 ++ .../fixtures/custom_field.json | 6 +- factura_electronica/public/js/facelec.js | 11 +- factura_electronica/public/js/facelec.min.js | 9 +- 10 files changed, 265 insertions(+), 26 deletions(-) create mode 100644 factura_electronica/factura_electronica/doctype/configuracion_series/__init__.py create mode 100644 factura_electronica/factura_electronica/doctype/configuracion_series/configuracion_series.json create mode 100644 factura_electronica/factura_electronica/doctype/configuracion_series/configuracion_series.py diff --git a/factura_electronica/api.py b/factura_electronica/api.py index e02feae2..e498b414 100644 --- a/factura_electronica/api.py +++ b/factura_electronica/api.py @@ -37,9 +37,9 @@ def generar_factura_electronica(serie_factura, nombre_cliente): frappe.msgprint(_('AVISO: La Factura ya fue generada Anteriormente {}'.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. @@ -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', @@ -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') @@ -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' @@ -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')) @@ -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']) diff --git a/factura_electronica/factura_electronica/doctype/configuracion_factura_electronica/configuracion_factura_electronica.js b/factura_electronica/factura_electronica/doctype/configuracion_factura_electronica/configuracion_factura_electronica.js index 0dce03af..4959cfc2 100644 --- a/factura_electronica/factura_electronica/doctype/configuracion_factura_electronica/configuracion_factura_electronica.js +++ b/factura_electronica/factura_electronica/doctype/configuracion_factura_electronica/configuracion_factura_electronica.js @@ -2,7 +2,7 @@ // For license information, please see license.txt frappe.ui.form.on('Configuracion Factura Electronica', { - refresh: function(frm) { + refresh: function(frm) { - } -}); + } +}); \ No newline at end of file diff --git a/factura_electronica/factura_electronica/doctype/configuracion_factura_electronica/configuracion_factura_electronica.json b/factura_electronica/factura_electronica/doctype/configuracion_factura_electronica/configuracion_factura_electronica.json index c4a371a2..159a4872 100644 --- a/factura_electronica/factura_electronica/doctype/configuracion_factura_electronica/configuracion_factura_electronica.json +++ b/factura_electronica/factura_electronica/doctype/configuracion_factura_electronica/configuracion_factura_electronica.json @@ -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, @@ -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", diff --git a/factura_electronica/factura_electronica/doctype/configuracion_factura_electronica/configuracion_factura_electronica.py b/factura_electronica/factura_electronica/doctype/configuracion_factura_electronica/configuracion_factura_electronica.py index ca639bdb..57a0a782 100644 --- a/factura_electronica/factura_electronica/doctype/configuracion_factura_electronica/configuracion_factura_electronica.py +++ b/factura_electronica/factura_electronica/doctype/configuracion_factura_electronica/configuracion_factura_electronica.py @@ -4,6 +4,7 @@ from __future__ import unicode_literals import frappe +from frappe import _ from frappe.model.document import Document class ConfiguracionFacturaElectronica(Document): diff --git a/factura_electronica/factura_electronica/doctype/configuracion_series/__init__.py b/factura_electronica/factura_electronica/doctype/configuracion_series/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/factura_electronica/factura_electronica/doctype/configuracion_series/configuracion_series.json b/factura_electronica/factura_electronica/doctype/configuracion_series/configuracion_series.json new file mode 100644 index 00000000..f2c3bbbf --- /dev/null +++ b/factura_electronica/factura_electronica/doctype/configuracion_series/configuracion_series.json @@ -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 +} \ No newline at end of file diff --git a/factura_electronica/factura_electronica/doctype/configuracion_series/configuracion_series.py b/factura_electronica/factura_electronica/doctype/configuracion_series/configuracion_series.py new file mode 100644 index 00000000..c02b6ac1 --- /dev/null +++ b/factura_electronica/factura_electronica/doctype/configuracion_series/configuracion_series.py @@ -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 diff --git a/factura_electronica/fixtures/custom_field.json b/factura_electronica/fixtures/custom_field.json index 498134be..2f903d4f 100644 --- a/factura_electronica/fixtures/custom_field.json +++ b/factura_electronica/fixtures/custom_field.json @@ -1,6 +1,6 @@ [ { - "allow_on_submit": 0, + "allow_on_submit": 1, "bold": 0, "collapsible": 0, "collapsible_depends_on": null, @@ -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, @@ -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, diff --git a/factura_electronica/public/js/facelec.js b/factura_electronica/public/js/facelec.js index 6eb5056b..b6c46ef4 100644 --- a/factura_electronica/public/js/facelec.js +++ b/factura_electronica/public/js/facelec.js @@ -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(); diff --git a/factura_electronica/public/js/facelec.min.js b/factura_electronica/public/js/facelec.min.js index 4c5ddc37..e6827be8 100644 --- a/factura_electronica/public/js/facelec.min.js +++ b/factura_electronica/public/js/facelec.min.js @@ -1,4 +1,8 @@ +/* + * /home/frappe/frappe-bench/apps/factura_electronica/factura_electronica/public/js/facelec.js + */ + frappe.ui.form.on("Sales Invoice", "refresh", function (frm) { @@ -26,9 +30,8 @@ frappe.ui.form.on("Sales Invoice", "refresh", function (frm) { serie_factura: frm.doc.name, nombre_cliente: frm.doc.customer }, - callback: function callback(r) { - - frm.set_value('cae_factura_electronica', r.message); + callback: function callback(data) { + cur_frm.set_value("cae_factura_electronica", data.message); if (frm.doc.cae_factura_electronica) { cur_frm.clear_custom_buttons();