Beispiel #1
0
    def digest(self,
               user_model: UserModel,
               accounts: set = None,
               activity: str = None,
               entity_slug: str = None,
               unit_slug: str = None,
               signs: bool = True,
               to_date: str = None,
               from_date: str = None,
               queryset: QuerySet = None,
               process_roles: bool = True,
               process_groups: bool = False,
               process_ratios: bool = False,
               equity_only: bool = False,
               by_period: bool = False,
               return_queryset: bool = False,
               digest_name: str = None) -> dict or tuple:

        txs_qs, accounts_digest = self.python_digest(
            queryset=queryset,
            user_model=user_model,
            accounts=accounts,
            activity=activity,
            entity_slug=entity_slug,
            unit_slug=unit_slug,
            to_date=to_date,
            from_date=from_date,
            signs=signs,
            equity_only=equity_only,
            by_period=by_period,
        )

        digest = dict(accounts=accounts_digest)

        if process_roles or process_groups:
            roles_mgr = RolesManager(tx_digest=digest,
                                     roles=process_roles,
                                     groups=process_groups,
                                     by_period=by_period)
            digest = roles_mgr.generate()

        if process_ratios:
            ratio_gen = FinancialRatioManager(tx_digest=digest)
            digest = ratio_gen.generate()

        if DJANGO_LEDGER_VALIDATE_SCHEMAS_AT_RUNTIME:
            validate(instance=digest, schema=SCHEMA_DIGEST)

        if not digest_name:
            digest_name = 'tx_digest'

        digest_results = {
            digest_name: digest,
        }

        if return_queryset:
            return txs_qs, digest_results
        return digest_results
Beispiel #2
0
    def digest(self,
               user_model: UserModel,
               accounts: set = None,
               activity: str = None,
               signs: bool = True,
               to_date: str = None,
               from_date: str = None,
               year: int = None,
               process_roles: bool = True,
               process_groups: bool = False,
               process_ratios: bool = False,
               equity_only: bool = False,
               by_period: bool = False) -> dict:

        accounts_digest = self.get_jes(
            user=user_model,
            accounts=accounts,
            activity=activity,
            to_date=to_date,
            from_date=from_date,
            year=year,
            signs=signs,
            equity_only=equity_only,
            by_period=by_period
        )

        digest = dict(
            accounts=accounts_digest
        )

        if process_roles or process_groups:
            roles_mgr = RolesManager(
                tx_digest=digest,
                roles=process_roles,
                groups=process_groups,
                by_period=by_period)
            digest = roles_mgr.generate()

        if process_ratios:
            ratio_gen = FinancialRatioManager(tx_digest=digest)
            digest = ratio_gen.generate()

        if DJANGO_LEDGER_VALIDATE_SCHEMAS_AT_RUNTIME:
            validate(instance=digest, schema=SCHEMA_DIGEST)

        return {
            'tx_digest': digest,
        }
Beispiel #3
0
    def digest(self,
               user_model: UserModel,
               accounts: set or list = None,
               activity: str = None,
               entity_slug: str = None,
               unit_slug: str = None,
               signs: bool = True,
               to_date: Union[str, datetime, date] = None,
               from_date: Union[str, datetime, date] = None,
               queryset: QuerySet = None,
               process_roles: bool = True,
               process_groups: bool = False,
               process_ratios: bool = False,
               equity_only: bool = False,
               by_period: bool = False,
               by_unit: bool = True,
               digest_name: str = None
               ) -> dict or tuple:

        txs_qs, accounts_digest = self.python_digest(
            queryset=queryset,
            user_model=user_model,
            accounts=accounts,
            activity=activity,
            entity_slug=entity_slug,
            unit_slug=unit_slug,
            to_date=to_date,
            from_date=from_date,
            signs=signs,
            equity_only=equity_only,
            by_period=by_period,
            by_unit=by_unit,
        )

        digest = dict(
            accounts=accounts_digest
        )

        if process_roles:
            roles_mgr = RoleManager(
                tx_digest=digest,
                by_period=by_period,
                by_unit=by_unit
            )
            digest = roles_mgr.digest()

        if process_groups:
            group_mgr = GroupManager(
                tx_digest=digest,
                by_period=by_period,
                by_unit=by_unit
            )
            digest = group_mgr.digest()

        if process_ratios:
            ratio_gen = FinancialRatioManager(tx_digest=digest)
            digest = ratio_gen.digest()

        if not digest_name:
            digest_name = 'tx_digest'

        digest_results = {
            digest_name: digest,
        }

        return txs_qs, digest_results