change of comparison report of 4 model update
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
from app import db
|
||||
from datetime import datetime
|
||||
from sqlalchemy import event
|
||||
import re
|
||||
# REGEX PATTERN
|
||||
PIPE_MM_PATTERN = re.compile(r"^pipe_\d+_mm$")
|
||||
|
||||
class LayingClient(db.Model):
|
||||
__tablename__ = "laying_client"
|
||||
@@ -55,4 +59,19 @@ class LayingClient(db.Model):
|
||||
"pipe_300_mm", "pipe_350_mm", "pipe_400_mm",
|
||||
"pipe_450_mm", "pipe_500_mm", "pipe_600_mm",
|
||||
"pipe_700_mm", "pipe_900_mm", "pipe_1200_mm"
|
||||
]
|
||||
]
|
||||
|
||||
# ===============================
|
||||
# AUTO TOTAL USING REGEX
|
||||
# ===============================
|
||||
def calculate_laying_total(mapper, connection, target):
|
||||
total = 0
|
||||
|
||||
for column in target.__table__.columns:
|
||||
if PIPE_MM_PATTERN.match(column.name):
|
||||
total += getattr(target, column.name) or 0
|
||||
|
||||
target.Total = total
|
||||
|
||||
event.listen(LayingClient, "before_insert", calculate_laying_total)
|
||||
event.listen(LayingClient, "before_update", calculate_laying_total)
|
||||
Reference in New Issue
Block a user