aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--generalresearch/managers/thl/payout.py16
-rw-r--r--generalresearch/models/thl/payout.py5
-rw-r--r--pyproject.toml2
-rw-r--r--tests/models/thl/test_payout.py41
4 files changed, 40 insertions, 24 deletions
diff --git a/generalresearch/managers/thl/payout.py b/generalresearch/managers/thl/payout.py
index d4134ea..ee175ec 100644
--- a/generalresearch/managers/thl/payout.py
+++ b/generalresearch/managers/thl/payout.py
@@ -558,8 +558,16 @@ class BusinessPayoutEventManager(PostgresManagerWithRedis):
res = self.pg_config.execute_sql_query(
f"""
- SELECT sp.*
+ SELECT sp.*,
+ COALESCE(ep.line_item_count, 0) as line_item_count
FROM supplier_payout sp
+ LEFT JOIN (
+ SELECT
+ supplier_payout_id,
+ COUNT(1) AS line_item_count
+ FROM event_payout
+ GROUP BY supplier_payout_id
+ ) AS ep ON sp.id = ep.supplier_payout_id
{filter_str}
ORDER BY {order_by_sql}
{pagination_sql}
@@ -869,7 +877,11 @@ class BusinessPayoutEventManager(PostgresManagerWithRedis):
| {"supplier_payout_id": supplier_payout_pk},
)
conn.commit()
- return BusinessPayoutEvent(id=supplier_payout_pk, **bpe.model_dump())
+ return BusinessPayoutEvent(
+ id=supplier_payout_pk,
+ line_item_count=len(bpe.bp_payouts),
+ **bpe.model_dump(),
+ )
def create_from_ach_or_wire(
self,
diff --git a/generalresearch/models/thl/payout.py b/generalresearch/models/thl/payout.py
index 46b9b38..2b15ea4 100644
--- a/generalresearch/models/thl/payout.py
+++ b/generalresearch/models/thl/payout.py
@@ -9,6 +9,7 @@ from pydantic import (
BaseModel,
ConfigDict,
Field,
+ NonNegativeInt,
PositiveInt,
computed_field,
field_validator,
@@ -392,6 +393,10 @@ class BusinessPayoutEvent(BusinessPayoutEventCreate):
default=None,
)
+ line_item_count: NonNegativeInt = Field(
+ description="The number of line items in the payout.",
+ )
+
@model_validator(mode="after")
def validate_bp_payouts(self) -> Self:
if self.bp_payouts is None:
diff --git a/pyproject.toml b/pyproject.toml
index b856c6d..3a79353 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "generalresearch"
-version = "3.8.3"
+version = "3.8.4"
description = "Python Utilities for General Research"
readme = "README.md"
requires-python = ">=3.14"
diff --git a/tests/models/thl/test_payout.py b/tests/models/thl/test_payout.py
index cc00f33..5b00e01 100644
--- a/tests/models/thl/test_payout.py
+++ b/tests/models/thl/test_payout.py
@@ -14,13 +14,12 @@ from generalresearch.models.gr.business import (
from generalresearch.models.gr.definitions import BusinessType
from generalresearch.models.thl.payout import (
BrokerageProductPayoutEvent,
- BusinessPayoutEvent,
+ BusinessPayoutEventCreate,
)
from generalresearch.models.thl.wallet.definitions import PayoutType
class TestBusinessPayoutEvent:
-
def test_validate(self):
# Doesn't validate anymore
@@ -51,30 +50,30 @@ class TestBusinessPayoutEvent:
assert isinstance(b, Business)
ext_ref_id = uuid4().hex
- bpe = BusinessPayoutEvent(
+ bpe = BusinessPayoutEventCreate(
business_id=uuid4().hex,
amount=USDCent(100_00),
payout_type=PayoutType.ACH,
ext_ref_id=ext_ref_id,
+ bp_payouts=[
+ BrokerageProductPayoutEvent(
+ product_id=uuid4().hex,
+ payout_type=PayoutType.ACH,
+ amount=USDCent(47_00),
+ cashout_method_uuid=uuid4().hex,
+ debit_account_uuid=uuid4().hex,
+ ext_ref_id=ext_ref_id,
+ ),
+ BrokerageProductPayoutEvent(
+ product_id=uuid4().hex,
+ payout_type=PayoutType.ACH,
+ amount=USDCent(53_00),
+ cashout_method_uuid=uuid4().hex,
+ debit_account_uuid=uuid4().hex,
+ ext_ref_id=ext_ref_id,
+ ),
+ ],
)
- bpe.bp_payouts = [
- BrokerageProductPayoutEvent(
- product_id=uuid4().hex,
- payout_type=PayoutType.ACH,
- amount=USDCent(47_00),
- cashout_method_uuid=uuid4().hex,
- debit_account_uuid=uuid4().hex,
- ext_ref_id=ext_ref_id,
- ),
- BrokerageProductPayoutEvent(
- product_id=uuid4().hex,
- payout_type=PayoutType.ACH,
- amount=USDCent(53_00),
- cashout_method_uuid=uuid4().hex,
- debit_account_uuid=uuid4().hex,
- ext_ref_id=ext_ref_id,
- ),
- ]
# Test validations (amount sum)
with pytest.raises(