Skip to content

Commit

Permalink
[REVERT] daily goal to corp journal
Browse files Browse the repository at this point in the history
[FIX] Wrong Calculate Daily Goal for Char Ledger
  • Loading branch information
Geuthur committed Jan 24, 2025
1 parent e62b494 commit 6521229
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 19 deletions.
11 changes: 7 additions & 4 deletions ledger/api/api_helper/billboard_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.db.models.functions import TruncDay, TruncHour, TruncMonth, TruncYear

from ledger.api.api_helper.core_manager import LedgerData, LedgerDate, LedgerModels
from ledger.api.helpers import convert_ess_payout
from ledger.api.helpers import convert_corp_tax
from ledger.hooks import get_extension_logger

logger = get_extension_logger(__name__)
Expand Down Expand Up @@ -146,14 +146,17 @@ def _process_corp_journal(self, annotations, period_format):
if self.is_corp:
self.data_dict[period]["total_bounty"] = entry["total_bounty"]
self.data_dict[period]["total_ess"] = entry["total_ess"]
self.data_dict[period]["total_daily"] = entry["total_daily"]

if not self.is_corp:
# Convert the ESS Payout for Character
self.data_dict[period]["total_ess"] = convert_ess_payout(
self.data_dict[period]["total_ess"] = convert_corp_tax(
self.data_dict[period]["total_ess"]
)
# ADD Daily Goal to Character
self.data_dict[period]["total_daily"] = entry["total_daily"]
# Convert the Daily Goal Payout for Character
self.data_dict[period]["total_daily"] = convert_corp_tax(
self.data_dict[period]["total_daily"]
)

def _process_char_journal(self, annotations, period_format):
char_journal = (
Expand Down
6 changes: 3 additions & 3 deletions ledger/api/api_helper/character_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
LedgerModels,
LedgerTotal,
)
from ledger.api.helpers import convert_ess_payout, get_alts_queryset
from ledger.api.helpers import convert_corp_tax, get_alts_queryset
from ledger.hooks import get_extension_logger
from ledger.models.characteraudit import CharacterWalletJournalEntry

Expand Down Expand Up @@ -109,7 +109,7 @@ def process_character_chars(self):
char_id = char.get("char_id", 0)

total_bounty = round(char.get("total_bounty", 0))
total_ess = round(convert_ess_payout(char.get("total_ess", 0)))
total_ess = round(convert_corp_tax(char.get("total_ess", 0)))
total_others = round(char.get("total_others", 0))
total_costs = round(char.get("total_costs", 0))

Expand All @@ -136,7 +136,7 @@ def process_character_chars(self):
char_name = char.get("second_party__name", "Unknown")
char_id = char.get("second_party__eve_id", 0)

total_daily_goal = round(char.get("total_amount", 0))
total_daily_goal = round(convert_corp_tax(char.get("total_amount", 0)))

if total_daily_goal:
character_dict.add_amount_to_character(
Expand Down
15 changes: 12 additions & 3 deletions ledger/api/api_helper/template_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.db.models.functions import Coalesce
from django.utils import timezone

from ledger.api.helpers import convert_ess_payout, get_alts_queryset
from ledger.api.helpers import convert_corp_tax, get_alts_queryset
from ledger.hooks import get_extension_logger
from ledger.models.characteraudit import CharacterWalletJournalEntry
from ledger.models.corporationaudit import CorporationWalletJournalEntry
Expand Down Expand Up @@ -255,13 +255,22 @@ def _process_amounts_char(self, models, chars_list):
)

# Convert ESS Payout for Character Ledger
amounts["ess"]["total_amount"] = convert_ess_payout(
amounts["ess"]["total_amount"] = convert_corp_tax(
amounts["ess"]["total_amount"]
)

amounts["ess"]["total_amount_day"] = convert_ess_payout(
amounts["ess"]["total_amount_day"] = convert_corp_tax(
amounts["ess"]["total_amount_day"]
)
# Convert Daily Goal Payout for Character Ledger
amounts["daily_goal"]["total_amount"] = convert_corp_tax(
amounts["daily_goal"]["total_amount"]
)

amounts["daily_goal"]["total_amount_day"] = convert_corp_tax(
amounts["daily_goal"]["total_amount_day"]
)

# Calculate the stolen ESS
amounts["stolen"] = defaultdict(Decimal)
amounts = calculate_ess_stolen(amounts)
Expand Down
3 changes: 2 additions & 1 deletion ledger/api/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
logger = get_extension_logger(__name__)


def convert_ess_payout(ess: int) -> float:
# TODO Handle it from generate_ledger
def convert_corp_tax(ess: int) -> float:
"""Convert ESS payout"""
return (ess / app_settings.LEDGER_CORP_TAX) * (100 - app_settings.LEDGER_CORP_TAX)

Expand Down
13 changes: 5 additions & 8 deletions ledger/managers/corpjournal_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
DAILY_GOAL_REWARD_FILTER = Q(ref_type__in=DAILY_GOAL_REWARD, amount__gt=0)
CITADEL_FILTER = Q(ref_type__in=CITADEL_INCOME, amount__gt=0)

MISC_FILTER = INCURSION_FILTER | MISSION_FILTER | CITADEL_FILTER
MISC_FILTER = (
INCURSION_FILTER | MISSION_FILTER | DAILY_GOAL_REWARD_FILTER | CITADEL_FILTER
)


class CorpWalletQueryFilter(models.QuerySet):
Expand Down Expand Up @@ -104,10 +106,7 @@ def annotate_citadel(self, first_party_ids: list) -> models.QuerySet:


class CorpWalletQuerySet(CorpWalletQueryFilter):
def _get_linked_chars(
self, corporations: list, chars_ids: list
) -> tuple[dict, set]:
"""Get all linked characters to the given corporations and characters"""
def _get_linked_chars(self, corporations: list, chars_ids: list) -> tuple:
linked_chars = EveCharacter.objects.filter(corporation_id__in=corporations)
linked_chars |= EveCharacter.objects.filter(
character_ownership__user__profile__main_character__corporation_id__in=corporations
Expand Down Expand Up @@ -233,6 +232,7 @@ def generate_template(
# Define the types and their respective filters
types_filters = {
"ess": ESS_FILTER,
"daily_goal": DAILY_GOAL_REWARD_FILTER,
}

# Only Corp Ledger
Expand All @@ -241,9 +241,6 @@ def generate_template(
types_filters["mission"] = MISSION_FILTER
types_filters["incursion"] = INCURSION_FILTER
types_filters["citadel"] = CITADEL_FILTER
else:
# Only Char Ledger
types_filters["daily_goal"] = DAILY_GOAL_REWARD_FILTER

annotations = {}
# Create the template
Expand Down

0 comments on commit 6521229

Please sign in to comment.