More Fixes

This commit is contained in:
Jérémy Munsch 2023-05-16 08:33:17 +02:00
parent cbc8f85cc0
commit 5e5493ff82
No known key found for this signature in database
GPG key ID: 18361AF3BFEC0FEC
3 changed files with 14 additions and 31 deletions

View file

@ -72,3 +72,6 @@ php artisan cashier:webhook
# TODO
- Allow changing e-mail quand ca sera supporté sur CRM (use soundsystem mechanism)
# FIXME
 Envoi d’un mail de remboursement avec l’avoir en pièce jointe : l’avoir est vide

View file

@ -107,7 +107,7 @@ class SystempayCreditTransactionUpdate
return ResponseType::expiredPayment();
case \in_array($transStatus, ['SUSPENDED']):
return ResponseType::suspendedPayment();
case $this->isCancelledPayment($transStatus) or
case $this->isCanceledPayment($transStatus) or
\in_array($transStatus, ['CANCELLED']):
return ResponseType::canceledPayment();
case $this->isPendingPayment($transStatus):
@ -165,7 +165,7 @@ class SystempayCreditTransactionUpdate
* @param string $transStatus
* @return boolean
*/
private function isCancelledPayment(string $transStatus): bool
private function isCanceledPayment(string $transStatus): bool
{
$canceled_statuses = [
'NOT_CREATED',

View file

@ -131,7 +131,6 @@ class Order extends Model
static::updating(function (self $model) {
static::assertValidateStatus($model);
static::assertCancelStatus($model);
static::assertDeliveryStatusCanBeChanged($model);
if ($model->validation_status->equals(ValidationStatus::validated())) {
OrderIsValidated::dispatchUnless($model->mail_sent, $model);
@ -285,12 +284,15 @@ class Order extends Model
*
* @return boolean
*/
public function getCanBeCancelledAttribute(): bool
public function getCanBeCanceledAttribute(): bool
{
// * Si le status de validation n'est pas annulé
return $this->getOriginal('validation_status') !== ValidationStatus::canceled()->value &&
// * Si le statut de livraison n'est pas récupéré
$this->getOriginal('delivery_status') !== DeliveryStatus::recovered()->value;
!\in_array($this->getOriginal('delivery_status'), [
DeliveryStatus::recovered()->value,
DeliveryStatus::canceled()->value,
]);
}
/**
@ -304,7 +306,10 @@ class Order extends Model
public function getCanBeRefundAttribute(): bool
{
return $this->total_ttc > $this->total_refund and
!$this->delivery_status->equals(DeliveryStatus::recovered());
!\in_array($this->getOriginal('delivery_status'), [
DeliveryStatus::recovered()->value,
DeliveryStatus::canceled()->value,
]);
}
/**
@ -581,31 +586,6 @@ class Order extends Model
}
}
/**
* Check if delivery status can be changed.
*
* @param self $model
* @return void
* @throws \Illuminate\Validation\ValidationException If the order is canceled while it cannot be.
*/
public static function assertDeliveryStatusCanBeChanged(self $model)
{
$deliveryStatusHasChanged = $model->getOriginal('delivery_status') !== $model->delivery_status->value;
if ($deliveryStatusHasChanged and !$model->validation_status->equals(ValidationStatus::validated())) {
throw ValidationException::withMessages([
'messages' =>
// phpcs:ignore Generic.Files.LineLength.TooLong
"L'état de livraison de la commande ne peut être modifié car la commande '{$model->id}' n'est pas validée"
]);
}
if ($model->getOriginal('validation_status') === ValidationStatus::canceled()->value) {
throw ValidationException::withMessages([
'messages' =>
"L'état de livraison de la commande ne peut être modifié car la commande '{$model->id}' est annulée"
]);
}
}
/**
* Get updated current session order
*