empresa-libre/source/app/settings.py

300 lines
9.2 KiB
Python
Raw Normal View History

2018-08-24 23:04:10 -05:00
#!/usr/bin/env python3
# ~ Empresa Libre
2022-01-20 17:02:11 -06:00
# ~ Copyright (C) 2016-2018 Mauricio Baeza Servin (publico@cuates.net)
2018-08-24 23:04:10 -05:00
# ~
# ~ This program is free software: you can redistribute it and/or modify
# ~ it under the terms of the GNU General Public License as published by
# ~ the Free Software Foundation, either version 3 of the License, or
# ~ (at your option) any later version.
# ~
# ~ This program is distributed in the hope that it will be useful,
# ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
# ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# ~ GNU General Public License for more details.
# ~
# ~ You should have received a copy of the GNU General Public License
# ~ along with this program. If not, see <http://www.gnu.org/licenses/>.
2017-06-27 15:43:02 -05:00
import logbook
import os
import sys
from mako.lookup import TemplateLookup
from logbook import Logger, StreamHandler, RotatingFileHandler
2017-09-21 23:24:18 -05:00
logbook.set_datetime_format('local')
2017-06-27 15:43:02 -05:00
2017-11-30 00:37:13 -06:00
from conf import DEBUG, MV, LOG_PATH
2017-06-27 15:43:02 -05:00
try:
from conf import DEFAULT_PASSWORD
except ImportError:
2018-01-30 23:40:33 -06:00
DEFAULT_PASSWORD = 'salgueiro3.3'
2018-01-25 23:06:03 -06:00
try:
from conf import TITLE_APP
except ImportError:
TITLE_APP = 'Empresa Libre'
2018-01-30 23:40:33 -06:00
try:
from conf import NO_HTTPS
except ImportError:
NO_HTTPS = True
2017-10-22 14:53:07 -05:00
DEBUG = DEBUG
2022-03-10 20:29:50 -06:00
VERSION = '2.0.0'
2019-02-03 23:32:48 -06:00
EMAIL_SUPPORT = ('soporte@empresalibre.mx',)
2018-06-03 00:00:04 -05:00
TITLE_APP = '{} v{}'.format(TITLE_APP, VERSION)
2017-06-27 15:43:02 -05:00
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
2020-01-07 00:32:48 -06:00
COMPANIES = os.path.abspath(os.path.join(BASE_DIR, '..', 'db', 'rfc.db'))
2018-01-11 10:20:55 -06:00
2018-11-20 00:03:07 -06:00
path_static = os.path.abspath(os.path.join(BASE_DIR, '..', 'static'))
2018-11-20 23:47:53 -06:00
path_docs = os.path.abspath(os.path.join(BASE_DIR, '..', 'docs'))
path_css = os.path.join(path_static, 'css')
path_img = os.path.join(path_static, 'img')
path_user_template = os.path.join(path_docs, 'templates')
path_user_logos = os.path.join(path_docs, 'logos')
2018-11-20 23:47:53 -06:00
2018-11-20 00:03:07 -06:00
# ~ PATH_STATIC = os.path.abspath(os.path.join(BASE_DIR, '..'))
2017-06-27 15:43:02 -05:00
PATH_TEMPLATES = os.path.abspath(os.path.join(BASE_DIR, '..', 'templates'))
2017-10-24 00:03:07 -05:00
PATH_MEDIA = os.path.abspath(os.path.join(BASE_DIR, '..', 'docs'))
2017-06-27 15:43:02 -05:00
2017-09-30 00:22:55 -05:00
PATH_CP = os.path.abspath(os.path.join(BASE_DIR, '..', 'db', 'cp.db'))
COMPANIES = os.path.abspath(os.path.join(BASE_DIR, '..', 'db', 'rfc.db'))
2017-10-04 00:11:49 -05:00
DB_SAT = os.path.abspath(os.path.join(BASE_DIR, '..', 'db', 'sat.db'))
2017-06-27 15:43:02 -05:00
2018-01-11 10:20:55 -06:00
PATH_SESSIONS = {
'data': os.path.abspath(os.path.join(BASE_DIR, '..', 'cache', 'data')),
'lock': os.path.abspath(os.path.join(BASE_DIR, '..', 'cache', 'lock')),
}
2017-10-26 13:09:47 -05:00
IV = 'valores_iniciales.json'
INIT_VALUES = os.path.abspath(os.path.join(BASE_DIR, '..', 'db', IV))
# ~ CT = 'cancel_template.xml'
# ~ TEMPLATE_CANCEL = os.path.abspath(os.path.join(PATH_TEMPLATES, CT))
2017-10-26 13:09:47 -05:00
2017-10-10 18:49:05 -05:00
PATH_XSLT = os.path.abspath(os.path.join(BASE_DIR, '..', 'xslt'))
PATH_BIN = os.path.abspath(os.path.join(BASE_DIR, '..', 'bin'))
2018-11-19 01:03:48 -06:00
PATH_TEMPLATES_USER = os.path.abspath(os.path.join(
BASE_DIR, '..', 'docs', 'templates'))
directories=[PATH_TEMPLATES, PATH_TEMPLATES_USER]
template_lookup = TemplateLookup(directories=directories,
2017-06-27 15:43:02 -05:00
input_encoding='utf-8',
output_encoding='utf-8')
LOG_NAME = 'API'
LOG_LEVEL = 'INFO'
format_string = '[{record.time:%d-%b-%Y %H:%M:%S}] ' \
'{record.level_name}: ' \
'{record.channel}: ' \
'{record.message}'
2017-10-22 15:13:35 -05:00
2017-06-27 15:43:02 -05:00
if DEBUG:
LOG_LEVEL = 'DEBUG'
StreamHandler(
sys.stdout,
level=LOG_LEVEL,
format_string=format_string).push_application()
else:
RotatingFileHandler(
LOG_PATH,
backup_count=10,
max_size=1073741824,
level=LOG_LEVEL,
format_string=format_string).push_application()
2017-10-22 15:13:35 -05:00
StreamHandler(
sys.stdout,
level=LOG_LEVEL,
format_string=format_string).push_application()
2017-06-27 15:43:02 -05:00
log = Logger(LOG_NAME)
2017-10-10 18:49:05 -05:00
PATH_XSLTPROC = 'xsltproc'
PATH_OPENSSL = 'openssl'
2017-10-29 16:53:10 -06:00
PATH_XMLSEC = 'xmlsec1'
2017-10-10 18:49:05 -05:00
if 'win' in sys.platform:
PATH_XSLTPROC = os.path.join(PATH_BIN, 'xsltproc.exe')
PATH_OPENSSL = os.path.join(PATH_BIN, 'openssl.exe')
2017-10-29 16:53:10 -06:00
PATH_XMLSEC = os.path.join(PATH_BIN, 'xmlsec.exe')
2017-10-15 02:30:55 -05:00
PRE = {
'2.0': '{http://www.sat.gob.mx/cfd/2}',
'2.2': '{http://www.sat.gob.mx/cfd/2}',
'3.0': '{http://www.sat.gob.mx/cfd/3}',
'3.2': '{http://www.sat.gob.mx/cfd/3}',
'3.3': '{http://www.sat.gob.mx/cfd/3}',
2022-03-10 20:29:50 -06:00
'4.0': '{http://www.sat.gob.mx/cfd/4}',
2017-10-15 02:30:55 -05:00
'TIMBRE': '{http://www.sat.gob.mx/TimbreFiscalDigital}',
2017-11-25 20:26:15 -06:00
'DONATARIA': '{http://www.sat.gob.mx/donat}',
2017-11-26 00:15:14 -06:00
'INE': '{http://www.sat.gob.mx/ine}',
2017-11-29 23:57:31 -06:00
'LOCALES': '{http://www.sat.gob.mx/implocal}',
2017-10-15 02:30:55 -05:00
'NOMINA': {
'1.1': '{http://www.sat.gob.mx/nomina}',
'1.2': '{http://www.sat.gob.mx/nomina12}',
2018-08-30 19:24:33 -05:00
},
'pagos': '{http://www.sat.gob.mx/Pagos}',
2017-10-15 02:30:55 -05:00
}
2017-10-25 19:46:13 -05:00
CURRENT_CFDI = '3.3'
2018-01-14 20:28:19 -06:00
CURRENT_CFDI_NOMINA = '1.2'
2017-11-14 20:04:01 -06:00
DECIMALES = 2
2018-01-21 21:38:29 -06:00
DECIMALES_TAX = 4
2018-07-10 23:34:32 -05:00
DECIMALES_PRECIOS = 4
2017-11-15 00:12:55 -06:00
IMPUESTOS = {
'ISR': '001',
'IVA': '002',
'IEPS': '003',
2018-01-04 21:20:14 -06:00
'EXENTO': '000',
2017-11-15 00:12:55 -06:00
'ISH': '000',
'INSPECCION DE OBRA': '000',
'ICIC': '000',
'CEDULAR': '000',
2018-01-16 13:26:06 -06:00
'CMIC': '000',
'SUPERVISION': '000',
2017-11-15 00:12:55 -06:00
}
2017-11-15 19:29:51 -06:00
DEFAULT_SAT_PRODUCTO = '01010101'
2018-01-02 01:37:52 -06:00
DEFAULT_SERIE_TICKET = 'T'
DEFAULT_CFDIPAY = {
'SERIE': 'FP',
'TYPE': 'P',
'WAYPAY': 'PPD',
'CURRENCY': 'XXX',
'USED': 'P01',
'KEYSAT': '84111506',
'UNITKEY': 'ACT',
'DESCRIPTION': 'Pago',
2018-09-07 00:08:16 -05:00
'TYPE_RELATION': '04',
}
DIR_FACTURAS = 'facturas'
USAR_TOKEN = False
2018-01-01 02:14:30 -06:00
CANCEL_SIGNATURE = False
2018-01-14 20:28:19 -06:00
PUBLIC = 'Público en general'
DEFAULT_SAT_NOMINA = {
2018-01-28 03:12:35 -06:00
'SERIE': 'N',
'FORMA_PAGO': '99',
'USO_CFDI': 'P01',
2018-01-14 20:28:19 -06:00
'CLAVE': '84111505',
'UNIDAD': 'ACT',
'DESCRIPCION': 'Pago de nómina',
2018-02-13 23:12:21 -06:00
}
2018-06-14 22:20:55 -05:00
API = 'https://api.empresalibre.net{}'
2018-09-26 23:22:29 -05:00
CURRENCY_MN = 'MXN'
2018-11-20 00:03:07 -06:00
# ~ v2
2021-12-12 13:51:51 -06:00
CANCEL_VERSION = ('3.3', '4.0')
2022-03-10 20:29:50 -06:00
CFDI_VERSIONS = CANCEL_VERSION
2021-12-12 13:51:51 -06:00
2020-01-07 00:32:48 -06:00
IS_MV = MV
DB_COMPANIES = os.path.abspath(os.path.join(BASE_DIR, '..', 'db', 'rfc.db'))
path_bk = os.path.join(path_docs, 'tmp')
2020-01-11 22:14:38 -06:00
path_local = 'facturas'
2020-01-12 22:40:45 -06:00
path_sat = os.path.abspath(os.path.join(BASE_DIR, '..', 'db', 'valores_iniciales.json'))
2020-01-07 00:32:48 -06:00
2018-11-20 00:03:07 -06:00
EXT = {
2018-11-20 23:47:53 -06:00
'CSS': 'css',
'HTML': 'html',
'ODS': 'ods',
2018-11-20 00:03:07 -06:00
'PNG': 'png',
2019-01-10 23:37:37 -06:00
'JSON': 'json',
2018-11-20 00:03:07 -06:00
}
MXN = 'MXN'
2020-01-07 00:32:48 -06:00
2022-01-03 19:14:20 -06:00
CARTA_PORTE = {
'MONEDA': 'XXX',
}
2018-11-20 00:03:07 -06:00
PATHS = {
'STATIC': path_static,
2018-11-20 23:47:53 -06:00
'CSS': path_css,
'IMG': path_img,
'DOCS': path_docs,
'USER': path_user_template,
'LOGOS': path_user_logos,
2020-01-07 00:32:48 -06:00
'BK': path_bk,
2020-01-11 22:14:38 -06:00
'LOCAL': path_local,
2020-01-12 22:40:45 -06:00
'SAT': path_sat,
2020-12-31 12:01:41 -06:00
'xslt': PATH_XSLT,
2018-11-20 00:03:07 -06:00
}
2020-01-07 00:32:48 -06:00
2018-11-20 00:03:07 -06:00
VALUES_PDF = {
'CANCEL': {True: 'inline', False: 'none'},
'TYPE': {'I': 'Ingreso', 'E': 'Egreso', 'T': 'Traslado'},
'TAX': {'001': 'ISR', '002': 'IVA', '003': 'IEPS'},
'METHOD': {
'PUE': 'Pago en una sola exhibición',
'PPD': 'Pago en parcialidades o diferido',
},
}
2020-01-07 00:32:48 -06:00
2020-03-03 22:47:40 -06:00
RFCS = {
'PUBLIC': 'XAXX010101000',
2020-03-04 22:36:20 -06:00
'FOREIGN': 'XEXX010101000',
2021-01-02 22:23:33 -06:00
'CVD110412TF6': 'finkok',
'SCD110105654': 'comercio',
2021-05-12 19:43:35 -05:00
'AAA010101AAA': 'comercio',
2021-10-03 22:21:01 -05:00
'SPR190613I52': 'comercio',
2020-03-03 22:47:40 -06:00
}
2020-01-07 00:32:48 -06:00
URL = {
2021-05-12 19:43:35 -05:00
'SEAFILE': 'https://seafile.cuates.net',
2020-01-07 00:32:48 -06:00
}
2020-03-04 22:36:20 -06:00
DEFAULT_GLOBAL = {
'cantidad': 1.00,
'unidad': 'ACT',
'descripcion': 'Venta',
'clave_sat': '01010101',
}
# ~ TEMPLATE_CANCEL = """<CancelaCFD xmlns="http://cancelacfd.sat.gob.mx">
# ~ <Cancelacion xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" RfcEmisor="{rfc}" Fecha="{fecha}">
# ~ <Folios>
# ~ <Folio UUID="{uuid}" Motivo="{motivo}"{folio}/>
# ~ </Folios>
# ~ <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
# ~ <SignedInfo>
# ~ <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
# ~ <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
# ~ <Reference URI="">
# ~ <Transforms>
# ~ <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
# ~ </Transforms>
# ~ <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
# ~ <DigestValue/>
# ~ </Reference>
# ~ </SignedInfo>
# ~ <SignatureValue/>
# ~ <KeyInfo>
# ~ <X509Data>
# ~ <X509IssuerSerial>
# ~ <X509IssuerName/>
# ~ <X509SerialNumber/>
# ~ </X509IssuerSerial>
# ~ <X509Certificate/>
# ~ </X509Data>
# ~ <KeyValue>
# ~ <RSAKeyValue>
# ~ <Modulus/>
# ~ <Exponent/>
# ~ </RSAKeyValue>
# ~ </KeyValue>
# ~ </KeyInfo>
# ~ </Signature>
# ~ </Cancelacion>
# ~ </CancelaCFD>"""
2022-01-25 19:12:41 -06:00
TEMPLATE_CANCEL = """<CancelaCFD xmlns="http://cancelacfd.sat.gob.mx"><Cancelacion xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Fecha="{fecha}" RfcEmisor="{rfc}" xmlns="http://cancelacfd.sat.gob.mx"><Folios><Folio UUID="{uuid}" Motivo="{motivo}"{folio}/></Folios><Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" /><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" /><Reference URI=""><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" /></Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /><DigestValue/></Reference></SignedInfo><SignatureValue/><KeyInfo><X509Data><X509IssuerSerial><X509IssuerName/><X509SerialNumber/></X509IssuerSerial><X509Certificate/></X509Data><KeyValue><RSAKeyValue><Modulus/><Exponent/></RSAKeyValue></KeyValue></KeyInfo></Signature></Cancelacion></CancelaCFD>"""