Exemplo n.º 1
0
def set_xml_to_pending_cfdi(cfdi,logger=None,sl1_execution_log=None):
	try:
		forest_db = _Utilities.set_connection_to_forest_db()
		db_CFDI = forest_db['CFDI']
		uuid = cfdi['uuid']
		# Get xml data:
		xml = cfdi['xml']
		validation = _Pauli_Helper.validate_xml(xml)
		xml_warnings = validation['warnings']
		xml_invalidations = validation['invalidations']
		# Updating data:
		updating_cfdi_data = {
			'xml' : xml,
			'validated' : True  if validation['validated'] else False,
			'details' : {
			    'invalidations' : xml_invalidations,
			    'warnings' : xml_warnings
			}# End of details
		}#End of updating_cfdi_data
		db_CFDI.update({'uuid':uuid},{'$set':updating_cfdi_data})
		sl1_execution_log['forest_db']['after']['pending_completed'] = sl1_execution_log['forest_db']['after']['pending_completed'] + 1
	except Exception as e:
		logger.critical(e.message)
		already_handled_exception = Already_Handled_Exception(e.message)
		raise already_handled_exception
Exemplo n.º 2
0
def set_xml_to_pending_cfdi(cfdi, logger=None, sl1_execution_log=None):
    try:
        forest_db = _Utilities.set_connection_to_forest_db()
        db_CFDI = forest_db['CFDI']
        uuid = cfdi['uuid']
        # Get xml data:
        xml = cfdi['xml']
        validation = _Pauli_Helper.validate_xml(xml)
        xml_warnings = validation['warnings']
        xml_invalidations = validation['invalidations']
        # Updating data:
        updating_cfdi_data = {
            'xml': xml,
            'validated': True if validation['validated'] else False,
            'details': {
                'invalidations': xml_invalidations,
                'warnings': xml_warnings
            }  # End of details
        }  #End of updating_cfdi_data
        db_CFDI.update({'uuid': uuid}, {'$set': updating_cfdi_data})
        sl1_execution_log['forest_db']['after'][
            'pending_completed'] = sl1_execution_log['forest_db']['after'][
                'pending_completed'] + 1
    except Exception as e:
        logger.critical(e.message)
        already_handled_exception = Already_Handled_Exception(e.message)
        raise already_handled_exception
Exemplo n.º 3
0
def create_cfdi(new_cfdi,logger=None,sl1_execution_log=None):
	try:
		forest_db = _Utilities.set_connection_to_forest_db()
		db_CFDI = forest_db['CFDI']
		uuid = new_cfdi['uuid'].upper()
		# Build new db cfdi:
		db_new_cfdi = {
			'uuid': uuid,
			'buyer': new_cfdi['buyer'],
			'seller': new_cfdi['seller'],
			'status': new_cfdi['status'],
			'voucher_effect' : new_cfdi['voucher_effect'] if 'voucher_effect' in new_cfdi else None
		}#End of db_ne_cfdi
		if 'simulated' in new_cfdi and new_cfdi['simulated'] == True:
			db_new_cfdi['certification_date'] = new_cfdi['certification_date']# It comes from db -- date is already parsed -- 
			db_new_cfdi['issued_date'] = new_cfdi['issued_date']
		else:
			db_new_cfdi['certification_date'] = _Utilities.sat_date_to_ISODate(new_cfdi['certification_date'])
			db_new_cfdi['issued_date'] = _Utilities.sat_date_to_ISODate(new_cfdi['issued_date'])
		# Get xml data:
		xml = new_cfdi['xml']
		if xml is not None and xml != '':#bug_solved, xml was '' and it causes errors in cfdi_type, currency and taxes
			cfdi_type = _Utilities.get_cfdi_type(xml,logger=logger)
			validation = _Pauli_Helper.validate_xml(xml)
			xml_warnings = validation['warnings']
			xml_invalidations = validation['invalidations']
			db_new_cfdi['xml'] = xml
			db_new_cfdi['validated'] = True  if validation['validated'] else False
			db_new_cfdi['details'] = {
				'invalidations' : xml_invalidations,
				'warnings' : xml_warnings
			}#End of details
			db_new_cfdi['cfdi_type'] = cfdi_type# It says if cfdi is a credit_note, payroll or normal
			currency = _Pauli_Helper.get_currency(xml,logger=logger)
			if currency is not None:
				db_new_cfdi['currency'] = currency
			else:
				db_new_cfdi['currency'] = 'mxn'# Default
			taxes_included = _Pauli_Helper.get_taxes_included_in_this_CFDI(xml,logger=logger)
			db_new_cfdi['_wl_ish'] = taxes_included['_wl_ish'] if taxes_included['_wl_ish'] is not None else False
			db_new_cfdi['_t_iva_16'] = taxes_included['_t_iva_16'] if taxes_included['_t_iva_16'] is not None else False
			db_new_cfdi['_t_iva_0'] = taxes_included['_t_iva_0'] if taxes_included['_t_iva_0'] is not None else False
			db_new_cfdi['_w_iva_10'] = taxes_included['_w_iva_10'] if taxes_included['_w_iva_10'] is not None else False
			db_new_cfdi['_w_isr'] = taxes_included['_w_isr'] if taxes_included['_w_isr'] is not None else False
			db_new_cfdi['_tl_ish'] = taxes_included['_tl_ish'] if taxes_included['_tl_ish'] is not None else False
			db_new_cfdi['_t_ieps'] = taxes_included['_t_ieps'] if taxes_included['_t_ieps'] is not None else False
			sl1_execution_log['forest_db']['after']['new'] = sl1_execution_log['forest_db']['after']['new'] + 1
		elif new_cfdi['status'] == _Constants.CANCELED_STATUS:
			# db_new_cfdi['xml'] = _Helper.build_default_xml(db_new_cfdi['seller'],db_new_cfdi['buyer'],db_new_cfdi['certification_date'],db_new_cfdi['issued_date'],db_new_cfdi['voucher_effect'],db_new_cfdi['uuid'])
			sl1_execution_log['forest_db']['after']['new'] = sl1_execution_log['forest_db']['after']['new'] + 1
		else:
			sl1_execution_log['forest_db']['after']['pending'] = sl1_execution_log['forest_db']['after']['pending'] + 1
		db_CFDI.insert(db_new_cfdi)
	except Exception as e:
		logger.critical(e.message)
		already_handled_exception = Already_Handled_Exception(e.message)
		raise already_handled_exception
