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

PLD Blocking accounts #396

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
14 changes: 10 additions & 4 deletions speid/models/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,16 @@ def is_valid_account(self) -> bool:
account = Account.objects.get(cuenta=self.cuenta_beneficiario)
if account.is_restricted:
ordenante = self.rfc_curp_ordenante
is_valid = (
ordenante == account.allowed_rfc
or ordenante == account.allowed_curp
) and self.monto >= MIN_AMOUNT
is_valid = all(
[
(
ordenante == account.allowed_rfc
or ordenante == account.allowed_curp
),
self.monto >= MIN_AMOUNT,
account.estado != Estado.pld_blocked,
]
)
except DoesNotExist:
pass
return is_valid
Expand Down
13 changes: 12 additions & 1 deletion speid/tasks/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from stpmex.exc import InvalidRfcOrCurp, StpmexException
from stpmex.resources.cuentas import Cuenta

from speid.models import Event, PhysicalAccount
from speid.models import Event, MoralAccount, PhysicalAccount
from speid.models.account import Account
from speid.tasks import celery
from speid.types import Estado, EventType
Expand Down Expand Up @@ -83,3 +83,14 @@ def deactivate_account(self, cuenta: str) -> None:
else:
account.estado = Estado.deactivated
account.save()


@celery.task(bind=True, max_retries=5)
def block_account(self, cuenta: str) -> None:
try:
account = MoralAccount.objects.get(cuenta=cuenta)
except DoesNotExist:
...
else:
account.estado = Estado.pld_blocked
account.save()
1 change: 1 addition & 0 deletions speid/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Estado(str, Enum):
rejected = 'rejected'
error = 'error' # Malformed order
deactivated = 'deactivated'
pld_blocked = 'pld_blocked' # Blocked but not deactivated

@classmethod
def get_state_from_stp(cls, stp_state: str) -> Enum:
Expand Down
21 changes: 21 additions & 0 deletions tests/tasks/test_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from speid.models import PhysicalAccount
from speid.models.account import MoralAccount
from speid.tasks.accounts import (
block_account,
create_account,
deactivate_account,
execute_create_account,
Expand Down Expand Up @@ -340,3 +341,23 @@ def test_deactivate_account_doesnot_exist(
):
deactivate_account('646180157000011122')
mock_retry.assert_not_called()


@patch('speid.tasks.accounts.block_account.retry')
def test_block_account(
mock_retry: MagicMock,
moral_account: MoralAccount,
):
assert moral_account.estado == Estado.succeeded
block_account(moral_account.cuenta)
moral_account.reload()
assert moral_account.estado == Estado.pld_blocked
mock_retry.assert_not_called()


@patch('speid.tasks.accounts.block_account.retry')
def test_block_account_doesnot_exist(
mock_retry: MagicMock,
):
block_account('646180157000011122')
mock_retry.assert_not_called()
21 changes: 19 additions & 2 deletions tests/views/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def test_create_incoming_restricted_account(
):
"""
Validate reject a depoist to restricted account if the
curp_rfc does not match with ordeenante
curp_rfc does not match with ordenante
"""
default_income_transaction['CuentaBeneficiario'] = moral_account.cuenta
moral_account.is_restricted = True
Expand All @@ -265,8 +265,25 @@ def test_create_incoming_restricted_account(
assert resp.json['estado'] == 'DEVOLUCION'
transaction.delete()

# curp and monto match, the transaction is approve, at least $100.0
# Curp Match and Monto match but account is blocked.
# The transaction is rejected
default_income_transaction['Monto'] = 100.00
default_income_transaction['RFCCurpOrdenante'] = moral_account.allowed_curp
default_income_transaction['ClaveRastreo'] = 'PRUEBATAMIZI2'
moral_account.estado = Estado.pld_blocked
moral_account.save()
resp = client.post('/ordenes', json=default_income_transaction)
transaction = Transaction.objects.order_by('-created_at').first()
assert transaction.estado is Estado.rejected
assert resp.status_code == 201
assert resp.json['estado'] == 'DEVOLUCION'
transaction.delete()

# curp, monto match and account is succeeded
# the transaction is approve, at least $100.0
default_income_transaction['Monto'] = 100.0
moral_account.estado = Estado.succeeded
moral_account.save()
resp = client.post('/ordenes', json=default_income_transaction)
transaction = Transaction.objects.order_by('-created_at').first()
assert resp.status_code == 201
Expand Down