Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigo-barraza committed Dec 11, 2023
1 parent 6cc9bdc commit be2d5e2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 81 deletions.
2 changes: 1 addition & 1 deletion pay-api/src/pay_api/models/non_sufficient_funds.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Meta(BaseSchema.Meta): # pylint: disable=too-few-public-methods


@define
class NonSufficientFundsSearchModel:
class NonSufficientFundsSearchModel: # pylint: disable=too-few-public-methods
"""Used to search for NSF records."""

id: int
Expand Down
88 changes: 8 additions & 80 deletions pay-api/src/pay_api/services/non_sufficient_funds.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
from __future__ import annotations

from datetime import datetime
from typing import Optional

from flask import current_app

from pay_api.models import CfsAccount as CfsAccountModel
from pay_api.models import Invoice as InvoiceModel
from pay_api.models import InvoiceReference as InvoiceReferenceModel
from pay_api.models import InvoiceSchema, NonSufficientFundsModel, NonSufficientFundsSchema
from pay_api.models import InvoiceSchema, NonSufficientFundsModel
from pay_api.models import Payment as PaymentModel
from pay_api.models import PaymentAccount as PaymentAccountModel
from pay_api.models import PaymentLineItem as PaymentLineItemModel
Expand All @@ -33,89 +32,18 @@
from .oauth_service import OAuthService


class NonSufficientFundsService: # pylint: disable=too-many-instance-attributes,too-many-public-methods
class NonSufficientFundsService:
"""Service to manage Non-Sufficient Funds related operations."""

def __init__(self):
"""Initialize the service."""
self.__dao = None
self._id: int = None
self._invoice_id: int = None
self._description: Optional[str] = None

@property
def _dao(self):
if not self.__dao:
self.__dao = NonSufficientFundsModel()
return self.__dao

@_dao.setter
def _dao(self, value):
self.__dao = value
self.id: int = self._dao.id
self.invoice_id: int = self._dao.invoice_id
self.description: str = self._dao.description

@property
def id(self):
"""Return the _id."""
return self._id

@id.setter
def id(self, value: int):
"""Set the _id."""
self._id = value
self._dao.id = value

@property
def invoice_id(self):
"""Return the _invoice_id."""
return self._invoice_id

@invoice_id.setter
def invoice_id(self, value: int):
"""Set the _invoice_id."""
self._invoice_id = value
self._dao.invoice_id = value

@property
def description(self):
"""Return the Non-Sufficient Funds description."""
return self._description

@description.setter
def description(self, value: str):
"""Set the Non-Sufficient Funds description."""
self._description = value
self._dao.description = value

def commit(self):
"""Save the information to the DB."""
return self._dao.commit()

def rollback(self):
"""Rollback."""
return self._dao.rollback()

def flush(self):
"""Save the information to the DB."""
return self._dao.flush()

def save(self):
"""Save the information to the DB."""
return self._dao.save()

def asdict(self):
"""Return the Non-Sufficient Funds as a python dict."""
non_sufficient_funds_schema = NonSufficientFundsSchema()
d = non_sufficient_funds_schema.dump(self._dao)
return d
self.dao = NonSufficientFundsModel()

@staticmethod
def populate(value: NonSufficientFundsModel):
"""Populate Non-Sufficient Funds Service."""
non_sufficient_funds_service: NonSufficientFundsService = NonSufficientFundsService()
non_sufficient_funds_service._dao = value # pylint: disable=protected-access
non_sufficient_funds_service = NonSufficientFundsService()
non_sufficient_funds_service.dao = value
return non_sufficient_funds_service

@staticmethod
Expand All @@ -124,9 +52,9 @@ def save_non_sufficient_funds(invoice_id: int, description: str) -> NonSufficien
current_app.logger.debug('<save_non_sufficient_funds')
non_sufficient_funds_service = NonSufficientFundsService()

non_sufficient_funds_service.invoice_id = invoice_id
non_sufficient_funds_service.description = description
non_sufficient_funds_dao = non_sufficient_funds_service.save()
non_sufficient_funds_service.dao.invoice_id = invoice_id
non_sufficient_funds_service.dao.description = description
non_sufficient_funds_dao = non_sufficient_funds_service.dao.save()

non_sufficient_funds_service = NonSufficientFundsService.populate(non_sufficient_funds_dao)
current_app.logger.debug('>save_non_sufficient_funds')
Expand Down

0 comments on commit be2d5e2

Please sign in to comment.