diff --git a/factura_electronica/__init__.py b/factura_electronica/__init__.py index 5e188c83..21c3ef3b 100755 --- a/factura_electronica/__init__.py +++ b/factura_electronica/__init__.py @@ -11,7 +11,7 @@ # locale.setlocale(locale.LC_ALL, str('en_US.UTF-8')) -__version__ = '7.0.8' +__version__ = '7.0.9' @frappe.whitelist() def currency_in_words(amount, currency, cent_in_numb=0): diff --git a/factura_electronica/api_erp.py b/factura_electronica/api_erp.py index eef6faca..021918da 100755 --- a/factura_electronica/api_erp.py +++ b/factura_electronica/api_erp.py @@ -6,10 +6,13 @@ import json import frappe +from frappe import _ +from frappe.utils import cstr + from factura_electronica.controllers.journal_entry import JournalEntrySaleInvoice from factura_electronica.controllers.journal_entry_special import JournalEntrySpecialISR from factura_electronica.factura_electronica.doctype.batch_electronic_invoice.batch_electronic_invoice import batch_generator -from frappe import _ +from factura_electronica.fel_api import validate_configuration # USAR ESTE SCRIPT COMO API PARA COMUNICAR APPS DEL ECOSISTEMA FRAPPE/ERPNEXT :) @@ -133,3 +136,38 @@ def download_asl_files(): filedata = fileobj.read() frappe.local.response.filecontent = filedata frappe.local.response.type = "download" + + +def custom_customer_info(doc, method): + # Runs on event update - Customer + # this function will get call `on_update` as we define in hook.py + add_address_info(doc) + + +def add_address_info(doc): + try: + if doc.flags.is_new_doc and doc.get('address_line1'): + # this name construct should work + # because we just create this customer + # Billing is default type + # there shouldn't be any more address of this customer + address_name = ( + cstr(doc.name).strip() + '-' + cstr(_('Billing')).strip() + ) + address_doc = frappe.get_doc('Address', address_name) + + email_facelec = doc.get('email_id') + if not doc.get('email_id'): + status_config = validate_configuration() + if status_config[0] and status_config[1]: + email_facelec = frappe.db.get_value('Configuracion Factura Electronica', {'name': status_config[1]}, 'correo_copia') + + # adding custom data to address + address_doc.email_id = email_facelec + address_doc.county = doc.get('county') + address_doc.phone = doc.get('phone') + # En la creacion de direccion se definira como default + address_doc.is_primary_address = doc.get('is_primary_address') if doc.get('is_primary_address') else 1 + address_doc.save() + except: + pass diff --git a/factura_electronica/hooks.py b/factura_electronica/hooks.py index 51ccea96..c5c9e7fb 100755 --- a/factura_electronica/hooks.py +++ b/factura_electronica/hooks.py @@ -108,7 +108,10 @@ # # "on_save": "factura_electronica.api.get_tax_html", # "on_cancel": "method", # "on_trash": "method" - # } + # }, + 'Customer': { + 'on_update': 'factura_electronica.api_erp.custom_customer_info' + } } # Scheduled Tasks diff --git a/factura_electronica/patches.txt b/factura_electronica/patches.txt old mode 100644 new mode 100755 index e69de29b..f59ab626 --- a/factura_electronica/patches.txt +++ b/factura_electronica/patches.txt @@ -0,0 +1 @@ +factura_electronica.patches.v7_0_9.update_props_address \ No newline at end of file diff --git a/factura_electronica/patches/v7_0_9/update_props_address.py b/factura_electronica/patches/v7_0_9/update_props_address.py new file mode 100755 index 00000000..14ec0ad8 --- /dev/null +++ b/factura_electronica/patches/v7_0_9/update_props_address.py @@ -0,0 +1,115 @@ +import frappe + +# This patch deletes all the duplicate indexes created for same column +# The patch only checks for indexes with UNIQUE constraints + +def execute(): + try: + # Cambios propiedades campo pincode + frappe.make_property_setter({ + "doctype": "Address", + "fieldname": "pincode", + "property": "allow_in_quick_entry", + "value": 1, + "property_type": "Int" + }) + + frappe.make_property_setter({ + "doctype": "Address", + "fieldname": "pincode", + "default": "0", + "property": "reqd", + "value": 1, + "property_type": "Int" + }) + + # Cambios propiedades campo email_id + frappe.make_property_setter({ + "doctype": "Address", + "fieldname": "email_id", + "property": "allow_in_quick_entry", + "value": 1, + "property_type": "Int" + }) + + frappe.make_property_setter({ + "doctype": "Address", + "fieldname": "email_id", + "property": "reqd", + "value": 0, + "property_type": "Int" + }) + + # Cambios propiedades campo phone + frappe.make_property_setter({ + "doctype": "Address", + "fieldname": "phone", + "property": "reqd", + "value": 0, + "property_type": "Int" + }) + + frappe.make_property_setter({ + "doctype": "Address", + "fieldname": "phone", + "property": "allow_in_quick_entry", + "value": 1, + "property_type": "Int" + }) + + # Campo tax id en Customer Dt + frappe.make_property_setter({ + "doctype": "Customer", + "fieldname": "tax_id", + "property": "reqd", + "value": 1, + "property_type": "Int" + }) + + frappe.make_property_setter({ + "doctype": "Address", + "fieldname": "tax_id", + "default": "C/F", + "property": "allow_in_quick_entry", + "value": 1, + "property_type": "Int" + }) + + frappe.make_property_setter({ + "doctype": "Customer", + "fieldname": "county", + "property": "reqd", + "value": 0, + "property_type": "Int" + }) + + frappe.make_property_setter({ + "doctype": "Address", + "fieldname": "county", + "default": "Guatemala", + "property": "allow_in_quick_entry", + "value": 1, + "property_type": "Int" + }) + + for ffield in ["city", "state", "country"]: + frappe.make_property_setter({ + "doctype": "Address", + "fieldname": ffield, + "default": "Guatemala", + "property": "reqd", + "value": 1, + "property_type": "Int" + }) + + frappe.make_property_setter({ + "doctype": "Address", + "fieldname": ffield, + "property": "allow_in_quick_entry", + "value": 1, + "property_type": "Int" + }) + + except: + with open("debug.txt", "w") as f: + f.write(str(frappe.get_traceback())) diff --git a/factura_electronica/public/js/facelec.js b/factura_electronica/public/js/facelec.js index 24297eb5..c7d3b7a3 100755 --- a/factura_electronica/public/js/facelec.js +++ b/factura_electronica/public/js/facelec.js @@ -76,6 +76,10 @@ frappe.ui.form.on("Customer", { var cust_name_desc = __("Legal Name, for tax, government or contract use. For Example: Apple, Inc. Amazon.com, Inc., The Home Depot, Inc."); cur_frm.set_df_property("customer_name", "description", cust_name_desc); frm.refresh_field('customer_name'); + }, + onload: function (frm) { + frm.set_value('tax_id', frm.doc.nit_face_customer); + frm.set_value('nit_face_customer', frm.doc.tax_id); } }); @@ -185,10 +189,11 @@ frappe.ui.form.on("Address", { frm.set_df_property("address_line1", "description", __("* FEL: Direccion Comercial 1")); frm.set_df_property("city", "description", __("FEL: Ciudad p. ej.: Antigua Guatemala")); frm.set_df_property("state", "description", __("FEL: Departamento p. ej.: Sacatepéquez")); - frm.set_df_property("county", "description", __("Municipio p. ej.: Antigua Guatemala")); - + frm.set_df_property("county", "description", __("FEL: Municipio p. ej.: Antigua Guatemala")); + frm.set_df_property("county", "reqd", 1); frm.set_df_property("country", "description", __("FEL: Pais p. ej: Guatemala")); frm.set_df_property("email_id", "description", __("FEL: Correo Electronico p. ej: micorreo@hola.com")); + frm.set_df_property("email_id", "reqd", 1); frm.set_df_property("phone", "description", __("Teléfono: p. ej: +502 2333-2516")); frm.set_df_property("pincode", "description", __("FEL: Código Postal p. ej.: 03001")); frm.set_df_property("is_primary_address", "description", __("FEL: Dirección para facturar")); @@ -208,4 +213,181 @@ frappe.ui.form.on("Expense Claim Detail", { frm.refresh(); } }, -}); \ No newline at end of file +}); + +// Personalizador de quick entry en customer +frappe.provide('frappe.ui.form'); + +frappe.ui.form.CustomerQuickEntryForm = frappe.ui.form.QuickEntryForm.extend({ + init: function (doctype, after_insert) { + this.skip_redirect_on_error = true; + this._super(doctype, after_insert); + }, + + render_dialog: function () { + // console.log('Ejecutando prueba') + this.mandatory = this.get_field(); + this._super(); + }, + + get_field: function () { + const variant_fields = [ + { + label: __('Full Name'), + fieldname: 'customer_name', + fieldtype: 'Data', + }, + { + label: __('Type'), + fieldname: 'customer_type', + fieldtype: 'Select', + options: ['', 'Company', 'Individual'] + }, + { + fieldtype: "Section Break", + label: __(""), + collapsible: 0 + }, + { + label: __('NIT FEL'), + fieldname: 'nit_face_customer', + fieldtype: 'Data', + default: 'C/F', + description: 'FEL: Si no tiene disponible el NIT escriba C/F' + }, + { + fieldtype: "Column Break" + }, + { + label: __('NIT'), + fieldname: 'tax_id', + fieldtype: 'Data', + default: 'C/F', + reqd: true, + description: 'FEL: Si no tiene disponible el NIT escriba C/F' + }, + { + fieldtype: "Section Break", + label: __(""), + collapsible: 0 + }, + { + label: __('Customer Group'), + fieldname: 'customer_group', + fieldtype: 'Link', + }, + { + label: __('Territory'), + fieldname: 'territory', + fieldtype: 'Link', + }, + + { + fieldtype: "Section Break", + label: __("Primary Contact Details"), + collapsible: 1 + }, + { + label: __("Email ID"), + fieldname: "email_id", + fieldtype: "Data", + options: 'Email', + reqd: 1 + }, + { + fieldtype: "Column Break" + }, + { + label: __("Mobile Number"), + fieldname: "mobile_no", + fieldtype: "Data" + }, + + { + fieldtype: "Section Break", + label: __("Primary Address Details"), + collapsible: 1 + }, + { + label: __("Address Line 1"), + fieldname: "address_line1", + fieldtype: "Data", + default: 'Guatemala', + reqd: 1, + options: 'FEL' + }, + { + label: __("Address Line 2"), + fieldname: "address_line2", + fieldtype: "Data" + }, + { + label: __("City/Town"), + fieldname: "city", + fieldtype: "Data", + default: 'Guatemala', + reqd: 1, + description: 'FEL Ciudad ej.: Antigua Guatemala' + }, + { + label: __("County"), + fieldname: "county", + fieldtype: "Data", + default: 'Guatemala', + reqd: 1, + description: 'FEL: Municipio p. ej.: Antigua Guatemala' + }, + { + label: __("State"), + fieldname: "state", + fieldtype: "Data", + default: 'Guatemala', + reqd: 1, + description: 'FEL Departamento ej.: Sacatepéquez' + }, + { + label: __("Country"), + fieldname: "country", + fieldtype: "Link", + default: 'Guatemala', + reqd: 1, + options: 'Country', + description: 'FEL Pais ej: Guatemala' + }, + { + label: __("ZIP Code"), + fieldname: "pincode", + default: '0', + reqd: 1, + fieldtype: "Data", + description: 'FEL Código Postal ej.: 03001' + }, + { + fieldtype: "Column Break" + }, + { + label: __("Phone"), + fieldname: "phone", + fieldtype: "Data", + allow_in_quick_entry: 1 + }, + { + label: __("Email Address"), + fieldname: "email_id", + fieldtype: "Data", + reqd: 1, + allow_in_quick_entry: 1, + // options: 'Email', + description: 'FEL Correo Electronico ej: micorreo@hola.com', + }, + { + label: __("Preferred Billing Address"), + fieldname: "is_primary_address", + fieldtype: "Check", + description: 'FEL Dirección para facturar', + allow_in_quick_entry: 1 + }]; + + return variant_fields; + }, +}) \ No newline at end of file