Refactor a bit to avoid monster formula

This commit is contained in:
counterweight 2023-12-02 18:07:21 +01:00
parent f5b33cce74
commit 385db5422e
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C

View file

@ -118,24 +118,27 @@ def generate_um_report(
if not order.contains_sku(relevant_sku):
continue
logger.debug(f"Reporting for order {order[ORDER_KEYS.id]}")
# A few helper variables to make the last variable more understandable
sats_received_for_sku = order.sats_received_for_sku(relevant_sku)
bbo_fee_if_applicable = (BBO_ROYALTY_FEE_PERCENTAGE * (relevant_sku in BBO_SKUS))
discount_factor_for_bbo_skus = 1 - bbo_fee_if_applicable
# We owe UM his percentages of the sats received after discounting
# royalties paid to BBO for the BBO products.
sats_owed_to_um = (
(sats_received_for_sku * discount_factor_for_bbo_skus)
* UM_FIRST_AGREEMENT_PERCENTAGE,
)
report.append(
{
"order_id": order[ORDER_KEYS.id],
"sku": relevant_sku,
"units_sold": order.units_of_sku(relevant_sku),
"eur_income": order.sales_of_sku(relevant_sku),
"sats_income": order.sats_received_for_sku(relevant_sku),
"sats_owed_to_um": (
order.sats_received_for_sku(relevant_sku)
* (
1
- (
BBO_ROYALTY_FEE_PERCENTAGE
* (relevant_sku in BBO_SKUS)
)
)
)
* UM_FIRST_AGREEMENT_PERCENTAGE,
"sats_income": sats_received_for_sku,
"sats_owed_to_um": sats_owed_to_um,
}
)
logger.info("Report generated.")