regular exp updated on model
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
from app import db
|
||||
from datetime import datetime
|
||||
from sqlalchemy import event
|
||||
|
||||
from app.utils.regex_utils import RegularExpression
|
||||
|
||||
class Laying(db.Model):
|
||||
@@ -48,24 +47,12 @@ class Laying(db.Model):
|
||||
return {c.name: getattr(self, c.name) for c in self.__table__.columns}
|
||||
|
||||
|
||||
# def sum_laying_fields():
|
||||
# return [
|
||||
# "pipe_150_mm", "pipe_200_mm", "pipe_250_mm",
|
||||
# "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 RegularExpression.PIPE_MM_PATTERN.match(column.name):
|
||||
total += getattr(target, column.name) or 0
|
||||
|
||||
target.Total = total
|
||||
|
||||
event.listen(Laying, "before_insert", calculate_laying_total)
|
||||
|
||||
Reference in New Issue
Block a user