Skip to content

Commit

Permalink
[MDS-5658] Fixing previous mine manager issue (#3028)
Browse files Browse the repository at this point in the history
* fixing previous mine manager retrieval

* updating unused imports
  • Loading branch information
isuru-aot authored Mar 27, 2024
1 parent 90a80bf commit 1ca2c74
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
13 changes: 10 additions & 3 deletions services/core-api/app/api/mines/mine/models/mine.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import uuid
from datetime import datetime, timezone

import utm
from geoalchemy2 import Geometry
Expand Down Expand Up @@ -180,9 +181,15 @@ def mine_location(self):
@hybrid_property
def mine_manager(self):
if self.mine_party_appt:
return next(
(mpa for mpa in self.mine_party_appt if mpa.mine_party_appt_type_code == 'MMG'),
None)
today = datetime.now(timezone.utc) # To filter out previous mine managers.
for party in self.mine_party_appt:
party_end_date = None
if party.end_date:
party_end_date = datetime.strptime(str(party.end_date), '%Y-%m-%d').replace(tzinfo=timezone.utc)
if party.mine_party_appt_type_code == "MMG" and party.party.email \
and (party_end_date == None or party_end_date > today) \
and str(party.status).lower() != "inactive": #There are mine managers with null status
return party
return None

@hybrid_property
Expand Down
6 changes: 2 additions & 4 deletions services/core-api/app/api/mines/reports/models/mine_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,8 @@ def collectRecipients(self, is_proponent):
core_recipients.extend(contacts_email)

# Adding mine manager's email.
if self.mine.mine_party_appt:
for party in self.mine.mine_party_appt:
if party.mine_party_appt_type_code == "MMG" and party.party.email:
ms_recipients.append(party.party.email)
if self.mine.mine_manager:
ms_recipients.append(self.mine.mine_manager.party.email)

# If no core_recipients found yet
if len(core_recipients) == 0:
Expand Down

0 comments on commit 1ca2c74

Please sign in to comment.