Fix: The lock was not working because:
1. The Account Types sent were sqlqueries and not integer literals 2. Voucher Types and Account Types were being compared to VoucherTypesSelected and AccountTypesSelected objects and not their ids.
This commit is contained in:
parent
dbf0ecf0d8
commit
637932c67c
@ -46,20 +46,16 @@ def get_lock_info(
|
||||
data = sorted(data, key=lambda d: d["index"], reverse=True)
|
||||
for it in data:
|
||||
li: LockInformation = LockInformation(
|
||||
voucherTypes=[
|
||||
VoucherTypesSelected(id=vt["id_"], name=VoucherType.by_id(vt["id_"]).name) for vt in it["voucher_types"]
|
||||
],
|
||||
accountTypes=[
|
||||
AccountTypesSelected(id=at["id_"], name=AccountType.by_id(at["id_"]).name) for at in it["account_types"]
|
||||
],
|
||||
voucherTypes=[VoucherTypesSelected(id=vt["id_"], name=vt["name"]) for vt in it["voucher_types"]],
|
||||
accountTypes=[AccountTypesSelected(id=at["id_"], name=at["name"]) for at in it["account_types"]],
|
||||
start=LockDate(days=it["start"]["days"], date=it["start"]["date_"]),
|
||||
finish=LockDate(days=it["finish"]["days"], date=it["finish"]["date_"]),
|
||||
index=it["index"],
|
||||
)
|
||||
# Data format
|
||||
if len(li.voucher_types) != 0 and voucher_type not in li.voucher_types:
|
||||
if len(li.voucher_types) != 0 and voucher_type not in [vt.id_ for vt in li.voucher_types]:
|
||||
continue
|
||||
if len(li.account_types) != 0 and len(set(account_types) & set(li.account_types)) == 0:
|
||||
if len(li.account_types) != 0 and len(set(account_types) & set([at.id_ for at in li.account_types])) == 0:
|
||||
continue
|
||||
|
||||
if li.start.days is not None:
|
||||
|
@ -61,8 +61,14 @@ def save_route(
|
||||
|
||||
|
||||
def save(data: schema_in.EmployeeBenefitIn, date_: date, user: UserToken, db: Session) -> Voucher:
|
||||
account_types = db.execute(
|
||||
select(distinct(AccountBase.type)).where(AccountBase.id.in_([dj.employee.id_ for dj in data.employee_benefits]))
|
||||
account_types = (
|
||||
db.execute(
|
||||
select(distinct(AccountBase.type)).where(
|
||||
AccountBase.id.in_([dj.employee.id_ for dj in data.employee_benefits])
|
||||
)
|
||||
)
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
allowed, message = get_lock_info([data.date_], VoucherType.by_name(data.type_), account_types, db)
|
||||
if not allowed:
|
||||
@ -174,13 +180,17 @@ def update_route(
|
||||
|
||||
def update_voucher(id_: uuid.UUID, data: schema_in.EmployeeBenefitIn, user: UserToken, db: Session) -> Voucher:
|
||||
voucher: Voucher = db.execute(select(Voucher).where(Voucher.id == id_)).scalar_one()
|
||||
account_types = db.execute(
|
||||
account_types = (
|
||||
db.execute(
|
||||
select(distinct(AccountBase.type)).where(
|
||||
AccountBase.id.in_(
|
||||
[dj.employee.id_ for dj in data.employee_benefits] + [vj.account_id for vj in voucher.journals]
|
||||
)
|
||||
)
|
||||
)
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
allowed, message = get_lock_info([voucher.date, data.date_], voucher.type, account_types, db)
|
||||
if not allowed:
|
||||
raise HTTPException(
|
||||
|
@ -61,9 +61,13 @@ def save_route(
|
||||
|
||||
|
||||
def save(data: schema_in.IncentiveIn, user: UserToken, db: Session) -> Voucher:
|
||||
account_types = db.execute(
|
||||
account_types = (
|
||||
db.execute(
|
||||
select(distinct(AccountBase.type)).where(AccountBase.id.in_([dj.employee_id for dj in data.incentives]))
|
||||
)
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
allowed, message = get_lock_info([data.date_], VoucherType.by_name(data.type_), account_types, db)
|
||||
if not allowed:
|
||||
raise HTTPException(
|
||||
@ -137,11 +141,17 @@ def update_route(
|
||||
|
||||
def update_voucher(id_: uuid.UUID, data: schema_in.IncentiveIn, user: UserToken, db: Session) -> Voucher:
|
||||
voucher: Voucher = db.execute(select(Voucher).where(Voucher.id == id_)).scalar_one()
|
||||
account_types = db.execute(
|
||||
account_types = (
|
||||
db.execute(
|
||||
select(distinct(AccountBase.type)).where(
|
||||
AccountBase.id.in_([dj.employee_id for dj in data.incentives] + [vj.account_id for vj in voucher.journals])
|
||||
AccountBase.id.in_(
|
||||
[dj.employee_id for dj in data.incentives] + [vj.account_id for vj in voucher.journals]
|
||||
)
|
||||
)
|
||||
)
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
allowed, message = get_lock_info([voucher.date, data.date_], voucher.type, account_types, db)
|
||||
if not allowed:
|
||||
raise HTTPException(
|
||||
|
@ -63,7 +63,9 @@ def save_route(
|
||||
|
||||
def save(data: schema_in.IssueIn, user: UserToken, db: Session) -> (Voucher, Optional[bool]):
|
||||
product_accounts = select(Product.account_id).where(Product.id.in_([i.product.id_ for i in data.inventories]))
|
||||
account_types = db.execute(select(distinct(AccountBase.type)).where(AccountBase.id.in_(product_accounts)))
|
||||
account_types = (
|
||||
db.execute(select(distinct(AccountBase.type)).where(AccountBase.id.in_(product_accounts))).scalars().all()
|
||||
)
|
||||
allowed, message = get_lock_info([data.date_], VoucherType.by_name(data.type_), account_types, db)
|
||||
if not allowed:
|
||||
raise HTTPException(
|
||||
@ -189,7 +191,8 @@ def update_route(
|
||||
def update_voucher(id_: uuid.UUID, data: schema_in.IssueIn, user: UserToken, db: Session) -> (Voucher, Optional[bool]):
|
||||
voucher: Voucher = db.execute(select(Voucher).where(Voucher.id == id_)).scalar_one()
|
||||
product_accounts = select(Product.account_id).where(Product.id.in_([i.product.id_ for i in data.inventories]))
|
||||
account_types = db.execute(
|
||||
account_types = (
|
||||
db.execute(
|
||||
select(distinct(AccountBase.type)).where(
|
||||
or_(
|
||||
AccountBase.id.in_([vj.account_id for vj in voucher.journals]),
|
||||
@ -197,6 +200,9 @@ def update_voucher(id_: uuid.UUID, data: schema_in.IssueIn, user: UserToken, db:
|
||||
)
|
||||
)
|
||||
)
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
allowed, message = get_lock_info([voucher.date, data.date_], voucher.type, account_types, db)
|
||||
if not allowed:
|
||||
raise HTTPException(
|
||||
|
@ -54,9 +54,13 @@ def save_route(
|
||||
|
||||
|
||||
def save(data: schema_in.JournalIn, user: UserToken, db: Session) -> Voucher:
|
||||
account_types = db.execute(
|
||||
account_types = (
|
||||
db.execute(
|
||||
select(distinct(AccountBase.type)).where(AccountBase.id.in_([dj.account.id_ for dj in data.journals]))
|
||||
)
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
allowed, message = get_lock_info([data.date_], VoucherType.by_name(data.type_), account_types, db)
|
||||
if not allowed:
|
||||
raise HTTPException(
|
||||
@ -114,11 +118,17 @@ def update_route(
|
||||
|
||||
def update_voucher(id_: uuid.UUID, data: schema_in.JournalIn, user: UserToken, db: Session) -> Voucher:
|
||||
voucher: Voucher = db.execute(select(Voucher).where(Voucher.id == id_)).scalar_one()
|
||||
account_types = db.execute(
|
||||
account_types = (
|
||||
db.execute(
|
||||
select(distinct(AccountBase.type)).where(
|
||||
AccountBase.id.in_([dj.account.id_ for dj in data.journals] + [vj.account_id for vj in voucher.journals])
|
||||
AccountBase.id.in_(
|
||||
[dj.account.id_ for dj in data.journals] + [vj.account_id for vj in voucher.journals]
|
||||
)
|
||||
)
|
||||
)
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
allowed, message = get_lock_info([voucher.date, data.date_], voucher.type, account_types, db)
|
||||
if not allowed:
|
||||
raise HTTPException(
|
||||
|
@ -62,7 +62,8 @@ def save_route(
|
||||
|
||||
def save(data: schema_in.PurchaseIn, user: UserToken, db: Session) -> Voucher:
|
||||
product_accounts = select(Product.account_id).where(Product.id.in_([i.product.id_ for i in data.inventories]))
|
||||
account_types = db.execute(
|
||||
account_types = (
|
||||
db.execute(
|
||||
select(distinct(AccountBase.type)).where(
|
||||
or_(
|
||||
AccountBase.id == data.vendor.id_,
|
||||
@ -70,6 +71,9 @@ def save(data: schema_in.PurchaseIn, user: UserToken, db: Session) -> Voucher:
|
||||
)
|
||||
)
|
||||
)
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
allowed, message = get_lock_info([data.date_], VoucherType.by_name(data.type_), account_types, db)
|
||||
if not allowed:
|
||||
raise HTTPException(
|
||||
@ -170,7 +174,8 @@ def update_route(
|
||||
def update_voucher(id_: uuid.UUID, data: schema_in.PurchaseIn, user: UserToken, db: Session) -> Voucher:
|
||||
voucher: Voucher = db.execute(select(Voucher).where(Voucher.id == id_)).scalar_one()
|
||||
product_accounts = select(Product.account_id).where(Product.id.in_([i.product.id_ for i in data.inventories]))
|
||||
account_types = db.execute(
|
||||
account_types = (
|
||||
db.execute(
|
||||
select(distinct(AccountBase.type)).where(
|
||||
or_(
|
||||
AccountBase.id.in_([data.vendor.id_] + [vj.account_id for vj in voucher.journals]),
|
||||
@ -178,6 +183,9 @@ def update_voucher(id_: uuid.UUID, data: schema_in.PurchaseIn, user: UserToken,
|
||||
)
|
||||
)
|
||||
)
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
allowed, message = get_lock_info([voucher.date, data.date_], voucher.type, account_types, db)
|
||||
if not allowed:
|
||||
raise HTTPException(
|
||||
|
@ -62,7 +62,8 @@ def save_route(
|
||||
|
||||
def save(data: schema_in.PurchaseIn, user: UserToken, db: Session) -> Voucher:
|
||||
product_accounts = select(Product.account_id).where(Product.id.in_([i.product.id_ for i in data.inventories]))
|
||||
account_types = db.execute(
|
||||
account_types = (
|
||||
db.execute(
|
||||
select(distinct(AccountBase.type)).where(
|
||||
or_(
|
||||
AccountBase.id == data.vendor.id_,
|
||||
@ -70,6 +71,9 @@ def save(data: schema_in.PurchaseIn, user: UserToken, db: Session) -> Voucher:
|
||||
)
|
||||
)
|
||||
)
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
allowed, message = get_lock_info([data.date_], VoucherType.by_name(data.type_), account_types, db)
|
||||
if not allowed:
|
||||
raise HTTPException(
|
||||
@ -177,7 +181,8 @@ def update_route(
|
||||
def update_voucher(id_: uuid.UUID, data: schema_in.PurchaseIn, user: UserToken, db: Session) -> Voucher:
|
||||
voucher: Voucher = db.execute(select(Voucher).where(Voucher.id == id_)).scalar_one()
|
||||
product_accounts = select(Product.account_id).where(Product.id.in_([i.product.id_ for i in data.inventories]))
|
||||
account_types = db.execute(
|
||||
account_types = (
|
||||
db.execute(
|
||||
select(distinct(AccountBase.type)).where(
|
||||
or_(
|
||||
AccountBase.id.in_([data.vendor.id_] + [vj.account_id for vj in voucher.journals]),
|
||||
@ -185,6 +190,9 @@ def update_voucher(id_: uuid.UUID, data: schema_in.PurchaseIn, user: UserToken,
|
||||
)
|
||||
)
|
||||
)
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
allowed, message = get_lock_info([voucher.date, data.date_], voucher.type, account_types, db)
|
||||
if not allowed:
|
||||
raise HTTPException(
|
||||
|
@ -41,8 +41,14 @@ def post_voucher(
|
||||
try:
|
||||
with SessionFuture() as db:
|
||||
voucher: Voucher = db.execute(select(Voucher).where(Voucher.id == id_)).scalar_one()
|
||||
account_types = db.execute(
|
||||
select(distinct(AccountBase.type)).where(AccountBase.id.in_([vj.account_id for vj in voucher.journals]))
|
||||
account_types = (
|
||||
db.execute(
|
||||
select(distinct(AccountBase.type)).where(
|
||||
AccountBase.id.in_([vj.account_id for vj in voucher.journals])
|
||||
)
|
||||
)
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
allowed, message = get_lock_info([voucher.date], voucher.type, account_types, db)
|
||||
if not allowed:
|
||||
@ -91,9 +97,13 @@ def delete_voucher(
|
||||
voucher: Voucher = db.execute(select(Voucher).where(Voucher.id == id_)).scalar_one()
|
||||
images = db.execute(select(DbImage).where(DbImage.resource_id == voucher.id)).scalars().all()
|
||||
check_delete_permissions(voucher, user)
|
||||
account_types = db.execute(
|
||||
account_types = (
|
||||
db.execute(
|
||||
select(distinct(AccountBase.type)).where(AccountBase.id.in_([vj.account_id for vj in voucher.journals]))
|
||||
)
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
allowed, message = get_lock_info([voucher.date], voucher.type, account_types, db)
|
||||
if not allowed:
|
||||
raise HTTPException(
|
||||
|
Loading…
x
Reference in New Issue
Block a user