def __init__(self): """ Initial value settings """ self.default_currency = SystemParameter.find_one( "CORE_DEFAULT_CURRENCY", FieldDataType.STRING, 'USD') self.default_locale = SystemParameter.find_one( "CORE_DEFAULT_LOCALE", FieldDataType.STRING, 'en_US')
def _load_xpdl(cls, params, html=False): """ Loads an XPDL to Antares """ if ('withpackage' in params): package = os.path.join(settings.BASE_DIR, SystemParameter.find_one( "INITIAL_SETTINGS_DEFAULT_FOLDER", FieldDataType.STRING, 'initialsettings'), params['withpackage'], 'flow', 'xpdl') if os.path.isdir(package) is False: return _(__name__ + ".package_leads_to_inexistent_path {package}").format( package=package) else: return _(__name__ + ".missing_parameter {parameter}").format( parameter='withpackage') if ('withfile' in params): xpdl_file = os.path.join(package, params['withfile']) if os.path.isfile(xpdl_file) is False: return _(__name__ + ".package_leads_to_inexistent_file {file}").format( file=xpdl_file) manager = FlowAdminManager(xpdl_file=xpdl_file) else: return _(__name__ + ".missing_parameter {parameter}").format( parameter='withfile') manager.load_xpdl() return _(__name__ + ".load_xpdl_sucess")
def total_accounting_balance(client): """ Returns the total balance for the given client :param client: the client object :returns: the consolidated total balance of the client already formatted. """ default_currency = SystemParameter.find_one("CORE_DEFAULT_CURRENCY", FieldDataType.STRING, 'USD') default_locale = SystemParameter.find_one("CORE_DEFAULT_LOCALE", FieldDataType.STRING, 'en_US') result = AccountBalance.get_total_balance_by_client(client) if result is None: return babel.numbers.format_currency( decimal.Decimal(0), currency=default_currency, locale=default_locale) else: return babel.numbers.format_currency( decimal.Decimal(result), currency=default_currency, locale=default_locale)
def load_isic_file(cls, language): """ Loads the ISIC file into Antares. """ message = "" folder = os.path.join( settings.BASE_DIR, SystemParameter.find_one("INITIAL_SETTINGS_DEFAULT_FOLDER", FieldDataType.STRING, 'initialsettings'), 'isic', 'files') if language == LanguageType.ENGLISH: with open(os.path.join(folder, 'ISIC_Rev_4_english_structure.txt'), 'r', encoding='utf-8') as csvfile: dialect = csv.Sniffer().sniff(csvfile.read(1024)) csvfile.seek(0) isic_reader = csv.DictReader(csvfile, dialect=dialect) for row in isic_reader: if (row['Code'].isalpha()): top_layer = row['Code'] IsicPosition.save_position(row['Code'], row['Description'], language) else: IsicPosition.save_position(top_layer + row['Code'], row['Description'], language) message = _(__name__ + ".command_successful") return message elif language == LanguageType.SPANISH: with open(os.path.join(folder, 'ISIC_Rev_4_spanish_structure.txt'), 'r', encoding='utf-8') as csvfile: dialect = csv.Sniffer().sniff(csvfile.read(1024)) csvfile.seek(0) isic_reader = csv.DictReader(csvfile, dialect=dialect) for row in isic_reader: if (row['Code'].isalpha()): top_layer = row['Code'] IsicPosition.save_position(row['Code'], row['Title'], language) else: IsicPosition.save_position(top_layer + row['Code'], row['Title'], language) message = _(__name__ + ".command_successful") return message else: return _(__name__ + ".unsupported_language")
def _process_payment_transaction(cls, transaction: AccountTransaction, document: Document) -> AccountTransaction: """ Processes a payment transaction to assign the proper values to the accounts. TODO: Needs to be implemented. :param document: the underlying document object :param rule: account rule to process :returns: the produced transactions """ paymentApplicationMethod = SystemParameter.find_one( "DEFAULT_PAYMENT_APPLICATION_METHOD", FieldDataType.STRING, 'PRINCIPAL_INTEREST_PENALTIES') return transaction
def get_system_user(cls): from antares.apps.core.models import SystemParameter from antares.apps.core.constants import FieldDataType """ Returns the system user, an special (deactivated) user, which serves as wildcard for actions taken by the system without human intervention. """ system_username = SystemParameter.find_one( "SYSTEM_USERNAME", FieldDataType.STRING, "system") system_user = User.find_one_by_username(system_username) if (system_user is not None): return system_user system_email = SystemParameter.find_one( "SYSTEM_EMAIL", FieldDataType.STRING, "*****@*****.**") system_user = User.objects.create( username=system_username, email=system_email, is_staff=True, is_active=False) # we don't want anyone to take over, so an UUID would be random enough system_user.set_password(str(uuid.uuid4())) system_user.save() return system_user
def _create_transaction(cls, account_document: AccountDocument, document: Document, rule: AccountRule) -> AccountTransaction: """ Computes the transaction out of a document and a rule :param account_document: Account document to process :param document: the underlying document object :param rule: account rule to process :returns: the produced transactions """ default_payment_transaction = SystemParameter.find_one( "DEFAULT_PAYMENT_TRANSACTION_TYPE", FieldDataType.STRING, 'PAYMENT') transaction = AccountTransaction() transaction.document = account_document.document transaction.account_document = account_document transaction.creation_date = timezone.now() transaction.transaction_date = timezone.now() transaction.posted_date = timezone.now() transaction.client = AccountManager._process_client( account_document, document, rule) transaction.account_type = AccountManager._process_account_type( account_document, document, rule) transaction.concept_type = AccountManager._process_concept_type( account_document, document, rule) transaction.period = AccountManager._process_period( account_document, document, rule) transaction.transaction_type = AccountManager._process_transaction_type( account_document, document, rule) transaction = AccountManager._process_amount(account_document, document, rule, transaction, False) if (transaction.transaction_type.id == default_payment_transaction): transaction = AccountManager._process_payment_transaction( transaction, document) transaction.balance = AccountBalance.find_or_create_by_CCPAD( transaction.client, transaction.concept_type, transaction.period, transaction.account_type, None) transaction.save() return transaction
def _find_period_list(cls, client_obligation, event_date): """ Returns a list of periods for processing, using defaults on a client obligation object. """ time_unit = TimeUnitType.to_enum( client_obligation.obligation_rule.time_unit_type) period_list = [] from_registration_date = SystemParameter.find_one( 'OBLIGATION_CALCULATE_PERIODS_FROM_REGISTRATION', FieldDataType.BOOLEAN, True) # if the client is defunct, it does not make sense to continue # calculating anything. if (client_obligation.client.status == ClientStatusType.DEFUNCT): return period_list if (client_obligation.client.registration_date > client_obligation.start_date and from_registration_date == True): base_date = client_obligation.start_date else: base_date = client_obligation.client.registration_date if (event_date is None): event_date = timezone.now() if (time_unit == TimeUnitType.YEAR): number_of_years_into_future = SystemParameter.find_one( "OBLIGATION_DEFAULT_NUMBER_OF_YEARS_INTO_FUTURE", FieldDataType.INTEGER, 3) require_full_years = SystemParameter.find_one( "OBLIGATION_CALCULATE_PERIODS_REQUIRE_FULL_YEARS", FieldDataType.BOOLEAN, True) if (require_full_years == True): base_date = base_date + relativedelta(years=1) interval = relativedelta( event_date, base_date).years + number_of_years_into_future for i in range(0, interval): period_list.append(int(str(base_date.year).zfill(4))) base_date = base_date + relativedelta(years=1) elif (time_unit == TimeUnitType.MONTH): number_of_months_into_future = SystemParameter.find_one( "OBLIGATION_DEFAULT_NUMBER_OF_MONTHS_INTO_FUTURE", FieldDataType.INTEGER, 3) require_full_months = SystemParameter.find_one( "OBLIGATION_CALCULATE_PERIODS_REQUIRE_FULL_MONTHS", FieldDataType.BOOLEAN, True) if (require_full_months == True): base_date = base_date + relativedelta(months=1) delta = relativedelta(event_date, base_date) interval = delta.years * 12 + delta.months + number_of_months_into_future for i in range(0, interval): period_list.append( int( str(base_date.year).zfill(4) + str(base_date.month) .zfill(2))) base_date = base_date + relativedelta(months=1) elif (time_unit == TimeUnitType.DAY): number_of_days_into_future = SystemParameter.find_one( "OBLIGATION_DEFAULT_NUMBER_OF_DAYS_INTO_FUTURE", FieldDataType.INTEGER, 3) delta = relativedelta(event_date, base_date) interval = delta.years * 12 + delta.months * 30 + delta.days + number_of_days_into_future for i in range(0, interval): period_list.append( int( str(base_date.year).zfill(4) + str(base_date.month) .zfill(2) + str(base_date.day).zfill(2))) base_date = base_date + relativedelta(days=1) else: raise NotImplementedError return period_list