regular exp updated on model

This commit is contained in:
2026-03-17 18:02:28 +05:30
parent 96a3a79731
commit 5ddfb1f440
11 changed files with 25 additions and 135 deletions

View File

@@ -1,6 +1,7 @@
from app import db
from datetime import datetime
from sqlalchemy import event
from app.utils.regex_utils import RegularExpression
class TrenchExcavationClient(db.Model):
__tablename__ = "tr_ex_client"
@@ -85,16 +86,13 @@ class TrenchExcavationClient(db.Model):
return {c.name: getattr(self, c.name) for c in self.__table__.columns}
# ==========================================
# AUTO CALCULATE GRAND TOTAL
# ==========================================
# AUTO TOTAL USING REGEX
def calculate_trench_client_total(mapper, connection, target):
total = 0
for column in target.__table__.columns:
if column.name.endswith("_total"):
if RegularExpression.STR_TOTAL_PATTERN.match(column.name):
total += getattr(target, column.name) or 0
target.Total = total
event.listen(TrenchExcavationClient, "before_insert", calculate_trench_client_total)
event.listen(TrenchExcavationClient, "before_update", calculate_trench_client_total)