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

@@ -50,25 +50,13 @@ class LayingClient(db.Model):
def serialize(self):
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(LayingClient, "before_insert", calculate_laying_total)