Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some changes in validate/verfiy flow #6055

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions bluebottle/funding/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from bluebottle.funding.validators import (
DeadlineValidator,
TargetValidator,
DeadlineMaxValidator,
DeadlineMaxValidator, BudgetValidator,
)
from bluebottle.utils.exchange_rates import convert
from bluebottle.utils.fields import MoneyField
Expand Down Expand Up @@ -154,7 +154,7 @@ class Funding(Activity):

needs_review = True

validators = [DeadlineValidator, DeadlineMaxValidator, TargetValidator]
validators = [DeadlineValidator, DeadlineMaxValidator, TargetValidator, BudgetValidator]

auto_approve = False

Expand Down Expand Up @@ -215,6 +215,12 @@ def update_amounts(self):
)
self.save()

@property
def total_budget(self):
budget_lines = self.budget_lines.all()
total_amount = sum(line.amount.amount for line in budget_lines)
return Money(currency=self.target.currency, amount=total_amount)

@property
def activity_date(self):
return self.deadline
Expand Down
4 changes: 3 additions & 1 deletion bluebottle/funding/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ class BudgetLineSerializer(ModelSerializer):
activity = ResourceRelatedField(queryset=Funding.objects.all())
amount = MoneySerializer()

validators = [FundingCurrencyValidator()]
validators = [
FundingCurrencyValidator(),
]

included_serializers = {
'activity': 'bluebottle.funding.serializers.FundingSerializer',
Expand Down
2 changes: 0 additions & 2 deletions bluebottle/funding/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ def psp_allows_refunding(self):
self.instance.bank_account.provider_class.refund_enabled

def kyc_is_valid(self):
if self.instance.payout_account:
print(self.instance.payout_account.status)
return (
self.instance.payout_account
and self.instance.payout_account.status == "verified"
Expand Down
11 changes: 0 additions & 11 deletions bluebottle/funding/triggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,17 +274,6 @@ class BankAccountTriggers(TriggerManager):
)
]
),
TransitionTrigger(
BankAccountStateMachine.verify,
effects=[
SubmitConnectedActivitiesEffect,
RelatedTransitionEffect(
'connect_account',
PlainPayoutAccountStateMachine.verify,
description='Verify connected KYC account'
)
]
),
]


Expand Down
11 changes: 11 additions & 0 deletions bluebottle/funding/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,14 @@ def is_valid(self):
if self.instance.target.amount <= 0:
return False
return True


class BudgetValidator(Validator):
code = 'budget'
message = _("Budget doesn't match the crowdfunding target")
field = 'budget'

def is_valid(self):
if self.instance.target.amount != self.instance.total_budget.amount:
return False
return True
1 change: 0 additions & 1 deletion bluebottle/funding_stripe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,6 @@ def get_account_link(self):

def update(self, data):
self.verified = data.individual.verification.status == "verified"
self.states.verify()
self.payments_enabled = data.charges_enabled
self.payouts_enabled = data.payouts_enabled

Expand Down