general cleanup
This commit is contained in:
+15
-12
@@ -1,16 +1,16 @@
|
||||
from .customer import Customer
|
||||
# from .customer import Customer
|
||||
from .account import Account
|
||||
from .loan import Loan
|
||||
from .transaction import Transaction
|
||||
from .repayment import Repayment
|
||||
from .loan_charge import LoanCharge
|
||||
from .offer import Offer
|
||||
from .charge import Charge
|
||||
from .rac_checks import RACCheck
|
||||
from .loan_repayment_schedule import LoanRepaymentSchedule
|
||||
from .transaction_offers import TransactionOffer
|
||||
from .repayments_data import RepaymentsData
|
||||
from .salary import Salary
|
||||
# from .loan import Loan
|
||||
# from .transaction import Transaction
|
||||
# from .repayment import Repayment
|
||||
# from .loan_charge import LoanCharge
|
||||
# from .offer import Offer
|
||||
# from .charge import Charge
|
||||
# from .rac_checks import RACCheck
|
||||
# from .loan_repayment_schedule import LoanRepaymentSchedule
|
||||
# from .transaction_offers import TransactionOffer
|
||||
# from .repayments_data import RepaymentsData
|
||||
# from .salary import Salary
|
||||
from .members import Members
|
||||
from .products import Products
|
||||
from .members_products import MembersProducts
|
||||
@@ -24,6 +24,8 @@ from .members_products_settings import MembersProductsSettings
|
||||
from .members_profile import MembersProfile
|
||||
from .subscription_options import SubscriptionOptions
|
||||
from .subscription_options_items import SubscriptionOptionsItems
|
||||
from .products_templates import ProductsTemplates
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -32,6 +34,7 @@ __all__ = ['Members','Customer', 'Account', 'Products',
|
||||
'MembersProducts', 'MembersActions', 'MembersPending', 'ProductsDetails',
|
||||
'ProvisionActions', 'MembersProductsRefresh','MembersProductsSettings',
|
||||
'PasswordReset','MembersProfile','SubscriptionOptions','SubscriptionOptionsItems',
|
||||
'ProductsTemplates',
|
||||
|
||||
'Loan', 'Transaction', 'Repayment',
|
||||
'LoanCharge', 'Offer', 'Charge', 'RACCheck', 'LoanRepaymentSchedule',
|
||||
|
||||
@@ -15,12 +15,12 @@ class Account(db.Model):
|
||||
created_at = db.Column(db.DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = db.Column(db.DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||||
|
||||
customer = relationship(
|
||||
"Customer",
|
||||
primaryjoin="Customer.id == Account.customer_id",
|
||||
foreign_keys=[customer_id],
|
||||
back_populates="accounts",
|
||||
)
|
||||
# customer = relationship(
|
||||
# "Customer",
|
||||
# primaryjoin="Customer.id == Account.customer_id",
|
||||
# foreign_keys=[customer_id],
|
||||
# back_populates="accounts",
|
||||
# )
|
||||
|
||||
@classmethod
|
||||
def create_account(cls, id, customer_id, account_type, status='active'):
|
||||
|
||||
@@ -15,12 +15,12 @@ class Charge(db.Model):
|
||||
due = db.Column(db.Integer, nullable=False)
|
||||
created_at = db.Column(db.DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = db.Column(db.DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||||
offer = relationship(
|
||||
"Offer",
|
||||
primaryjoin="Charge.offer_id == Offer.id",
|
||||
foreign_keys=[offer_id],
|
||||
back_populates="charges",
|
||||
)
|
||||
# offer = relationship(
|
||||
# "Offer",
|
||||
# primaryjoin="Charge.offer_id == Offer.id",
|
||||
# foreign_keys=[offer_id],
|
||||
# back_populates="charges",
|
||||
# )
|
||||
|
||||
@classmethod
|
||||
def add_charges(cls, offer_id, charges):
|
||||
|
||||
+18
-18
@@ -16,26 +16,26 @@ class Customer(db.Model):
|
||||
country_code = db.Column(db.String(3), nullable=False)
|
||||
created_at = db.Column(db.DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = db.Column(db.DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||||
accounts = relationship(
|
||||
"Account",
|
||||
primaryjoin="Customer.id == Account.customer_id",
|
||||
foreign_keys="Account.customer_id",
|
||||
back_populates="customer",
|
||||
)
|
||||
# accounts = relationship(
|
||||
# # "Account",
|
||||
# # primaryjoin="Customer.id == Account.customer_id",
|
||||
# # foreign_keys="Account.customer_id",
|
||||
# # back_populates="customer",
|
||||
# # )
|
||||
|
||||
loans = relationship(
|
||||
"Loan",
|
||||
primaryjoin="Customer.id == Loan.customer_id",
|
||||
foreign_keys="Loan.customer_id",
|
||||
back_populates="customer",
|
||||
)
|
||||
# loans = relationship(
|
||||
# "Loan",
|
||||
# primaryjoin="Customer.id == Loan.customer_id",
|
||||
# foreign_keys="Loan.customer_id",
|
||||
# back_populates="customer",
|
||||
# )
|
||||
|
||||
transaction_offers = relationship(
|
||||
"TransactionOffer",
|
||||
primaryjoin="Customer.id == TransactionOffer.customer_id",
|
||||
foreign_keys="TransactionOffer.customer_id",
|
||||
back_populates="customer",
|
||||
)
|
||||
# transaction_offers = relationship(
|
||||
# "TransactionOffer",
|
||||
# primaryjoin="Customer.id == TransactionOffer.customer_id",
|
||||
# foreign_keys="TransactionOffer.customer_id",
|
||||
# back_populates="customer",
|
||||
# )
|
||||
|
||||
@classmethod
|
||||
def is_valid_customer(cls, customer_id):
|
||||
|
||||
+6
-6
@@ -50,12 +50,12 @@ class Loan(db.Model):
|
||||
verify_result = db.Column(db.String(10), nullable=True)
|
||||
verify_description = db.Column(db.String(100), nullable=True)
|
||||
|
||||
customer = relationship(
|
||||
"Customer",
|
||||
primaryjoin="Customer.id == Loan.customer_id",
|
||||
foreign_keys=[customer_id],
|
||||
back_populates="loans",
|
||||
)
|
||||
# customer = relationship(
|
||||
# "Customer",
|
||||
# primaryjoin="Customer.id == Loan.customer_id",
|
||||
# foreign_keys=[customer_id],
|
||||
# back_populates="loans",
|
||||
# )
|
||||
|
||||
loan_charges = relationship(
|
||||
"LoanCharge",
|
||||
|
||||
@@ -19,12 +19,12 @@ class LoanCharge(db.Model):
|
||||
due_date = db.Column(db.DateTime, nullable=True)
|
||||
created_at = db.Column(db.DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = db.Column(db.DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||||
loan = relationship(
|
||||
"Loan",
|
||||
primaryjoin="LoanCharge.loan_id == Loan.id",
|
||||
foreign_keys=[loan_id],
|
||||
back_populates="loan_charges",
|
||||
)
|
||||
# loan = relationship(
|
||||
# "Loan",
|
||||
# primaryjoin="LoanCharge.loan_id == Loan.id",
|
||||
# foreign_keys=[loan_id],
|
||||
# back_populates="loan_charges",
|
||||
# )
|
||||
|
||||
@classmethod
|
||||
def create_charges_for_loan(cls, loan_id, transaction_id, charges, referenced_amount = 0.0):
|
||||
|
||||
@@ -20,12 +20,12 @@ class LoanRepaymentSchedule(db.Model):
|
||||
|
||||
created_at = db.Column(db.DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = db.Column(db.DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||||
loan = relationship(
|
||||
"Loan",
|
||||
primaryjoin="LoanRepaymentSchedule.loan_id == Loan.id",
|
||||
foreign_keys=[loan_id],
|
||||
back_populates="loan_repayment_schedules",
|
||||
)
|
||||
# loan = relationship(
|
||||
# "Loan",
|
||||
# primaryjoin="LoanRepaymentSchedule.loan_id == Loan.id",
|
||||
# foreign_keys=[loan_id],
|
||||
# back_populates="loan_repayment_schedules",
|
||||
# )
|
||||
|
||||
|
||||
@classmethod
|
||||
|
||||
+6
-6
@@ -24,12 +24,12 @@ class Offer(db.Model):
|
||||
created_at = db.Column(db.DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = db.Column(db.DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||||
|
||||
charges = relationship(
|
||||
"Charge",
|
||||
primaryjoin="Offer.id == Charge.offer_id",
|
||||
foreign_keys="Charge.offer_id",
|
||||
back_populates="offer",
|
||||
)
|
||||
# charges = relationship(
|
||||
# "Charge",
|
||||
# primaryjoin="Offer.id == Charge.offer_id",
|
||||
# foreign_keys="Charge.offer_id",
|
||||
# back_populates="offer",
|
||||
# )
|
||||
|
||||
@classmethod
|
||||
def get_all_offers(cls):
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
from datetime import datetime, timezone
|
||||
from app.extensions import db
|
||||
from app.models.charge import Charge
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
|
||||
class Offer(db.Model):
|
||||
__tablename__ = 'payments'
|
||||
|
||||
id = db.Column(db.String, primary_key=True)
|
||||
product_id = db.Column(db.String, nullable=False)
|
||||
min_amount = db.Column(db.Float, nullable=False)
|
||||
max_amount = db.Column(db.Float, nullable=False)
|
||||
tenor = db.Column(db.Integer, nullable=False)
|
||||
schedule = db.Column(db.Integer, nullable=True)
|
||||
interest_rate = db.Column(db.Float, default=3.0)
|
||||
management_rate = db.Column(db.Float, default=1.0)
|
||||
insurance_rate = db.Column(db.Float, default=1.0)
|
||||
vat_rate = db.Column(db.Float, default=7.5)
|
||||
list_order = db.Column(db.Integer, nullable=True)
|
||||
max_daily_loans = db.Column(db.Integer, nullable=True)
|
||||
max_active_loans = db.Column(db.Integer, nullable=True)
|
||||
max_life_loans = db.Column(db.Integer, nullable=True)
|
||||
created_at = db.Column(db.DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = db.Column(db.DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||||
|
||||
charges = relationship(
|
||||
"Charge",
|
||||
primaryjoin="Offer.id == Charge.offer_id",
|
||||
foreign_keys="Charge.offer_id",
|
||||
back_populates="offer",
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def get_all_offers(cls):
|
||||
"""
|
||||
Return all offers in dictionary format.
|
||||
"""
|
||||
offers = cls.query.all()
|
||||
|
||||
if not offers:
|
||||
raise ValueError(f"No available offers")
|
||||
return offers
|
||||
|
||||
@classmethod
|
||||
def is_valid_offer(cls, offer_id):
|
||||
offer = cls.query.filter_by(id=str(offer_id)).first()
|
||||
|
||||
if not offer:
|
||||
return False
|
||||
return offer
|
||||
|
||||
@classmethod
|
||||
def get_offer_by_id(cls, offer_id):
|
||||
"""
|
||||
Return an offer by its ID.
|
||||
"""
|
||||
offer = cls.query.filter_by(id=str(offer_id)).first()
|
||||
|
||||
if not offer:
|
||||
raise ValueError(f"Offer with ID {offer_id} not found")
|
||||
return offer
|
||||
|
||||
@classmethod
|
||||
def get_offer_by_product_id(cls, product_id):
|
||||
"""
|
||||
Return an offer by its product ID.
|
||||
"""
|
||||
offer = cls.query.filter_by(product_id=str(product_id)).first()
|
||||
|
||||
if not offer:
|
||||
raise ValueError(f"Offer with Product ID {product_id} not found")
|
||||
return offer
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
"offerId": self.id,
|
||||
"productId": self.product_id,
|
||||
"minAmount": self.min_amount,
|
||||
"maxAmount": self.max_amount,
|
||||
"tenor": self.tenor,
|
||||
"interest_rate": self.interest_rate,
|
||||
"management_rate": self.management_rate,
|
||||
"insurance_rate": self.insurance_rate,
|
||||
"vat_rate": self.vat_rate,
|
||||
"maxDailyLoans": self.max_daily_loans,
|
||||
"maxActiveLoans": self.max_active_loans,
|
||||
"maxLifeLoans": self.max_life_loans
|
||||
|
||||
}
|
||||
|
||||
def __repr__(self):
|
||||
return f'<LoanOffer {self.id}>'
|
||||
@@ -0,0 +1,41 @@
|
||||
from datetime import datetime, timezone
|
||||
from app.extensions import db
|
||||
from app.models.charge import Charge
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
class ProductsTemplates(db.Model):
|
||||
__tablename__ = 'products_templates'
|
||||
|
||||
id = db.Column(db.String, primary_key=True)
|
||||
uid = db.Column(db.String, nullable=False)
|
||||
product_id = db.Column(db.String, nullable=False)
|
||||
name = db.Column(db.String, nullable=False)
|
||||
status = db.Column(db.Integer, nullable=True, default=1)
|
||||
owner_uid = db.Column(db.String, nullable=False)
|
||||
provision_name = db.Column(db.String, nullable=False)
|
||||
added = db.Column(db.DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||||
|
||||
|
||||
@classmethod
|
||||
def get_template_by_product_id(cls, product_id):
|
||||
templates = cls.query.filter_by(product_id=str(product_id)).all()
|
||||
|
||||
if not templates:
|
||||
raise ValueError(f"Templates with Product ID {product_id} not found")
|
||||
return templates
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
"id": self.id,
|
||||
"uid": self.uid,
|
||||
"product_id": self.product_id,
|
||||
"name": self.name,
|
||||
"status": self.status,
|
||||
"owner_uid": self.owner_uid,
|
||||
"provision_name": self.provision_name,
|
||||
"provision_name": self.provision_name
|
||||
}
|
||||
|
||||
def __repr__(self):
|
||||
return f'<LoanOffer {self.id}>'
|
||||
@@ -24,12 +24,12 @@ class TransactionOffer(db.Model):
|
||||
|
||||
created_at = db.Column(db.DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = db.Column(db.DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||||
customer = relationship(
|
||||
"Customer",
|
||||
primaryjoin="Customer.id == TransactionOffer.customer_id",
|
||||
foreign_keys=[customer_id],
|
||||
back_populates="transaction_offers",
|
||||
)
|
||||
# customer = relationship(
|
||||
# "Customer",
|
||||
# primaryjoin="Customer.id == TransactionOffer.customer_id",
|
||||
# foreign_keys=[customer_id],
|
||||
# back_populates="transaction_offers",
|
||||
# )
|
||||
|
||||
@classmethod
|
||||
def is_valid_transaction_offer(cls, transaction_offer, customer_id, product_id):
|
||||
|
||||
Reference in New Issue
Block a user