feat:add financial pre payment
This commit is contained in:
@@ -0,0 +1,14 @@
|
|||||||
|
import datetime
|
||||||
|
import uuid
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
from pydantic import Field
|
||||||
|
|
||||||
|
from core.models.base import BaseModel
|
||||||
|
|
||||||
|
|
||||||
|
class PrePaymentModel(BaseModel):
|
||||||
|
id: Optional[uuid.UUID] = Field(alias='_id')
|
||||||
|
project_id: Optional[uuid.UUID] = Field(description="کد شناسایی پروژه در این فیلد قرار می گیرد")
|
||||||
|
amount:Optional[int]=Field(description='مبلغ')
|
||||||
|
date_at:Optional[datetime.datetime] = Field(description='تاریخ پرداخت')
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import uuid
|
||||||
|
|
||||||
|
from app.config import TaskEnv
|
||||||
|
from app.models.financial_pre_payment import PrePaymentModel
|
||||||
|
from core.repositories.base import BaseRepository
|
||||||
|
from core.service.mongo_db import use_collection
|
||||||
|
|
||||||
|
|
||||||
|
class PrePaymentRepository(BaseRepository):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__(collection=TaskEnv.CLN_FINANCIAL_PRE_PAYMENT, model=PrePaymentModel)
|
||||||
|
|
||||||
|
|
||||||
|
async def sum_amount(self,project_id:uuid.UUID):
|
||||||
|
sum = await use_collection(TaskEnv.CLN_FINANCIAL_PRE_PAYMENT).aggregate([
|
||||||
|
{'$match': {'project_id': project_id}},
|
||||||
|
{'$group': {'_id': None, 'sum': { '$sum': "$amount"}}}
|
||||||
|
]).to_list(None)
|
||||||
|
if sum:
|
||||||
|
return sum[0]['sum']
|
||||||
|
return None
|
||||||
|
|
||||||
|
async def get_list(self,project_id:uuid.UUID):
|
||||||
|
get_list = await use_collection(TaskEnv.CLN_FINANCIAL_PRE_PAYMENT).find({'project_id': project_id}).to_list(None)
|
||||||
|
return get_list
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
from uuid import UUID
|
||||||
|
|
||||||
|
from fastapi import Body
|
||||||
|
|
||||||
|
from app.models.financial_pre_payment import PrePaymentModel
|
||||||
|
from app.repositories.financial_pre_payment import PrePaymentRepository
|
||||||
|
from core.app import app
|
||||||
|
from core.utils.router import generate_router, shrink
|
||||||
|
from core.utils.table_engine import TableEngineExport, TableEngineRequestType
|
||||||
|
|
||||||
|
ThisModel = PrePaymentModel
|
||||||
|
router_base_url = 'financial_pre'
|
||||||
|
_tag_base = [router_base_url]
|
||||||
|
router = generate_router(router_base_url, auth_dependencies=False, version='v2')
|
||||||
|
repo = PrePaymentRepository()
|
||||||
|
|
||||||
|
@router.post('/create', response_model=ThisModel, tags=_tag_base)
|
||||||
|
@shrink(repo.create)
|
||||||
|
def create(coding: ThisModel = Body(...)):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@router.get('sum/{project_id}', response_model=ThisModel, tags=_tag_base)
|
||||||
|
@shrink(repo.sum_amount)
|
||||||
|
def sum_amount(project_id: UUID):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@router.get('list/{project_id}', response_model=ThisModel, tags=_tag_base)
|
||||||
|
@shrink(repo.get_list)
|
||||||
|
def get_list(project_id: UUID):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@router.put('/{_id}', response_model=ThisModel, tags=_tag_base)
|
||||||
|
@shrink(repo.update)
|
||||||
|
def update(_id: UUID, coding: ThisModel = Body(...)):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@router.get('/{_id}', response_model=ThisModel, tags=_tag_base)
|
||||||
|
@shrink(repo.get)
|
||||||
|
def get(_id: UUID):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@router.delete('/{_id}', response_model=ThisModel, tags=_tag_base)
|
||||||
|
@shrink(repo.delete)
|
||||||
|
def delete(_id: UUID):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@router.post('', response_model=TableEngineExport[ThisModel], tags=_tag_base)
|
||||||
|
@shrink(repo.fetch)
|
||||||
|
def fetch(body: TableEngineRequestType = Body(...)):
|
||||||
|
pass
|
||||||
|
|
||||||
|
app.include_router(router)
|
||||||
Reference in New Issue
Block a user