Fix: Incentive takes into account the date chosen
Fix: Employee query was querying AccountBase and errored out as it did not have the designation column Fix: Incentive update set_date was wrong Fix: Incentive amount takes into account the current date but not any incentive voucher for the date
This commit is contained in:
@ -13,7 +13,6 @@ from sqlalchemy.orm import Session, joinedload_all
|
|||||||
from ..core.security import get_current_active_user as get_user
|
from ..core.security import get_current_active_user as get_user
|
||||||
from ..db.session import SessionLocal
|
from ..db.session import SessionLocal
|
||||||
from ..models.account import Account
|
from ..models.account import Account
|
||||||
from ..models.account_base import AccountBase
|
|
||||||
from ..models.cost_centre import CostCentre
|
from ..models.cost_centre import CostCentre
|
||||||
from ..models.employee import Employee
|
from ..models.employee import Employee
|
||||||
from ..models.journal import Journal
|
from ..models.journal import Journal
|
||||||
@ -150,7 +149,7 @@ async def show_term(
|
|||||||
current_user: UserToken = Depends(get_user),
|
current_user: UserToken = Depends(get_user),
|
||||||
):
|
):
|
||||||
list_ = []
|
list_ = []
|
||||||
for index, item in enumerate(AccountBase.query(q=q, type_=10, db=db)):
|
for index, item in enumerate(Employee.query(q=q, type_=10, db=db)):
|
||||||
list_.append(
|
list_.append(
|
||||||
{
|
{
|
||||||
"id": item.id,
|
"id": item.id,
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import brewman.schemas.input as schema_in
|
|||||||
import brewman.schemas.voucher as output
|
import brewman.schemas.voucher as output
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, HTTPException, Request, Security, status
|
from fastapi import APIRouter, Depends, HTTPException, Request, Security, status
|
||||||
from sqlalchemy import func, or_
|
from sqlalchemy import and_, func, or_
|
||||||
from sqlalchemy.exc import SQLAlchemyError
|
from sqlalchemy.exc import SQLAlchemyError
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ def update_route(
|
|||||||
update_incentives(item, employees, point_value, db)
|
update_incentives(item, employees, point_value, db)
|
||||||
check_journals_are_valid(item)
|
check_journals_are_valid(item)
|
||||||
db.commit()
|
db.commit()
|
||||||
set_date(request.session, data.date_)
|
set_date(data.date_.strftime("%d-%b-%Y"), request.session)
|
||||||
return voucher_info(item, db)
|
return voucher_info(item, db)
|
||||||
except SQLAlchemyError as e:
|
except SQLAlchemyError as e:
|
||||||
db.rollback()
|
db.rollback()
|
||||||
@ -254,9 +254,17 @@ def balance(date_: date, voucher_id: Optional[uuid.UUID], db: Session):
|
|||||||
amount = (
|
amount = (
|
||||||
db.query(func.sum(Journal.amount * Journal.debit))
|
db.query(func.sum(Journal.amount * Journal.debit))
|
||||||
.join(Journal.voucher)
|
.join(Journal.voucher)
|
||||||
.filter(Voucher.date <= date_)
|
.filter(
|
||||||
.filter(Voucher.type != VoucherType.by_name("Issue").id)
|
Journal.account_id == Account.incentive_id(),
|
||||||
.filter(Journal.account_id == Account.incentive_id())
|
Voucher.type != VoucherType.by_name("Issue").id,
|
||||||
|
or_(
|
||||||
|
Voucher.date <= date_,
|
||||||
|
and_(
|
||||||
|
Voucher.date == date_,
|
||||||
|
Voucher.type != VoucherType.by_name("Incentive").id,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
)
|
)
|
||||||
if voucher_id is not None:
|
if voucher_id is not None:
|
||||||
amount = amount.filter(Voucher.id != voucher_id)
|
amount = amount.filter(Voucher.id != voucher_id)
|
||||||
|
|||||||
@ -98,7 +98,7 @@ async def login_for_access_token(
|
|||||||
data={
|
data={
|
||||||
"sub": user.name,
|
"sub": user.name,
|
||||||
"scopes": ["authenticated"]
|
"scopes": ["authenticated"]
|
||||||
+ list(set([p.name.replace(" ", "-").lower() for r in user.roles for p in r.permissions])),
|
+ list(set([p.name.replace(" ", "-").lower() for r in user.roles for p in r.permissions])), # noqa: W503
|
||||||
"userId": str(user.id),
|
"userId": str(user.id),
|
||||||
"lockedOut": user.locked_out,
|
"lockedOut": user.locked_out,
|
||||||
"ver": __version__.__version__,
|
"ver": __version__.__version__,
|
||||||
|
|||||||
@ -7,7 +7,7 @@ from typing import Optional
|
|||||||
import brewman.schemas.voucher as output
|
import brewman.schemas.voucher as output
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, HTTPException, Security, status
|
from fastapi import APIRouter, Depends, HTTPException, Security, status
|
||||||
from sqlalchemy import func, or_
|
from sqlalchemy import and_, func, or_
|
||||||
from sqlalchemy.exc import SQLAlchemyError
|
from sqlalchemy.exc import SQLAlchemyError
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
@ -377,9 +377,17 @@ def incentive_employees(date_, db: Session):
|
|||||||
amount = (
|
amount = (
|
||||||
db.query(func.sum(Journal.amount * Journal.debit))
|
db.query(func.sum(Journal.amount * Journal.debit))
|
||||||
.join(Journal.voucher)
|
.join(Journal.voucher)
|
||||||
.filter(Voucher.date < finish_date)
|
.filter(
|
||||||
.filter(Voucher.type != VoucherType.by_name("Issue").id)
|
Journal.account_id == Account.incentive_id(),
|
||||||
.filter(Journal.account_id == Account.incentive_id())
|
Voucher.type != VoucherType.by_name("Issue").id,
|
||||||
|
or_(
|
||||||
|
Voucher.date <= finish_date,
|
||||||
|
and_(
|
||||||
|
Voucher.date == finish_date,
|
||||||
|
Voucher.type != VoucherType.by_name("Incentive").id,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
.scalar()
|
.scalar()
|
||||||
)
|
)
|
||||||
amount = 0 if amount is None else amount * Decimal(0.9) * -1
|
amount = 0 if amount is None else amount * Decimal(0.9) * -1
|
||||||
|
|||||||
@ -3,7 +3,7 @@ from decimal import Decimal
|
|||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
from brewman.schemas import to_camel
|
from brewman.schemas import to_camel
|
||||||
from pydantic import Field, validator
|
from pydantic import validator
|
||||||
from pydantic.main import BaseModel
|
from pydantic.main import BaseModel
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user