Allow part lots to have an null storage location.

Otherwise we loose informations on migration.
This commit is contained in:
Jan Böhmer 2019-08-21 11:58:41 +02:00
parent c7e8fc9642
commit 016c2889ba
4 changed files with 16 additions and 8 deletions

View file

@ -71,9 +71,9 @@ class PartLot extends DBElement
protected $expiration_date;
/**
* @var Storelocation The storelocation of this lot
* @var Storelocation|null The storelocation of this lot
* @ORM\ManyToOne(targetEntity="Storelocation")
* @ORM\JoinColumn(name="id_store_location", referencedColumnName="id")
* @ORM\JoinColumn(name="id_store_location", referencedColumnName="id", nullable=true)
* @Selectable()
*/
protected $storage_location;
@ -82,6 +82,7 @@ class PartLot extends DBElement
* @var Part The part that is stored in this lot
* @ORM\ManyToOne(targetEntity="Part", inversedBy="partLots")
* @ORM\JoinColumn(name="id_part", referencedColumnName="id")
* @Assert\NotNull()
*/
protected $part;
@ -195,7 +196,7 @@ class PartLot extends DBElement
/**
* Gets the storage locatiion, where this part lot is stored.
* @return Storelocation The store location where this part is stored
* @return Storelocation|null The store location where this part is stored
*/
public function getStorageLocation(): ?Storelocation
{
@ -204,10 +205,10 @@ class PartLot extends DBElement
/**
* Sets the storage location, where this part lot is stored
* @param Storelocation $storage_location
* @param Storelocation|null $storage_location
* @return PartLot
*/
public function setStorageLocation(Storelocation $storage_location): PartLot
public function setStorageLocation(?Storelocation $storage_location): PartLot
{
$this->storage_location = $storage_location;
return $this;

View file

@ -58,6 +58,7 @@ class PartLotType extends AbstractType
$builder->add('storage_location', StructuralEntityType::class, ['class' => Storelocation::class,
'label' => 'part_lot.edit.location',
'required' => false,
'disable_not_selectable' => true,
'attr' => ['class' => 'selectpicker form-control-sm', 'data-live-search' => true]]);

View file

@ -32,14 +32,14 @@ final class Version20190812154222 extends AbstractMigration
$this->addSql(
'INSERT INTO part_lots (id_part, id_store_location, amount, instock_unknown, last_modified, datetime_added) ' .
'SELECT parts.id, parts.id_storelocation, parts.instock, 0, NOW(), NOW() FROM parts ' .
'WHERE parts.instock >= 0 AND parts.id_storelocation IS NOT NULL'
'WHERE parts.instock >= 0'
);
//Migrate part locations for parts with unknown instock
$this->addSql(
'INSERT INTO part_lots (id_part, id_store_location, amount, instock_unknown, last_modified, datetime_added) ' .
'SELECT parts.id, parts.id_storelocation, 0, 1, NOW(), NOW() FROM parts ' .
'WHERE parts.instock = -2 AND parts.id_storelocation IS NOT NULL'
'WHERE parts.instock = -2'
);
$this->addSql('ALTER TABLE attachements CHANGE element_id element_id INT DEFAULT NULL, CHANGE type_id type_id INT DEFAULT NULL, CHANGE last_modified last_modified DATETIME NOT NULL, CHANGE datetime_added datetime_added DATETIME NOT NULL');

View file

@ -14,7 +14,13 @@
<tr>
<td>{{ lot.description }}</td>
<td>
{{ lot.storageLocation.fullPath }}
{% if lot.storageLocation %}
{{ lot.storageLocation.fullPath }}
{% else %}
<span class="badge badge-pill badge-warning">
<i class="fas fa-question-circle fa-fw"></i> {% trans %}part_lots.location_unknown{% endtrans %}
</span>
{% endif %}
</td>
<td>
{% if lot.instockUnknown %}