Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [ANDROAPP-6509] Use enrolment org unit when creating a new event from TEI detail #3942

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading