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:
Amritanshu Agrawal 2021-01-25 12:48:36 +05:30
parent d7f635b7b6
commit f2df28ca9c
5 changed files with 28 additions and 13 deletions

View File

@ -13,7 +13,6 @@ from sqlalchemy.orm import Session, joinedload_all
from ..core.security import get_current_active_user as get_user
from ..db.session import SessionLocal
from ..models.account import Account
from ..models.account_base import AccountBase
from ..models.cost_centre import CostCentre
from ..models.employee import Employee
from ..models.journal import Journal
@ -150,7 +149,7 @@ async def show_term(
current_user: UserToken = Depends(get_user),
):
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(
{
"id": item.id,

View File

@ -8,7 +8,7 @@ import brewman.schemas.input as schema_in
import brewman.schemas.voucher as output
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.orm import Session
@ -133,7 +133,7 @@ def update_route(
update_incentives(item, employees, point_value, db)
check_journals_are_valid(item)
db.commit()
set_date(request.session, data.date_)
set_date(data.date_.strftime("%d-%b-%Y"), request.session)
return voucher_info(item, db)
except SQLAlchemyError as e:
db.rollback()
@ -254,9 +254,17 @@ def balance(date_: date, voucher_id: Optional[uuid.UUID], db: Session):
amount = (
db.query(func.sum(Journal.amount * Journal.debit))
.join(Journal.voucher)
.filter(Voucher.date <= date_)
.filter(Voucher.type != VoucherType.by_name("Issue").id)
.filter(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:
amount = amount.filter(Voucher.id != voucher_id)

View File

@ -98,7 +98,7 @@ async def login_for_access_token(
data={
"sub": user.name,
"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),
"lockedOut": user.locked_out,
"ver": __version__.__version__,

View File

@ -7,7 +7,7 @@ from typing import Optional
import brewman.schemas.voucher as output
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.orm import Session
@ -377,9 +377,17 @@ def incentive_employees(date_, db: Session):
amount = (
db.query(func.sum(Journal.amount * Journal.debit))
.join(Journal.voucher)
.filter(Voucher.date < finish_date)
.filter(Voucher.type != VoucherType.by_name("Issue").id)
.filter(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()
)
amount = 0 if amount is None else amount * Decimal(0.9) * -1

View File

@ -3,7 +3,7 @@ from decimal import Decimal
from typing import List, Optional
from brewman.schemas import to_camel
from pydantic import Field, validator
from pydantic import validator
from pydantic.main import BaseModel