Skip to content

Commit

Permalink
fix: [ANDROAPP-6509] Use enrolment org unit when creating a new event…
Browse files Browse the repository at this point in the history
… from TEI detail
  • Loading branch information
xavimolloy committed Dec 20, 2024
1 parent 164b76a commit cb374fa
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ class TEIDataFragment : FragmentGlobalAbstract(), TEIDataContracts.View {
)
.onSelection { selectedOrgUnits ->
if (selectedOrgUnits.isNotEmpty()) {
presenter.onOrgUnitForNewEventSelected(
presenter.onNewEventSelected(
orgUnitUid = selectedOrgUnits.first().uid(),
programStageUid = programStageUid,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,8 @@ class TEIDataPresenter(
if (stage != null) {
when (eventCreationType) {
EventCreationType.ADDNEW -> programUid?.let { program ->
checkOrgUnitCount(program, stage.uid())
val orgUnitUid = d2.enrollment(enrollmentUid)?.organisationUnit()
orgUnitUid?.let { onNewEventSelected(orgUnitUid, stage.uid()) } ?: checkOrgUnitCount(program, stage.uid())
}

EventCreationType.SCHEDULE -> {
Expand Down Expand Up @@ -425,14 +426,14 @@ class TEIDataPresenter(
CoroutineScope(dispatcher.io()).launch {
val orgUnits = teiDataRepository.programOrgListInCaptureScope(programUid)
if (orgUnits.count() == 1) {
onOrgUnitForNewEventSelected(orgUnits.first().uid(), programStageUid)
onNewEventSelected(orgUnits.first().uid(), programStageUid)
} else {
view.displayOrgUnitSelectorForNewEvent(programUid, programStageUid)
}
}
}

fun onOrgUnitForNewEventSelected(orgUnitUid: String, programStageUid: String) {
fun onNewEventSelected(orgUnitUid: String, programStageUid: String) {
CoroutineScope(dispatcher.io()).launch {
programUid?.let {
createEventUseCase(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ class TeiDataPresenterTest {
),
) doReturn (Result.success(eventUid))

teiDataPresenter.onOrgUnitForNewEventSelected(
teiDataPresenter.onNewEventSelected(
orgUnitUid,
programStageUid,
)
Expand Down Expand Up @@ -319,7 +319,7 @@ class TeiDataPresenterTest {

whenever(d2ErrorUtils.getErrorMessage(d2Error)) doReturn (errorMessage)

teiDataPresenter.onOrgUnitForNewEventSelected(
teiDataPresenter.onNewEventSelected(
orgUnitUid,
programStageUid,
)
Expand Down

0 comments on commit cb374fa

Please sign in to comment.