Skip to content

Commit

Permalink
feat: create_subsidy() - pass sales reference into underlying ledger
Browse files Browse the repository at this point in the history
This also bumps openedx-ledger to a verion (1.5.2) which supports
creating "initial" Deposit objects as part of Ledger creation.

ENT-9075
  • Loading branch information
pwnage101 committed Jul 10, 2024
1 parent bed205c commit 22b1cdd
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 8 deletions.
15 changes: 14 additions & 1 deletion enterprise_subsidy/apps/subsidy/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
from django.db.models.signals import pre_save
from django.dispatch import receiver
from openedx_ledger.api import create_ledger
from openedx_ledger.models import SalesContractReferenceProvider

from .models import Subsidy
from .models import Subsidy, SubsidyReferenceChoices


@receiver(pre_save, sender=Subsidy)
Expand All @@ -21,6 +22,16 @@ def subsidy_pre_save(sender, instance, *args, **kwargs): # pylint: disable=unus
if instance.ledger or not instance._state.adding:
return

# In order to call create_ledger() later, we first need to get or create a SalesContractReferenceProvider. In order
# to avoid manual intervention, we mirror the SubsidyReferenceChoices selection into the
# SalesContractReferenceProvider table as needed. The normal steady-state is to always just re-use (get) an existing
# provider.
subsidy_reference_choices = dict((slug, name) for slug, name in SubsidyReferenceChoices.CHOICES)
sales_contract_reference_provider, _ = SalesContractReferenceProvider.objects.get_or_create(
slug=instance.reference_type,
defaults={"name": subsidy_reference_choices[instance.reference_type]},
)

# create_ledger() saves the ledger instance.
# If a transaction for the starting_balance is created,
# that transaction record is also saved during
Expand All @@ -29,4 +40,6 @@ def subsidy_pre_save(sender, instance, *args, **kwargs): # pylint: disable=unus
unit=instance.unit,
subsidy_uuid=instance.uuid,
initial_deposit=instance.starting_balance,
sales_contract_reference_id=instance.reference_id,
sales_contract_reference_provider=sales_contract_reference_provider,
)
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ openedx-events==9.11.0
# -r requirements/base.in
# edx-event-bus-kafka
# openedx-ledger
openedx-ledger==1.5.1
openedx-ledger==1.5.2
# via -r requirements/base.in
packaging==24.1
# via drf-yasg
Expand Down
2 changes: 1 addition & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ openedx-events==9.11.0
# -r requirements/validation.txt
# edx-event-bus-kafka
# openedx-ledger
openedx-ledger==1.5.1
openedx-ledger==1.5.2
# via -r requirements/validation.txt
packaging==24.1
# via
Expand Down
2 changes: 1 addition & 1 deletion requirements/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ openedx-events==9.11.0
# -r requirements/test.txt
# edx-event-bus-kafka
# openedx-ledger
openedx-ledger==1.5.1
openedx-ledger==1.5.2
# via -r requirements/test.txt
packaging==24.1
# via
Expand Down
2 changes: 1 addition & 1 deletion requirements/production.txt
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ openedx-events==9.11.0
# -r requirements/base.txt
# edx-event-bus-kafka
# openedx-ledger
openedx-ledger==1.5.1
openedx-ledger==1.5.2
# via -r requirements/base.txt
packaging==24.1
# via
Expand Down
2 changes: 1 addition & 1 deletion requirements/quality.txt
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ openedx-events==9.11.0
# -r requirements/test.txt
# edx-event-bus-kafka
# openedx-ledger
openedx-ledger==1.5.1
openedx-ledger==1.5.2
# via -r requirements/test.txt
packaging==24.1
# via
Expand Down
2 changes: 1 addition & 1 deletion requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ openedx-events==9.11.0
# -r requirements/base.txt
# edx-event-bus-kafka
# openedx-ledger
openedx-ledger==1.5.1
openedx-ledger==1.5.2
# via -r requirements/base.txt
packaging==24.1
# via
Expand Down
2 changes: 1 addition & 1 deletion requirements/validation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ openedx-events==9.11.0
# -r requirements/test.txt
# edx-event-bus-kafka
# openedx-ledger
openedx-ledger==1.5.1
openedx-ledger==1.5.2
# via
# -r requirements/quality.txt
# -r requirements/test.txt
Expand Down

0 comments on commit 22b1cdd

Please sign in to comment.