def current_ratio(self, request): cr = {"status": "", "ratio": 0} accounts = Account.objects.filter( is_active=True, account_type__classification=AccountClassifications.CURRENT, account_type__category__in=[ AccountCategories.ASSET, AccountCategories.LIABILITY ]) total_assets = 0 total_liabilities = 0 for account in accounts: if account.account_type.category == AccountCategories.ASSET: total_assets += account.get_balance() elif account.account_type.category == AccountCategories.LIABILITY: total_liabilities += account.get_balance() cr["ratio"] = 0 if (total_liabilities != 0): cr["ratio"] = Decimal(total_assets / total_liabilities) if cr["ratio"] < 0.02: cr["status"] = "red" elif cr["ratio"] >= 0.02 and cr["ratio"] <= 0.05: cr["status"] = "yellow" else: cr["status"] = "green" cr["ratio"] = format_percent(cr["ratio"] * 100) return Response(cr)
def net_profit_margin(self, request): ratio = 0 status = "" net_profit = 0 total_sales = 0 accounts = Account.objects.filter(is_active=True, account_type__category__in=[ AccountCategories.REVENUE, AccountCategories.EXPENSE ]) for account in accounts: account_balance = account.get_balance() if account.account_type.category == AccountCategories.REVENUE: # TODO: make sure it is correct to use all revenues for this total_sales += account_balance net_profit += account_balance elif account.account_type.category == AccountCategories.EXPENSE: net_profit -= account_balance output = 0 if total_sales != 0: output = Decimal(net_profit / total_sales) if output < 0.05: status = "red" elif output >= 0.05 and output < 0.1: status = "yellow" else: status = "green" output = format_percent(output * 100) return Response({'ratio': output, 'status': status})
def asset_turnover(self, request): ratio = 0 status = "" total_assets = 0 total_sales = 0 accounts = Account.objects.filter(is_active=True, account_type__category__in=[ AccountCategories.ASSET, AccountCategories.REVENUE ]) for account in accounts: account_balance = account.get_balance() if account.account_type.category == AccountCategories.ASSET: total_assets += account_balance elif account.account_type.category == AccountCategories.REVENUE: # TODO: make sure it is correct to use all revenues for this total_sales += account_balance output = 0 if total_assets != 0: output = Decimal(total_sales / total_assets) if output < 0.03: status = "red" elif output >= 0.03 and output < 0.07: status = "yellow" else: status = "green" output = format_percent(output * 100) return Response({'ratio': output, 'status': status})
def return_on_equity(self, request): ratio = 0 status = "" net_profit = 0 total_equity = 0 accounts = Account.objects.filter(is_active=True, account_type__category__in=[ AccountCategories.EQUITY, AccountCategories.REVENUE, AccountCategories.EXPENSE ]) for account in accounts: account_balance = account.get_balance() if account.account_type.category == AccountCategories.EQUITY: total_equity += account_balance elif account.account_type.category == AccountCategories.REVENUE: net_profit += account_balance elif account.account_type.category == AccountCategories.EXPENSE: net_profit -= account_balance output = 0 if total_equity != 0: output = Decimal(net_profit / total_equity) if output < 0.05: status = "red" elif output >= 0.05 and output < 0.1: status = "yellow" else: status = "green" output = format_percent(output * 100) return Response({'ratio': output, 'status': status})
def quick_ratio(self, request): ratio = 0 status = "" total_assets = 0 total_liabilities = 0 total_inventory = 0 accounts = Account.objects.filter( is_active=True, account_type__classification=AccountClassifications.CURRENT, account_type__category__in=[ AccountCategories.ASSET, AccountCategories.LIABILITY ]) for account in accounts: account_balance = account.get_balance() if account.account_type.category == AccountCategories.ASSET: total_assets += account_balance if account.account_type.name == "Inventories": total_inventory += account_balance elif account.account_type.category == AccountCategories.LIABILITY: total_liabilities += account_balance output = 0 if total_liabilities != 0: output = Decimal( (total_assets - total_inventory) / total_liabilities) if output < 0.02: status = "red" elif output >= 0.02 and output < 0.04: status = "yellow" else: status = "green" output = format_percent(output * 100) return Response({'ratio': output, 'status': status})