regular exp updated on model
This commit is contained in:
@@ -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)
|
||||
Reference in New Issue
Block a user