Enforece that part lot owner matches storage location owner, if option is selected

This commit is contained in:
Jan Böhmer 2023-04-02 23:58:15 +02:00
parent a7ff690891
commit 1acceae81e
2 changed files with 25 additions and 2 deletions

View file

@ -34,6 +34,7 @@ use Doctrine\ORM\Mapping as ORM;
use Exception;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
/**
* This entity describes a lot where parts can be stored.
@ -332,10 +333,26 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named
return $this;
}
public function getName(): string
{
return $this->description;
}
/**
* @Assert\Callback
*/
public function validate(ExecutionContextInterface $context, $payload)
{
//When the storage location sets the owner must match, the part lot owner must match the storage location owner
if ($this->getStorageLocation() && $this->getStorageLocation()->isPartOwnerMustMatch()
&& $this->getStorageLocation()->getOwner() && $this->getOwner()) {
if ($this->getOwner() !== $this->getStorageLocation()->getOwner()
&& $this->owner->getID() !== $this->getStorageLocation()->getOwner()->getID()) {
$context->buildViolation('validator.part_lot.owner_must_match_storage_location_owner')
->setParameter('%owner_name%', $this->getStorageLocation()->getOwner()->getFullName(true))
->atPath('owner')
->addViolation();
}
}
}
}

View file

@ -305,5 +305,11 @@
<target>Set a value here, or upload a file to automatically use its filename as name for the attachment.</target>
</segment>
</unit>
<unit id="nwGaNBW" name="validator.part_lot.owner_must_match_storage_location_owner">
<segment>
<source>validator.part_lot.owner_must_match_storage_location_owner</source>
<target>The owner of this lot must match the owner of the selected storage location (%owner_name%)!</target>
</segment>
</unit>
</file>
</xliff>