added salary table

This commit is contained in:
Chinenye Nmoh
2025-06-19 21:30:21 +01:00
parent 3be765bf41
commit 7fbb659fc6
7 changed files with 164 additions and 41 deletions
+28 -1
View File
@@ -45,7 +45,7 @@ class Salary(db.Model):
try:
new_data = cls(
customer_id=data.get('customerId'),
amount=data.get('salaryAmount', 0.0),
amount=data.get('amount', 0.0),
status='START',
salary_date = datetime.strptime(data.get('salaryDate'), "%Y-%m-%d").date() if data.get('salaryDate') else None,
account_id=data.get('accountId')
@@ -69,3 +69,30 @@ class Salary(db.Model):
except Exception as e:
logger.error(f"Error fetching pending salaries: {str(e)}")
return []
@classmethod
def update_status(cls, salary_id, status):
"""
Update the status of the salary record with the given salary_id.
"""
try:
# Retrieve salary record
salary = cls.query.get(salary_id)
if not salary:
raise ValueError(f"Salary with ID {salary_id} does not exist.")
if salary.status == status:
return salary.to_dict() # Still return the current state if no change
# Update status and timestamp
salary.status = status
salary.updated_at = datetime.now(timezone.utc) # Manually update timestamp if not auto-updating
db.session.commit()
logger.info("Salary status updated and committed.")
return salary.to_dict()
except Exception as e:
db.session.rollback()
logger.error(f"Error updating salary status: {e}")
raise Exception(f"Error updating salary status: {str(e)}")