Fix: Employee and Account showed [object Object] in Department instead of the department name.
This is due to enabling strict mode in Typescript and changing the list department from string to object. But the html was not updated.
This commit is contained in:
parent
9cd4a4ef20
commit
4c4c1b994e
brewman/brewman
overlord/src/app
@ -1,7 +1,8 @@
|
||||
import uuid
|
||||
|
||||
from datetime import datetime
|
||||
from typing import List, Optional
|
||||
from decimal import Decimal
|
||||
from typing import List
|
||||
|
||||
import brewman.schemas.master as schemas
|
||||
|
||||
@ -34,7 +35,7 @@ def save(
|
||||
data: schemas.AccountIn,
|
||||
db: Session = Depends(get_db),
|
||||
user: UserToken = Security(get_user, scopes=["accounts"]),
|
||||
):
|
||||
) -> schemas.Account:
|
||||
try:
|
||||
item = Account(
|
||||
name=data.name,
|
||||
@ -63,7 +64,7 @@ def update(
|
||||
data: schemas.AccountIn,
|
||||
db: Session = Depends(get_db),
|
||||
user: UserToken = Security(get_user, scopes=["accounts"]),
|
||||
):
|
||||
) -> schemas.Account:
|
||||
try:
|
||||
item: Account = db.query(Account).filter(Account.id == id_).first()
|
||||
if item.is_fixture:
|
||||
@ -92,18 +93,18 @@ def update(
|
||||
raise
|
||||
|
||||
|
||||
@router.delete("/{id_}")
|
||||
@router.delete("/{id_}", response_model=schemas.AccountIn)
|
||||
def delete(
|
||||
id_: uuid.UUID,
|
||||
db: Session = Depends(get_db),
|
||||
user: UserToken = Security(get_user, scopes=["accounts"]),
|
||||
):
|
||||
) -> schemas.AccountIn:
|
||||
account: Account = db.query(Account).filter(Account.id == id_).first()
|
||||
can_delete, reason = account.can_delete("advanced-delete" in user.permissions)
|
||||
if can_delete:
|
||||
delete_with_data(account, db)
|
||||
db.commit()
|
||||
return account_info(None)
|
||||
return account_blank()
|
||||
else:
|
||||
db.rollback()
|
||||
raise HTTPException(
|
||||
@ -112,30 +113,18 @@ def delete(
|
||||
)
|
||||
|
||||
|
||||
@router.get("")
|
||||
@router.get("", response_model=schemas.AccountIn)
|
||||
def show_blank(
|
||||
db: Session = Depends(get_db),
|
||||
user: UserToken = Security(get_user, scopes=["accounts"]),
|
||||
):
|
||||
return account_info(None)
|
||||
) -> schemas.AccountIn:
|
||||
return account_blank()
|
||||
|
||||
|
||||
@router.get("/list")
|
||||
async def show_list(db: Session = Depends(get_db), user: UserToken = Depends(get_user)):
|
||||
@router.get("/list", response_model=List[schemas.Account])
|
||||
async def show_list(db: Session = Depends(get_db), user: UserToken = Depends(get_user)) -> List[schemas.Account]:
|
||||
return [
|
||||
{
|
||||
"id": item.id,
|
||||
"name": item.name,
|
||||
"type": item.type_object.name,
|
||||
"isActive": item.is_active,
|
||||
"isReconcilable": item.is_reconcilable,
|
||||
"isStarred": item.is_starred,
|
||||
"costCentre": {
|
||||
"id": item.cost_centre_id,
|
||||
"name": item.cost_centre.name,
|
||||
},
|
||||
"isFixture": item.is_fixture,
|
||||
}
|
||||
account_info(item)
|
||||
for item in db.query(Account).order_by(Account.type).order_by(Account.name).order_by(Account.code).all()
|
||||
]
|
||||
|
||||
@ -170,17 +159,17 @@ async def show_balance(
|
||||
return {"date": balance(id_, date, db), "total": balance(id_, None, db)}
|
||||
|
||||
|
||||
@router.get("/{id_}")
|
||||
@router.get("/{id_}", response_model=schemas.Account)
|
||||
def show_id(
|
||||
id_: uuid.UUID,
|
||||
db: Session = Depends(get_db),
|
||||
user: UserToken = Security(get_user, scopes=["accounts"]),
|
||||
):
|
||||
) -> schemas.Account:
|
||||
item: Account = db.query(Account).filter(Account.id == id_).first()
|
||||
return account_info(item)
|
||||
|
||||
|
||||
def balance(id_: uuid.UUID, date, db: Session):
|
||||
def balance(id_: uuid.UUID, date, db: Session) -> Decimal:
|
||||
account = db.query(AccountBase).filter(AccountBase.id == id_).first()
|
||||
if not account.type_object.balance_sheet:
|
||||
return 0
|
||||
@ -193,31 +182,32 @@ def balance(id_: uuid.UUID, date, db: Session):
|
||||
return 0 if bal is None else bal
|
||||
|
||||
|
||||
def account_info(item: Optional[Account]):
|
||||
if item is None:
|
||||
return {
|
||||
"code": "(Auto)",
|
||||
"type": AccountType.by_name("Creditors").id,
|
||||
"isActive": True,
|
||||
"isReconcilable": False,
|
||||
"isStarred": False,
|
||||
"costCentre": CostCentre.overall(),
|
||||
}
|
||||
else:
|
||||
return {
|
||||
"id": item.id,
|
||||
"code": item.code,
|
||||
"name": item.name,
|
||||
"type": item.type,
|
||||
"isActive": item.is_active,
|
||||
"isReconcilable": item.is_reconcilable,
|
||||
"isStarred": item.is_starred,
|
||||
"isFixture": item.is_fixture,
|
||||
"costCentre": {
|
||||
"id": item.cost_centre_id,
|
||||
"name": item.cost_centre.name,
|
||||
},
|
||||
}
|
||||
def account_info(item: Account) -> schemas.Account:
|
||||
return schemas.Account(
|
||||
id=item.id,
|
||||
code=item.code,
|
||||
name=item.name,
|
||||
type=item.type,
|
||||
isActive=item.is_active,
|
||||
isReconcilable=item.is_reconcilable,
|
||||
isStarred=item.is_starred,
|
||||
isFixture=item.is_fixture,
|
||||
costCentre=schemas.CostCentreLink(
|
||||
id=item.cost_centre_id,
|
||||
name=item.cost_centre.name,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def account_blank() -> schemas.AccountIn:
|
||||
return schemas.AccountIn(
|
||||
name="",
|
||||
type=AccountType.by_name("Creditors").id,
|
||||
isActive=True,
|
||||
isReconcilable=False,
|
||||
isStarred=False,
|
||||
costCentre=CostCentre.overall(),
|
||||
)
|
||||
|
||||
|
||||
def delete_with_data(account: Account, db: Session):
|
||||
|
@ -1,6 +1,9 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from typing import List
|
||||
|
||||
import brewman.schemas.master as schemas
|
||||
import brewman.schemas.employee as schemas
|
||||
import brewman.schemas.master as master_schemas
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Security, status
|
||||
from sqlalchemy import desc
|
||||
@ -31,7 +34,7 @@ def save(
|
||||
data: schemas.EmployeeIn,
|
||||
db: Session = Depends(get_db),
|
||||
user: UserToken = Security(get_user, scopes=["employees"]),
|
||||
):
|
||||
) -> schemas.Employee:
|
||||
try:
|
||||
item = Employee(
|
||||
name=data.name,
|
||||
@ -45,7 +48,7 @@ def save(
|
||||
leaving_date=None if data.is_active else data.leaving_date,
|
||||
).create(db)
|
||||
db.commit()
|
||||
return employee_info(item.id, db)
|
||||
return employee_info(item)
|
||||
except SQLAlchemyError as e:
|
||||
db.rollback()
|
||||
raise HTTPException(
|
||||
@ -63,7 +66,7 @@ def update(
|
||||
data: schemas.EmployeeIn,
|
||||
db: Session = Depends(get_db),
|
||||
user: UserToken = Security(get_user, scopes=["employees"]),
|
||||
):
|
||||
) -> schemas.Employee:
|
||||
try:
|
||||
item: Employee = db.query(Employee).filter(Employee.id == id_).first()
|
||||
if item.is_fixture:
|
||||
@ -81,7 +84,7 @@ def update(
|
||||
item.is_active = data.is_active
|
||||
item.leaving_date = data.leaving_date
|
||||
db.commit()
|
||||
return employee_info(item.id, db)
|
||||
return employee_info(item)
|
||||
except SQLAlchemyError as e:
|
||||
db.rollback()
|
||||
raise HTTPException(
|
||||
@ -93,18 +96,18 @@ def update(
|
||||
raise
|
||||
|
||||
|
||||
@router.delete("/{id_}")
|
||||
@router.delete("/{id_}", response_model=schemas.EmployeeBlank)
|
||||
def delete(
|
||||
id_: uuid.UUID,
|
||||
db: Session = Depends(get_db),
|
||||
user: UserToken = Security(get_user, scopes=["employees"]),
|
||||
):
|
||||
) -> schemas.EmployeeBlank:
|
||||
employee: Employee = db.query(Employee).filter(Employee.id == id_).first()
|
||||
can_delete, reason = employee.can_delete("advanced-delete" in user.permissions)
|
||||
if can_delete:
|
||||
delete_with_data(employee, db)
|
||||
db.commit()
|
||||
return employee_info(None, db)
|
||||
return employee_blank()
|
||||
else:
|
||||
db.rollback()
|
||||
raise HTTPException(
|
||||
@ -113,33 +116,18 @@ def delete(
|
||||
)
|
||||
|
||||
|
||||
@router.get("")
|
||||
@router.get("", response_model=schemas.EmployeeBlank)
|
||||
def show_blank(
|
||||
db: Session = Depends(get_db),
|
||||
user: UserToken = Security(get_user, scopes=["employees"]),
|
||||
):
|
||||
return employee_info(None, db)
|
||||
) -> schemas.EmployeeBlank:
|
||||
return employee_blank()
|
||||
|
||||
|
||||
@router.get("/list")
|
||||
@router.get("/list", response_model=List[schemas.Employee])
|
||||
async def show_list(db: Session = Depends(get_db), user: UserToken = Depends(get_user)):
|
||||
return [
|
||||
{
|
||||
"id": item.id,
|
||||
"code": item.code,
|
||||
"name": item.name,
|
||||
"designation": item.designation,
|
||||
"salary": item.salary,
|
||||
"points": item.points,
|
||||
"isActive": item.is_active,
|
||||
"costCentre": {
|
||||
"id": item.cost_centre_id,
|
||||
"name": item.cost_centre.name,
|
||||
},
|
||||
"joiningDate": item.joining_date.strftime("%d-%b-%Y"),
|
||||
"leavingDate": "" if item.is_active else item.leaving_date.strftime("%d-%b-%Y"),
|
||||
"isStarred": item.is_starred,
|
||||
}
|
||||
employee_info(item)
|
||||
for item in db.query(Employee)
|
||||
.order_by(desc(Employee.is_active))
|
||||
.order_by(Account.cost_centre_id)
|
||||
@ -174,51 +162,52 @@ async def show_term(
|
||||
return list_
|
||||
|
||||
|
||||
@router.get("/{id_}")
|
||||
@router.get("/{id_}", response_model=schemas.Employee)
|
||||
def show_id(
|
||||
id_: uuid.UUID,
|
||||
db: Session = Depends(get_db),
|
||||
user: UserToken = Security(get_user, scopes=["employees"]),
|
||||
):
|
||||
return employee_info(id_, db)
|
||||
) -> schemas.Employee:
|
||||
item: Employee = db.query(Employee).filter(Employee.id == id_).first()
|
||||
return employee_info(item)
|
||||
|
||||
|
||||
def employee_info(id_, db):
|
||||
if id_ is None:
|
||||
employee = {
|
||||
"code": "(Auto)",
|
||||
"isStarred": False,
|
||||
"isActive": True,
|
||||
"costCentre": CostCentre.overall(),
|
||||
}
|
||||
else:
|
||||
employee = db.query(Employee).filter(Employee.id == id_).first()
|
||||
if employee is None:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="Employee not found",
|
||||
)
|
||||
employee = {
|
||||
"id": employee.id,
|
||||
"code": employee.code,
|
||||
"name": employee.name,
|
||||
"isActive": employee.is_active,
|
||||
"isStarred": employee.is_starred,
|
||||
"designation": employee.designation,
|
||||
"salary": employee.salary,
|
||||
"points": employee.points,
|
||||
"joiningDate": employee.joining_date.strftime("%d-%b-%Y"),
|
||||
"leavingDate": None if employee.is_active else employee.leaving_date.strftime("%d-%b-%Y"),
|
||||
"costCentre": {
|
||||
"id": employee.cost_centre_id,
|
||||
"name": employee.cost_centre.name,
|
||||
},
|
||||
"isFixture": employee.is_fixture,
|
||||
}
|
||||
def employee_info(employee: Employee) -> schemas.Employee:
|
||||
employee = schemas.Employee(
|
||||
id=employee.id,
|
||||
code=employee.code,
|
||||
name=employee.name,
|
||||
isActive=employee.is_active,
|
||||
isStarred=employee.is_starred,
|
||||
designation=employee.designation,
|
||||
salary=employee.salary,
|
||||
points=employee.points,
|
||||
joiningDate=employee.joining_date,
|
||||
leavingDate=None if employee.is_active else employee.leaving_date,
|
||||
costCentre=master_schemas.CostCentreLink(
|
||||
id=employee.cost_centre_id,
|
||||
name=employee.cost_centre.name,
|
||||
),
|
||||
isFixture=employee.is_fixture,
|
||||
)
|
||||
return employee
|
||||
|
||||
|
||||
def delete_with_data(employee, db):
|
||||
def employee_blank() -> schemas.EmployeeBlank:
|
||||
return schemas.EmployeeBlank(
|
||||
name="",
|
||||
isStarred=False,
|
||||
isActive=True,
|
||||
costCentre=CostCentre.overall(),
|
||||
designation="",
|
||||
salary=0,
|
||||
points=0,
|
||||
joiningDate=datetime.today(),
|
||||
leavingDate=None,
|
||||
)
|
||||
|
||||
|
||||
def delete_with_data(employee: Employee, db: Session):
|
||||
suspense_account = db.query(Account).filter(Account.id == Account.suspense()).first()
|
||||
query = (
|
||||
db.query(Voucher)
|
||||
|
59
brewman/brewman/schemas/employee.py
Normal file
59
brewman/brewman/schemas/employee.py
Normal file
@ -0,0 +1,59 @@
|
||||
import uuid
|
||||
from datetime import date, datetime
|
||||
from decimal import Decimal
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import Field, validator
|
||||
|
||||
from brewman.schemas import to_camel
|
||||
from brewman.schemas.master import AccountBase
|
||||
|
||||
|
||||
class EmployeeIn(AccountBase):
|
||||
designation: str
|
||||
salary: int = Field(ge=0)
|
||||
points: Decimal = Field(ge=0, lt=1000, multiple_of=0.01)
|
||||
joining_date: date
|
||||
leaving_date: Optional[date]
|
||||
|
||||
@validator("joining_date", pre=True)
|
||||
def parse_joining_date(cls, value):
|
||||
if isinstance(value, date):
|
||||
return value
|
||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||
|
||||
@validator("leaving_date", pre=True)
|
||||
def parse_leaving_date(cls, value):
|
||||
if isinstance(value, date):
|
||||
return value
|
||||
if value is None:
|
||||
return value
|
||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||
|
||||
@validator("leaving_date")
|
||||
def leaving_date_more_than_joining_date(cls, v, values, **kwargs):
|
||||
if values["is_active"]:
|
||||
return None
|
||||
if v < values["joining_date"]:
|
||||
raise ValueError("Leaving Date cannot be less than Joining Date")
|
||||
return v
|
||||
|
||||
class Config:
|
||||
anystr_strip_whitespace = True
|
||||
alias_generator = to_camel
|
||||
json_encoders = {datetime: lambda v: v.strftime("%d-%b-%Y %H:%M"), date: lambda v: v.strftime("%d-%b-%Y")}
|
||||
|
||||
|
||||
class Employee(EmployeeIn):
|
||||
id_: uuid.UUID
|
||||
code: int
|
||||
is_fixture: bool
|
||||
|
||||
|
||||
class EmployeeBlank(EmployeeIn):
|
||||
name: str
|
||||
|
||||
class Config:
|
||||
anystr_strip_whitespace = True
|
||||
alias_generator = to_camel
|
||||
json_encoders = {datetime: lambda v: v.strftime("%d-%b-%Y %H:%M"), date: lambda v: v.strftime("%d-%b-%Y")}
|
@ -150,39 +150,6 @@ class Account(AccountIn):
|
||||
is_fixture: bool
|
||||
|
||||
|
||||
class EmployeeIn(AccountBase):
|
||||
designation: str
|
||||
salary: int = Field(ge=0)
|
||||
points: Decimal = Field(ge=0, lt=1000, multiple_of=0.01)
|
||||
joining_date: date
|
||||
leaving_date: Optional[date]
|
||||
|
||||
@validator("joining_date", pre=True)
|
||||
def parse_joining_date(cls, value):
|
||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||
|
||||
@validator("leaving_date", pre=True)
|
||||
def parse_leaving_date(cls, value):
|
||||
if value is None or value == "":
|
||||
return None
|
||||
else:
|
||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||
|
||||
@validator("leaving_date")
|
||||
def leaving_date_more_than_joining_date(cls, v, values, **kwargs):
|
||||
if values["is_active"]:
|
||||
return None
|
||||
if v < values["joining_date"]:
|
||||
raise ValueError("Leaving Date cannot be less than Joining Date")
|
||||
return v
|
||||
|
||||
|
||||
class Employee(EmployeeIn):
|
||||
id_: uuid.UUID
|
||||
code: int
|
||||
is_fixture: bool
|
||||
|
||||
|
||||
class DbSetting(BaseModel):
|
||||
id_: uuid.UUID
|
||||
name: str
|
||||
|
@ -60,7 +60,7 @@
|
||||
<!-- Cost Centre Column -->
|
||||
<ng-container matColumnDef="costCentre">
|
||||
<mat-header-cell *matHeaderCellDef mat-sort-header>Cost Centre</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{ row.costCentre }}</mat-cell>
|
||||
<mat-cell *matCellDef="let row">{{ row.costCentre.name }}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
|
||||
|
@ -69,7 +69,7 @@
|
||||
<!-- Department Column -->
|
||||
<ng-container matColumnDef="department">
|
||||
<mat-header-cell *matHeaderCellDef>Department</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{ row.costCentre }}</mat-cell>
|
||||
<mat-cell *matCellDef="let row">{{ row.costCentre.name }}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- JoiningDate Column -->
|
||||
|
Loading…
x
Reference in New Issue
Block a user