Skip to content

Commit

Permalink
Merge pull request #234 from sihaysistema/custom-quick-entry
Browse files Browse the repository at this point in the history
Custom quick entry
  • Loading branch information
monroy95 authored May 14, 2021
2 parents f278112 + f48c99e commit 2f24c74
Show file tree
Hide file tree
Showing 6 changed files with 345 additions and 6 deletions.
2 changes: 1 addition & 1 deletion factura_electronica/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
40 changes: 39 additions & 1 deletion factura_electronica/api_erp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 :)

Expand Down Expand Up @@ -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
5 changes: 4 additions & 1 deletion factura_electronica/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions factura_electronica/patches.txt
100644 → 100755
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
factura_electronica.patches.v7_0_9.update_props_address
115 changes: 115 additions & 0 deletions factura_electronica/patches/v7_0_9/update_props_address.py
Original file line number Diff line number Diff line change
@@ -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()))
Loading

0 comments on commit 2f24c74

Please sign in to comment.