Revised the code to find the next number in the populate_obj method of the AccountForm form.
This commit is contained in:
parent
d368c5e062
commit
9f9c40c30e
@ -68,10 +68,10 @@ class AccountForm(FlaskForm):
|
|||||||
obj.id = new_id(Account)
|
obj.id = new_id(Account)
|
||||||
obj.base_code = self.base_code.data
|
obj.base_code = self.base_code.data
|
||||||
if prev_base_code != self.base_code.data:
|
if prev_base_code != self.base_code.data:
|
||||||
last_same_base: Account = Account.query\
|
max_no: int = db.session.scalars(
|
||||||
.filter(Account.base_code == self.base_code.data)\
|
sa.select(sa.func.max(Account.no))
|
||||||
.order_by(Account.base_code.desc()).first()
|
.filter(Account.base_code == self.base_code.data)).one()
|
||||||
obj.no = 1 if last_same_base is None else last_same_base.no + 1
|
obj.no = 1 if max_no is None else max_no + 1
|
||||||
obj.title = self.title.data
|
obj.title = self.title.data
|
||||||
obj.is_offset_needed = self.is_offset_needed.data
|
obj.is_offset_needed = self.is_offset_needed.data
|
||||||
if is_new:
|
if is_new:
|
||||||
|
Loading…
Reference in New Issue
Block a user