Allow to edit the vendor_barcode field of a PartLot

This commit is contained in:
Jan Böhmer 2023-11-17 23:05:47 +01:00
parent 3e6b80d1cf
commit 96a771e7ac
5 changed files with 74 additions and 2 deletions

View file

@ -47,6 +47,7 @@ use App\Validator\Constraints\ValidPartLot;
use DateTime; use DateTime;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Exception; use Exception;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface; use Symfony\Component\Validator\Context\ExecutionContextInterface;
@ -64,6 +65,7 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface;
#[ORM\Index(columns: ['needs_refill'], name: 'part_lots_idx_needs_refill')] #[ORM\Index(columns: ['needs_refill'], name: 'part_lots_idx_needs_refill')]
#[ORM\Index(columns: ['vendor_barcode'], name: 'part_lots_idx_barcode')] #[ORM\Index(columns: ['vendor_barcode'], name: 'part_lots_idx_barcode')]
#[ValidPartLot] #[ValidPartLot]
#[UniqueEntity(['vendor_barcode'], message: 'validator.part_lot.vendor_barcode_must_be_unique')]
#[ApiResource( #[ApiResource(
operations: [ operations: [
new Get(security: 'is_granted("read", object)'), new Get(security: 'is_granted("read", object)'),
@ -159,6 +161,7 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named
* @var string|null The content of the barcode of this part lot (e.g. a barcode on the package put by the vendor) * @var string|null The content of the barcode of this part lot (e.g. a barcode on the package put by the vendor)
*/ */
#[ORM\Column(type: Types::STRING, nullable: true)] #[ORM\Column(type: Types::STRING, nullable: true)]
#[Groups(['part_lot:read', 'part_lot:write'])]
protected ?string $vendor_barcode = null; protected ?string $vendor_barcode = null;
public function __clone() public function __clone()
@ -361,6 +364,29 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named
return $this->description; return $this->description;
} }
/**
* The content of the barcode of this part lot (e.g. a barcode on the package put by the vendor), or
* null if no barcode is set.
* @return string|null
*/
public function getVendorBarcode(): ?string
{
return $this->vendor_barcode;
}
/**
* Set the content of the barcode of this part lot (e.g. a barcode on the package put by the vendor).
* @param string|null $vendor_barcode
* @return $this
*/
public function setVendorBarcode(?string $vendor_barcode): PartLot
{
$this->vendor_barcode = $vendor_barcode;
return $this;
}
#[Assert\Callback] #[Assert\Callback]
public function validate(ExecutionContextInterface $context, $payload): void public function validate(ExecutionContextInterface $context, $payload): void
{ {

View file

@ -80,7 +80,7 @@ class PartLotType extends AbstractType
'required' => false, 'required' => false,
]); ]);
$builder->add('expirationDate', DateType::class, [ $builder->add('expiration_date', DateType::class, [
'label' => 'part_lot.edit.expiration_date', 'label' => 'part_lot.edit.expiration_date',
'attr' => [], 'attr' => [],
'widget' => 'single_text', 'widget' => 'single_text',
@ -102,6 +102,12 @@ class PartLotType extends AbstractType
'required' => false, 'required' => false,
'help' => 'part_lot.owner.help', 'help' => 'part_lot.owner.help',
]); ]);
$builder->add('vendor_barcode', TextType::class, [
'label' => 'part_lot.edit.vendor_barcode',
'help' => 'part_lot.edit.vendor_barcode.help',
'required' => false,
]);
} }
public function configureOptions(OptionsResolver $resolver): void public function configureOptions(OptionsResolver $resolver): void

View file

@ -89,7 +89,23 @@
{% import 'components/collection_type.macro.html.twig' as collection %} {% import 'components/collection_type.macro.html.twig' as collection %}
<tr> <tr>
<td> <td>
{{ form_widget(form) }} {{ form_row(form.description) }}
{{ form_row(form.storage_location) }}
{{ form_row(form.amount) }}
{{ form_row(form.instock_unknown) }}
{{ form_row(form.needs_refill) }}
{{ form_row(form.expiration_date) }}
{% set id = 'collapse_' ~ random() %}
<a class="btn btn-link offset-sm-3 btn-sm" data-bs-toggle="collapse" href="#{{ id }}" role="button" aria-expanded="false" aria-controls="{{ id }}">
{% trans %}part_lot.edit.advanced{% endtrans %}
</a>
<div class="collapse" id="{{ id }}">
{{ form_row(form.comment) }}
{{ form_row(form.owner) }}
{{ form_row(form.vendor_barcode) }}
</div>
</td> </td>
<td> <td>
<button type="button" class="btn btn-danger lot_btn_delete" {{ collection.delete_btn() }}> <button type="button" class="btn btn-danger lot_btn_delete" {{ collection.delete_btn() }}>

View file

@ -11927,5 +11927,23 @@ Please note, that you can not impersonate a disabled user. If you try you will g
<target>Do you really want to delete this association? This can not be undone.</target> <target>Do you really want to delete this association? This can not be undone.</target>
</segment> </segment>
</unit> </unit>
<unit id="o3HcwZn" name="part_lot.edit.advanced">
<segment>
<source>part_lot.edit.advanced</source>
<target>Expand advanced options</target>
</segment>
</unit>
<unit id="f9LyaPM" name="part_lot.edit.vendor_barcode">
<segment>
<source>part_lot.edit.vendor_barcode</source>
<target>Vendor barcode</target>
</segment>
</unit>
<unit id="wSvbQyH" name="part_lot.edit.vendor_barcode.help">
<segment>
<source>part_lot.edit.vendor_barcode.help</source>
<target>If this lot already have a barcode (e.g. put there by the vendor), you can input its content here, to easily scan it.</target>
</segment>
</unit>
</file> </file>
</xliff> </xliff>

View file

@ -335,5 +335,11 @@
<target>The association with this part already exists!</target> <target>The association with this part already exists!</target>
</segment> </segment>
</unit> </unit>
<unit id="sfW4NYE" name="validator.part_lot.vendor_barcode_must_be_unique">
<segment>
<source>validator.part_lot.vendor_barcode_must_be_unique</source>
<target>This vendor barcode value was already used in another lot. The barcode must be unique!</target>
</segment>
</unit>
</file> </file>
</xliff> </xliff>