Merge pull request #376 from eReuse/feature/3854-new-button-transfer

add new buttons for transfer
This commit is contained in:
cayop 2022-10-06 18:25:18 +02:00 committed by GitHub
commit fbf70aac89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 8 deletions

View File

@ -1275,14 +1275,14 @@ class TransferForm(FlaskForm):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self._type = kwargs.get('type') self._type = kwargs.get('type')
lot_id = kwargs.pop('lot_id', None) lot_id = kwargs.pop('lot_id', None)
self._tmp_lot = Lot.query.filter(Lot.id == lot_id).one() self._tmp_lot = None
if lot_id:
self._tmp_lot = Lot.query.filter(Lot.id == lot_id).one()
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self._obj = None self._obj = None
def validate(self, extra_validators=None): def validate(self, extra_validators=None):
is_valid = super().validate(extra_validators) is_valid = super().validate(extra_validators)
if not self._tmp_lot:
return False
if self._type and self.type.data not in ['incoming', 'outgoing']: if self._type and self.type.data not in ['incoming', 'outgoing']:
return False return False
@ -1303,8 +1303,12 @@ class TransferForm(FlaskForm):
return self._obj return self._obj
def set_obj(self): def set_obj(self):
self.newlot = Lot(name=self._tmp_lot.name) name = self.code.data
self.newlot.devices = self._tmp_lot.devices if self._tmp_lot:
name = self._tmp_lot.name
self.newlot = Lot(name=name)
if self._tmp_lot:
self.newlot.devices = self._tmp_lot.devices
db.session.add(self.newlot) db.session.add(self.newlot)
self._obj = Transfer(lot=self.newlot) self._obj = Transfer(lot=self.newlot)

View File

@ -753,7 +753,7 @@ class NewTransferView(GenericMixin):
form_class = TransferForm form_class = TransferForm
title = "Add new transfer" title = "Add new transfer"
def dispatch_request(self, lot_id, type_id): def dispatch_request(self, type_id, lot_id=None):
self.form = self.form_class(lot_id=lot_id, type=type_id) self.form = self.form_class(lot_id=lot_id, type=type_id)
self.get_context() self.get_context()
@ -1355,6 +1355,10 @@ devices.add_url_rule(
) )
devices.add_url_rule( devices.add_url_rule(
'/lot/<string:lot_id>/transfer/<string:type_id>/', '/lot/<string:lot_id>/transfer/<string:type_id>/',
view_func=NewTransferView.as_view('lot_new_transfer'),
)
devices.add_url_rule(
'/lot/transfer/<string:type_id>/',
view_func=NewTransferView.as_view('new_transfer'), view_func=NewTransferView.as_view('new_transfer'),
) )
devices.add_url_rule( devices.add_url_rule(

View File

@ -194,6 +194,11 @@
{% else %} {% else %}
<ul id="incoming-lots-nav" class="nav-content collapse" data-bs-parent="#sidebar-nav"> <ul id="incoming-lots-nav" class="nav-content collapse" data-bs-parent="#sidebar-nav">
{% endif %} {% endif %}
<li>
<a href="{{ url_for('inventory.new_transfer', type_id='incoming') }}">
<i class="bi bi-plus" style="font-size: larger;"></i><span>New Incoming lot</span>
</a>
</li>
{% for lot in lots %} {% for lot in lots %}
{% if lot.is_incoming %} {% if lot.is_incoming %}
<li> <li>
@ -219,6 +224,11 @@
{% else %} {% else %}
<ul id="outgoing-lots-nav" class="nav-content collapse " data-bs-parent="#sidebar-nav"> <ul id="outgoing-lots-nav" class="nav-content collapse " data-bs-parent="#sidebar-nav">
{% endif %} {% endif %}
<li>
<a href="{{ url_for('inventory.new_transfer', type_id='outgoing') }}">
<i class="bi bi-plus" style="font-size: larger;"></i><span>New Outgoing lot</span>
</a>
</li>
{% for lot in lots %} {% for lot in lots %}
{% if lot.is_outgoing %} {% if lot.is_outgoing %}
<li> <li>

View File

@ -47,10 +47,10 @@
{% if lot.is_temporary or not lot.transfer.closed %} {% if lot.is_temporary or not lot.transfer.closed %}
{% if lot and lot.is_temporary %} {% if lot and lot.is_temporary %}
<a type="button" href="{{ url_for('inventory.new_transfer', lot_id=lot.id, type_id='outgoing') }}" class="btn btn-primary doTransfer" > <a type="button" href="{{ url_for('inventory.lot_new_transfer', lot_id=lot.id, type_id='outgoing') }}" class="btn btn-primary doTransfer" >
Create Outgoing Lot Create Outgoing Lot
</a> </a>
<a type="button" href="{{ url_for('inventory.new_transfer', lot_id=lot.id, type_id='incoming') }}" class="btn btn-primary doTransfer"> <a type="button" href="{{ url_for('inventory.lot_new_transfer', lot_id=lot.id, type_id='incoming') }}" class="btn btn-primary doTransfer">
Create Incoming Lot Create Incoming Lot
</a> </a>
{% endif %} {% endif %}

View File

@ -68,6 +68,7 @@ def test_api_docs(client: Client):
'/inventory/lot/{lot_id}/trade-document/add/', '/inventory/lot/{lot_id}/trade-document/add/',
'/inventory/lot/{lot_id}/transfer/{type_id}/', '/inventory/lot/{lot_id}/transfer/{type_id}/',
'/inventory/lot/{lot_id}/transfer/', '/inventory/lot/{lot_id}/transfer/',
'/inventory/lot/transfer/{type_id}/',
'/inventory/lot/{lot_id}/upload-snapshot/', '/inventory/lot/{lot_id}/upload-snapshot/',
'/inventory/snapshots/{snapshot_uuid}/', '/inventory/snapshots/{snapshot_uuid}/',
'/inventory/snapshots/', '/inventory/snapshots/',