Skip to content

Commit

Permalink
Merge branch 'main' of github.com:open-contracting/credere-backend in…
Browse files Browse the repository at this point in the history
…to 299-new-fetch-method
  • Loading branch information
yolile committed Jul 4, 2024
2 parents acffc69 + 101c6d2 commit 83be19d
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ ci:
skip: [pip-compile]
repos:
- repo: https://github.com/psf/black
rev: 24.3.0
rev: 24.4.2
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
rev: 7.1.0
hooks:
- id: flake8
additional_dependencies: [flake8-comprehensions]
Expand Down
1 change: 1 addition & 0 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ class CreditProductBase(SQLModel):
additional_information: str = Field(default="", nullable=False)
type: CreditType = Field(nullable=False)
borrower_types: dict[str, bool] = Field(default={}, sa_column=Column(JSON, nullable=False))
procurement_category_to_exclude: str = Field(default="", nullable=False)
required_document_types: dict[str, bool] = Field(default={}, sa_column=Column(JSON))
other_fees_total_amount: Decimal = Field(sa_column=Column(DECIMAL(precision=16, scale=2), nullable=False))
other_fees_description: str = Field(default="", nullable=False)
Expand Down
2 changes: 2 additions & 0 deletions app/routers/guest/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ async def credit_product_options(
models.CreditProduct.borrower_size == payload.borrower_size,
models.CreditProduct.lower_limit <= payload.amount_requested,
models.CreditProduct.upper_limit >= payload.amount_requested,
models.CreditProduct.procurement_category_to_exclude != application.award.procurement_category,
col(models.Lender.id).notin_(rejecter_lenders),
filter,
)
Expand All @@ -267,6 +268,7 @@ async def credit_product_options(
models.CreditProduct.borrower_size == payload.borrower_size,
models.CreditProduct.lower_limit <= payload.amount_requested,
models.CreditProduct.upper_limit >= payload.amount_requested,
models.CreditProduct.procurement_category_to_exclude != application.award.procurement_category,
col(models.Lender.id).notin_(rejecter_lenders),
filter,
)
Expand Down
15 changes: 15 additions & 0 deletions app/routers/lenders.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from app import dependencies, models, serializers
from app.db import get_db, rollback_on_error
from app.sources.colombia import get_procurement_categories
from app.util import commit_and_refresh, get_object_or_404

router = APIRouter()
Expand Down Expand Up @@ -156,6 +157,20 @@ async def get_lenders_list(
)


@router.get(
"/procurement-categories",
tags=["lenders"],
)
async def get_procurement_categories_from_source() -> list[str]:
"""
Get the list of the existing procurement categories from the source.
:return: The list of existing procurement categories.
"""

return get_procurement_categories()


@router.get(
"/credit-products/{credit_product_id}",
tags=["lenders"],
Expand Down
31 changes: 31 additions & 0 deletions app/sources/colombia.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,37 @@ def _get_remote_contract(
return sources.make_request_with_retry(contract_url, HEADERS).json(), contract_url


def get_procurement_categories():
# from https://www.datos.gov.co/resource/p6dx-8zbt.json?$query=SELECT distinct `tipo_de_contrato`
return [
"Comodato",
"Empréstito",
"Venta inmuebles",
"Seguros",
"Interventoría",
"Arrendamiento de muebles",
"Negocio fiduciario",
"Concesión",
"No",
"Asociación Público Privada",
"No Especificado",
"Otro",
"Acuerdo Marco de Precios",
"Arrendamiento de inmuebles",
"Compraventa",
"Comisión",
"Prestación de servicios",
"Decreto 092 de 2017",
"Venta muebles",
"Operaciones de Crédito Público",
"Suministros",
"Obra",
"Servicios financieros",
"Acuerdo de cooperación",
"Consultoría",
]


def get_award(
entry: dict[str, Any],
borrower_id: int | None = None,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""credit product procurement category
Revision ID: 63f2125bb242
Revises: 6a0d845e53cb
Create Date: 2024-07-03 17:19:57.192737
"""

from alembic import op
import sqlalchemy as sa
import sqlmodel # added

# revision identifiers, used by Alembic.
revision = "63f2125bb242"
down_revision = "6a0d845e53cb"
branch_labels = None
depends_on = None


def upgrade() -> None:
op.add_column(
"credit_product",
sa.Column(
"procurement_category_to_exclude",
sqlmodel.sql.sqltypes.AutoString(),
nullable=False,
server_default="",
),
)


def downgrade() -> None:
op.drop_column("credit_product", "procurement_category_to_exclude")
21 changes: 21 additions & 0 deletions migrations/versions/e92a5c6cf445_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""empty message
Revision ID: e92a5c6cf445
Revises: 63f2125bb242, c681e99808d6
Create Date: 2024-07-04 14:53:23.835649
"""

# revision identifiers, used by Alembic.
revision = "e92a5c6cf445"
down_revision = ("63f2125bb242", "c681e99808d6")
branch_labels = None
depends_on = None


def upgrade() -> None:
pass


def downgrade() -> None:
pass

0 comments on commit 83be19d

Please sign in to comment.