removed accidentally committed file.

voucher.py is now formatted with standard width of 120 instead of 88
will now use that as the default in the future
This commit is contained in:
2020-05-31 14:26:50 +05:30
parent 972ee59837
commit 6f5d9af6e3
3 changed files with 26 additions and 442 deletions

View File

@ -51,9 +51,7 @@ def get_db() -> Session:
@router.post("/post-voucher/{id_}", response_model=output.Voucher)
def post_voucher(
id_: uuid.UUID,
db: Session = Depends(get_db),
user: UserToken = Security(get_user, scopes=["post-vouchers"]),
id_: uuid.UUID, db: Session = Depends(get_db), user: UserToken = Security(get_user, scopes=["post-vouchers"]),
):
try:
voucher: Voucher = db.query(Voucher).filter(Voucher.id == id_).first()
@ -70,8 +68,7 @@ def post_voucher(
except Exception:
db.rollback()
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail=traceback.format_exc(),
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=traceback.format_exc(),
)
@ -89,15 +86,14 @@ def check_delete_permissions(voucher: Voucher, user: UserToken):
)
elif voucher_type not in user.permissions:
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN, detail=f"You are not allowed ({VoucherType.by_id(voucher.type).name}) vouchers",
status_code=status.HTTP_403_FORBIDDEN,
detail=f"You are not allowed ({VoucherType.by_id(voucher.type).name}) vouchers",
)
@router.delete("/delete/{id_}")
def delete_voucher(
id_: uuid.UUID,
db: Session = Depends(get_db),
user: UserToken = Security(get_user),
id_: uuid.UUID, db: Session = Depends(get_db), user: UserToken = Security(get_user),
):
voucher: Voucher = db.query(Voucher).filter(Voucher.id == id_).first()
images = db.query(DbImage).filter(DbImage.resource_id == voucher.id).all()
@ -139,9 +135,7 @@ def delete_voucher(
.scalar()
)
if uses > 0:
raise ValueError(
f"{item.product.name} has been issued and cannot be deleted"
)
raise ValueError(f"{item.product.name} has been issued and cannot be deleted")
batches_to_delete.append(item.batch)
elif voucher.type == VoucherType.by_name("Purchase Return").id:
for item in voucher.inventories:
@ -216,9 +210,7 @@ def voucher_info(voucher, db):
}
)
for item in voucher.incentives:
employee = (
db.query(Employee).filter(Employee.id == item.journal.account_id).first()
)
employee = db.query(Employee).filter(Employee.id == item.journal.account_id).first()
json_voucher["incentives"].append(
{
"employeeId": item.journal.account_id,
@ -230,9 +222,7 @@ def voucher_info(voucher, db):
}
)
if len(json_voucher["incentives"]) > 0:
json_voucher["incentive"] = next(
x.amount for x in voucher.journals if x.account_id == Account.incentive_id()
)
json_voucher["incentive"] = next(x.amount for x in voucher.journals if x.account_id == Account.incentive_id())
for item in voucher.inventories:
text = f"{item.product.name} ({item.product.units}) {item.batch.quantity_remaining:.2f}@{item.batch.rate:.2f} from {item.batch.name.strftime('%d-%b-%Y')}"
json_voucher["inventories"].append(
@ -256,16 +246,19 @@ def voucher_info(voucher, db):
"tax": item.batch.tax,
"discount": item.batch.discount,
"rate": item.batch.rate,
"product": {
"id": item.batch.product.id,
"name": item.batch.product.full_name,
},
"product": {"id": item.batch.product.id, "name": item.batch.product.full_name,},
},
}
)
images = db.query(DbImage).filter(DbImage.resource_id == voucher.id).all()
for image in images:
json_voucher["files"].append({"id": image.id, "resized": f"/db-image/{image.id}/resized", "thumbnail": f"/db-image/{image.id}/thumbnail"})
json_voucher["files"].append(
{
"id": image.id,
"resized": f"/db-image/{image.id}/resized",
"thumbnail": f"/db-image/{image.id}/thumbnail",
}
)
return json_voucher
@ -290,11 +283,7 @@ def blank_voucher(info, db):
elif type_ == "Payment":
account = None
if info and "account" in info and info["account"]:
account = (
db.query(AccountBase)
.filter(AccountBase.id == uuid.UUID(info["account"]))
.first()
)
account = db.query(AccountBase).filter(AccountBase.id == uuid.UUID(info["account"])).first()
if account is not None:
account = {"id": account.id, "name": account.name}
else:
@ -303,11 +292,7 @@ def blank_voucher(info, db):
elif type_ == "Receipt":
account = None
if info and "account" in info and info["account"]:
account = (
db.query(AccountBase)
.filter(AccountBase.id == uuid.UUID(info["account"]))
.first()
)
account = db.query(AccountBase).filter(AccountBase.id == uuid.UUID(info["account"])).first()
if account is not None:
account = {"id": account.id, "name": account.name}
else:
@ -317,9 +302,7 @@ def blank_voucher(info, db):
json_voucher["vendor"] = AccountBase.local_purchase()
elif type_ == "Purchase Return":
json_voucher["journals"].append(
{"account": AccountBase.local_purchase(), "amount": 0, "debit": 1}
)
json_voucher["journals"].append({"account": AccountBase.local_purchase(), "amount": 0, "debit": 1})
elif type_ == "Issue":
if "source" in info:
json_voucher["source"] = {"id": info["source"]}
@ -332,9 +315,7 @@ def blank_voucher(info, db):
elif type_ == "Employee Benefit":
json_voucher["employeeBenefits"] = []
elif type_ == "Incentive":
json_voucher["incentives"], json_voucher["incentive"] = incentive_employees(
info["date"], db
)
json_voucher["incentives"], json_voucher["incentive"] = incentive_employees(info["date"], db)
else:
raise ValueError(f'Voucher of type "{type_}" does not exist.')
json_voucher["files"] = []
@ -390,22 +371,12 @@ def incentive_employees(date_, db: Session):
def check_voucher_lock_info(voucher_date: Optional[date], data_date: date, db: Session):
start, finish = get_lock_info(db)
if (
start is not None
and start > data_date
or voucher_date is not None
and start > voucher_date
):
if start is not None and start > data_date or voucher_date is not None and start > voucher_date:
raise HTTPException(
status_code=status.HTTP_423_LOCKED,
detail=f"Vouchers before {start.strftime('%d-%b-%Y')} have been locked.",
)
elif (
finish is not None
and finish < data_date
or voucher_date is not None
and finish < voucher_date
):
elif finish is not None and finish < data_date or voucher_date is not None and finish < voucher_date:
raise HTTPException(
status_code=status.HTTP_423_LOCKED,
detail=f"Vouchers after {finish.strftime('%d-%b-%Y')} have been locked.",
@ -425,14 +396,9 @@ def check_voucher_lock_info(voucher_date: Optional[date], data_date: date, db: S
def check_voucher_edit_allowed(voucher: Voucher, user: UserToken):
if voucher.posted and "edit-posted-vouchers" not in user.permissions:
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail="You are not allowed to edit posted vouchers",
status_code=status.HTTP_403_FORBIDDEN, detail="You are not allowed to edit posted vouchers",
)
elif (
voucher.user_id != user.id_
and "edit-other-user's-vouchers" not in user.permissions
):
elif voucher.user_id != user.id_ and "edit-other-user's-vouchers" not in user.permissions:
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail="You are not allowed to edit other user's vouchers",
status_code=status.HTTP_403_FORBIDDEN, detail="You are not allowed to edit other user's vouchers",
)