Exemplo n.º 4
0
def create_cfdi(new_cfdi, logger=None, sl1_execution_log=None):
    try:
        forest_db = _Utilities.set_connection_to_forest_db()
        db_CFDI = forest_db['CFDI']
        uuid = new_cfdi['uuid'].upper()
        # Build new db cfdi:
        db_new_cfdi = {
            'uuid':
            uuid,
            'buyer':
            new_cfdi['buyer'],
            'seller':
            new_cfdi['seller'],
            'status':
            new_cfdi['status'],
            'voucher_effect':
            new_cfdi['voucher_effect']
            if 'voucher_effect' in new_cfdi else None
        }  #End of db_ne_cfdi
        if 'simulated' in new_cfdi and new_cfdi['simulated'] == True:
            db_new_cfdi['certification_date'] = new_cfdi[
                'certification_date']  # It comes from db -- date is already parsed --
            db_new_cfdi['issued_date'] = new_cfdi['issued_date']
        else:
            db_new_cfdi['certification_date'] = _Utilities.sat_date_to_ISODate(
                new_cfdi['certification_date'])
            db_new_cfdi['issued_date'] = _Utilities.sat_date_to_ISODate(
                new_cfdi['issued_date'])
        # Get xml data:
        xml = new_cfdi['xml']
        if xml is not None and xml != '':  #bug_solved, xml was '' and it causes errors in cfdi_type, currency and taxes
            cfdi_type = _Utilities.get_cfdi_type(xml, logger=logger)
            validation = _Pauli_Helper.validate_xml(xml)
            xml_warnings = validation['warnings']
            xml_invalidations = validation['invalidations']
            db_new_cfdi['xml'] = xml
            db_new_cfdi[
                'validated'] = True if validation['validated'] else False
            db_new_cfdi['details'] = {
                'invalidations': xml_invalidations,
                'warnings': xml_warnings
            }  #End of details
            db_new_cfdi[
                'cfdi_type'] = cfdi_type  # It says if cfdi is a credit_note, payroll or normal
            currency = _Pauli_Helper.get_currency(xml, logger=logger)
            if currency is not None:
                db_new_cfdi['currency'] = currency
            else:
                db_new_cfdi['currency'] = 'mxn'  # Default
            taxes_included = _Pauli_Helper.get_taxes_included_in_this_CFDI(
                xml, logger=logger)
            db_new_cfdi['_wl_ish'] = taxes_included[
                '_wl_ish'] if taxes_included['_wl_ish'] is not None else False
            db_new_cfdi[
                '_t_iva_16'] = taxes_included['_t_iva_16'] if taxes_included[
                    '_t_iva_16'] is not None else False
            db_new_cfdi[
                '_t_iva_0'] = taxes_included['_t_iva_0'] if taxes_included[
                    '_t_iva_0'] is not None else False
            db_new_cfdi[
                '_w_iva_10'] = taxes_included['_w_iva_10'] if taxes_included[
                    '_w_iva_10'] is not None else False
            db_new_cfdi['_w_isr'] = taxes_included['_w_isr'] if taxes_included[
                '_w_isr'] is not None else False
            db_new_cfdi['_tl_ish'] = taxes_included[
                '_tl_ish'] if taxes_included['_tl_ish'] is not None else False
            db_new_cfdi['_t_ieps'] = taxes_included[
                '_t_ieps'] if taxes_included['_t_ieps'] is not None else False
            sl1_execution_log['forest_db']['after'][
                'new'] = sl1_execution_log['forest_db']['after']['new'] + 1
        elif new_cfdi['status'] == _Constants.CANCELED_STATUS:
            # db_new_cfdi['xml'] = _Helper.build_default_xml(db_new_cfdi['seller'],db_new_cfdi['buyer'],db_new_cfdi['certification_date'],db_new_cfdi['issued_date'],db_new_cfdi['voucher_effect'],db_new_cfdi['uuid'])
            sl1_execution_log['forest_db']['after'][
                'new'] = sl1_execution_log['forest_db']['after']['new'] + 1
        else:
            sl1_execution_log['forest_db']['after'][
                'pending'] = sl1_execution_log['forest_db']['after'][
                    'pending'] + 1
        db_CFDI.insert(db_new_cfdi)
    except Exception as e:
        logger.critical(e.message)
        already_handled_exception = Already_Handled_Exception(e.message)
        raise already_handled_exception