Skip to content

Commit

Permalink
[Admin] Can not change donation to membership if no linked adherent
Browse files Browse the repository at this point in the history
  • Loading branch information
Remg committed Oct 30, 2024
1 parent 41a76d7 commit 9e28540
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/Admin/DonationAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ protected function configureFormFields(FormMapper $form): void
->add('membership', CheckboxType::class, [
'label' => 'Cotisation',
'required' => false,
'disabled' => $donation->isMembership(),
'disabled' => $donation->isMembership() || null === $donation->getDonator()?->getAdherent(),
])
->add('code', null, [
'label' => 'Code don',
Expand Down Expand Up @@ -616,6 +616,18 @@ protected function preUpdate(object $object): void
$this->handleAdherentMembership($object);
}

/**
* @param Donation $object
*/
protected function postUpdate(object $object): void
{
parent::postUpdate($object);

if ($adherent = $object->getDonator()?->getAdherent()) {
$this->refreshAdherent($adherent);
}
}

/**
* @param Donation $object
*/
Expand All @@ -624,8 +636,7 @@ protected function postRemove(object $object): void
parent::postRemove($object);

if ($object->isMembership() && $adherent = $object->getDonator()?->getAdherent()) {
$this->adherentRepository->refreshLastDonationDate($adherent);
$this->dispatcher->dispatch(new UserEvent($adherent), UserEvents::USER_UPDATED_IN_ADMIN);
$this->refreshAdherent($adherent);
}

if ($object->hasFileUploaded()) {
Expand All @@ -637,6 +648,12 @@ protected function postRemove(object $object): void
}
}

private function refreshAdherent(Adherent $adherent): void
{
$this->adherentRepository->refreshLastDonationDate($adherent);
$this->dispatcher->dispatch(new UserEvent($adherent), UserEvents::USER_UPDATED_IN_ADMIN);
}

protected function createNewInstance(): object
{
/** @var Donation $donation */
Expand Down

0 comments on commit 9e28540

Please sign in to comment.