person: create a person with address (and household without position (remove required position for household member)

This commit is contained in:
nobohan 2022-04-19 18:01:25 +02:00
parent c214c2f4a4
commit bad5506b98
8 changed files with 80 additions and 70 deletions

View File

@ -82,14 +82,13 @@ class HouseholdMember
/** /**
* @ORM\ManyToOne(targetEntity=Position::class) * @ORM\ManyToOne(targetEntity=Position::class)
* @Serializer\Groups({"read", "docgen:read"}) * @Serializer\Groups({"read", "docgen:read"})
* @Assert\NotNull(groups={"household_memberships_created"})
*/ */
private ?Position $position = null; private ?Position $position = null;
/** /**
* @ORM\Column(type="boolean", name="sharedhousehold") * @ORM\Column(type="boolean", name="sharedhousehold")
*/ */
private bool $shareHousehold = false; private bool $shareHousehold = true;
/** /**
* @ORM\Column(type="date_immutable", nullable=true, options={"default": null}) * @ORM\Column(type="date_immutable", nullable=true, options={"default": null})
@ -201,7 +200,7 @@ class HouseholdMember
return $this; return $this;
} }
public function setPosition(Position $position): self public function setPosition(?Position $position): self
{ {
if ($this->position instanceof Position) { if ($this->position instanceof Position) {
throw new LogicException('The position is already set. You cannot change ' . throw new LogicException('The position is already set. You cannot change ' .
@ -209,7 +208,9 @@ class HouseholdMember
} }
$this->position = $position; $this->position = $position;
if (null !== $position){
$this->shareHousehold = $position->getShareHousehold(); $this->shareHousehold = $position->getShareHousehold();
}
return $this; return $this;
} }

View File

@ -55,7 +55,7 @@ class MembersEditor
$this->eventDispatcher = $eventDispatcher; $this->eventDispatcher = $eventDispatcher;
} }
public function addMovement(DateTimeImmutable $date, Person $person, Position $position, ?bool $holder = false, ?string $comment = null): self public function addMovement(DateTimeImmutable $date, Person $person, ?Position $position, ?bool $holder = false, ?string $comment = null): self
{ {
if (null === $this->household) { if (null === $this->household) {
throw new LogicException('You must define a household first'); throw new LogicException('You must define a household first');
@ -69,6 +69,7 @@ class MembersEditor
->setComment($comment); ->setComment($comment);
$this->household->addMember($membership); $this->household->addMember($membership);
if (null !== $position) {
if ($position->getShareHousehold()) { if ($position->getShareHousehold()) {
// launch event only if moving to a "share household" position, // launch event only if moving to a "share household" position,
// and if the destination household is different than the previous one // and if the destination household is different than the previous one
@ -134,6 +135,8 @@ class MembersEditor
} }
} }
} }
}
$this->membershipsAffected[] = $membership; $this->membershipsAffected[] = $membership;
$this->persistables[] = $membership; $this->persistables[] = $membership;

View File

@ -302,14 +302,10 @@ export default {
'type': 'person', 'type': 'person',
'id': responsePerson.id 'id': responsePerson.id
}, },
'position': {
"type": "household_position",
"id": 4 //TODO, which position?
},
'start_date': { 'start_date': {
'datetime': `${new Date().toISOString().split('T')[0]}T00:00:00+02:00` 'datetime': `${new Date().toISOString().split('T')[0]}T00:00:00+02:00`
}, },
'holder': false, //TODO true or false? 'holder': false,
'comment': null 'comment': null
} }
], ],

View File

@ -146,6 +146,7 @@
<label class="form-check-label">{{ $t('person.address.show_address_form') }}</label> <label class="form-check-label">{{ $t('person.address.show_address_form') }}</label>
</div> </div>
<div v-if="action === 'create' && showAddressFormValue" class="form-floating mb-3"> <div v-if="action === 'create' && showAddressFormValue" class="form-floating mb-3">
<p>{{ $t('person.address.warning') }}</p>
<add-address <add-address
:context="addAddress.context" :context="addAddress.context"
:options="addAddress.options" :options="addAddress.options"

View File

@ -45,7 +45,8 @@ const personMessages = {
}, },
address: { address: {
create_address: "Ajouter une adresse", create_address: "Ajouter une adresse",
show_address_form: "Créer un ménage et ajouter une adresse" show_address_form: "Créer un ménage et ajouter une adresse",
warning: "Un nouveau ménage va être créé. L'usager sera membre de ce ménage."
} }
}, },
error_only_one_person: "Une seule personne peut être sélectionnée !" error_only_one_person: "Une seule personne peut être sélectionnée !"

View File

@ -111,6 +111,7 @@
{{ form_row(form.addressForm) }} {{ form_row(form.addressForm) }}
</div> </div>
<div id=address> <div id=address>
<p>{{ 'A new household will be created. The person will be member of this household.'|trans }}</p>
{{ form_row(form.address) }} {{ form_row(form.address) }}
</div> </div>

View File

@ -116,12 +116,18 @@ class MembersEditorNormalizer implements DenormalizerAwareInterface, Denormalize
$format, $format,
$context $context
); );
if (\array_key_exists('position', $concerned)) {
$position = $this->denormalizer->denormalize( $position = $this->denormalizer->denormalize(
$concerned['position'] ?? null, $concerned['position'] ?? null,
Position::class, Position::class,
$format, $format,
$context $context
); );
} else {
$position = null;
}
$startDate = $this->denormalizer->denormalize( $startDate = $this->denormalizer->denormalize(
$concerned['start_date'] ?? null, $concerned['start_date'] ?? null,
DateTimeImmutable::class, DateTimeImmutable::class,

View File

@ -87,6 +87,7 @@ choose civility: --
All genders: tous les genres All genders: tous les genres
Any person selected: Aucune personne sélectionnée Any person selected: Aucune personne sélectionnée
Create a household and add an address: Créer un ménage et ajouter une adresse Create a household and add an address: Créer un ménage et ajouter une adresse
A new household will be created. The person will be member of this household.: Un nouveau ménage va être créé. L'usager sera membre de ce ménage.
# dédoublonnage # dédoublonnage
Old person: Doublon Old person: Doublon