Files
sakhteman/app/repositories/bill_delay.py
T

67 lines
2.4 KiB
Python

from uuid import UUID
from app.config import TaskEnv
from app.models.bill_delay import BillDelayModel
from core.repositories.base import BaseRepository
class BillDelayRepository(BaseRepository):
def __init__(self):
super().__init__(collection=TaskEnv.CLN_BILL_DELAY, model=BillDelayModel)
def create_sum(self, coding: BillDelayModel) -> BillDelayModel:
all_total = 0
if coding.financial:
total = 0
if coding.financial.status:
total += coding.financial.status
if coding.financial.prepayment:
total += coding.financial.prepayment
if coding.financial.modification:
total += coding.financial.modification
if coding.financial.good_job:
total += coding.financial.good_job
coding.financial.total = total
all_total += total
if coding.force_major:
total = 0
if coding.force_major.force_event:
total += coding.force_major.force_event
if coding.force_major.material:
total += coding.force_major.material
if coding.force_major.rules:
total += coding.force_major.rules
if coding.force_major.define_indicators:
total += coding.force_major.define_indicators
coding.force_major.total = total
all_total += total
if coding.technical:
total = 0
if coding.technical.map_technical:
total += coding.technical.map_technical
if coding.technical.permit:
total += coding.technical.permit
if coding.technical.purchase:
total += coding.technical.purchase
if coding.technical.suspense:
total += coding.technical.suspense
coding.technical.total = total
all_total += total
if coding.extra_new_work:
all_total += coding.extra_new_work
if coding.other:
all_total += coding.other
if all_total:
coding.total_day = all_total
return coding
async def create(self, coding: BillDelayModel):
coding = self.create_sum(coding)
return await super().create(coding)
async def update(self, _id: UUID, update: BillDelayModel):
update = self.create_sum(update)
return await super().update(_id, update)