updated and cleaned

This commit is contained in:
2025-03-24 13:36:14 +03:00
parent 713730420c
commit 22876d250d
26 changed files with 161 additions and 98 deletions

View File

@@ -25,6 +25,7 @@ ADD /BankServices/RoutineEmailService /
ADD /Configs /Configs
ADD /Schemas /Schemas
ADD /Commons /Commons
ADD /BankServices/ServiceDepends/template_accounts.html /templates/template_accounts.html
ADD /Services/MongoService /Services/MongoService
ADD /Services/PostgresService /Services/PostgresService

View File

@@ -6,11 +6,24 @@ from jinja2 import Environment, FileSystemLoader
from Services.EmailService.provider import send_email
def render_email_template(headers: list, rows: list):
def render_email_template(
headers: list, rows: list, balance_error: bool, bank_balance: float
):
template_dir = os.path.join(os.path.dirname(__file__), "templates")
env = Environment(loader=FileSystemLoader(template_dir)) # Load templates from the directory
template = env.get_template("template_accounts.html") # Load the specific template file
return template.render(headers=headers, rows=rows) # Render template with variables
env = Environment(
loader=FileSystemLoader(template_dir)
) # Load templates from the directory
template = env.get_template(
"template_accounts.html"
) # Load the specific template file
# Render template with variables
return template.render(
headers=headers,
rows=rows,
bank_balance=f"{bank_balance:.4f}",
balance_error=balance_error,
today=str(arrow.now().date()),
)
def send_email_to_given_address(send_to: str, html_template: str):
@@ -27,30 +40,42 @@ def send_email_to_given_address(send_to: str, html_template: str):
def set_account_records_to_send_email():
"""
from app import set_account_records_to_send_email
"""
db_session = AccountRecords.new_session()
account_records = AccountRecords.filter_all(db=db_session).core_query
account_records = (
AccountRecords.query.filter()
.order_by(
account_records.order_by(
AccountRecords.bank_date.desc(), AccountRecords.bank_reference_code.desc()
)
.limit(3)
.all()
)
first_record, second_record, balance_error = account_records[0], account_records[1], False
first_record, second_record, balance_error = (
account_records[0],
account_records[1],
False,
)
second_balance = first_record.bank_balance - first_record.currency_value
if second_balance != second_record.bank_balance:
balance_error = True
rows = [{
"date": record.bank_date, "comment": record.bank_comment, "currency": record.currency_value,
} for record in account_records]
list_of_rows = list()
for record in account_records:
list_of_rows.append(
[record.bank_date, record.process_comment, f"{record.currency_value:.4f}"]
)
send_to = "karatay@mehmetkaratay.com.tr"
html_template = render_email_template(
headers=["Ulaştığı Tarih", "Banka Transaksiyonu Ek Bilgi", "Aktarım Değeri"],
rows=rows,
rows=list_of_rows,
balance_error=balance_error,
bank_balance=account_records[0].bank_balance,
)
exit()
send_email_to_given_address(send_to=send_to, html_template=html_template)
if __name__ == "__main__":