create regular exp added and change model

This commit is contained in:
2026-03-17 15:35:52 +05:30
parent c5b3e7bd60
commit 96a3a79731
9 changed files with 97 additions and 186 deletions

View File

@@ -1,9 +1,7 @@
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$")
from app.utils.regex_utils import RegularExpression
class LayingClient(db.Model):
__tablename__ = "laying_client"
@@ -53,13 +51,13 @@ class LayingClient(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"
]
# 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
@@ -68,7 +66,7 @@ def calculate_laying_total(mapper, connection, target):
total = 0
for column in target.__table__.columns:
if PIPE_MM_PATTERN.match(column.name):
if RegularExpression.PIPE_MM_PATTERN.match(column.name):
total += getattr(target, column.name) or 0
target.Total = total