From abe3c44213c94db010a30b22ee74854024ad39c8 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 6 Oct 2022 16:56:12 +0200 Subject: [PATCH 1/2] add new buttons for transfer --- ereuse_devicehub/inventory/forms.py | 14 +++++++++----- ereuse_devicehub/inventory/views.py | 6 +++++- .../templates/ereuse_devicehub/base_site.html | 10 ++++++++++ .../templates/inventory/device_list.html | 4 ++-- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index b1503c6e..ed69f202 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -1275,14 +1275,14 @@ class TransferForm(FlaskForm): def __init__(self, *args, **kwargs): self._type = kwargs.get('type') 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) self._obj = None def validate(self, extra_validators=None): is_valid = super().validate(extra_validators) - if not self._tmp_lot: - return False if self._type and self.type.data not in ['incoming', 'outgoing']: return False @@ -1303,8 +1303,12 @@ class TransferForm(FlaskForm): return self._obj def set_obj(self): - self.newlot = Lot(name=self._tmp_lot.name) - self.newlot.devices = self._tmp_lot.devices + name = self.code.data + 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) self._obj = Transfer(lot=self.newlot) diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 41a3c16b..63d9294f 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -753,7 +753,7 @@ class NewTransferView(GenericMixin): form_class = TransferForm 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.get_context() @@ -1355,6 +1355,10 @@ devices.add_url_rule( ) devices.add_url_rule( '/lot//transfer//', + view_func=NewTransferView.as_view('lot_new_transfer'), +) +devices.add_url_rule( + '/lot/transfer//', view_func=NewTransferView.as_view('new_transfer'), ) devices.add_url_rule( diff --git a/ereuse_devicehub/templates/ereuse_devicehub/base_site.html b/ereuse_devicehub/templates/ereuse_devicehub/base_site.html index 4abeec8b..a4deb465 100644 --- a/ereuse_devicehub/templates/ereuse_devicehub/base_site.html +++ b/ereuse_devicehub/templates/ereuse_devicehub/base_site.html @@ -194,6 +194,11 @@ {% else %}