diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index ed69f202..69f0b4ba 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -86,12 +86,18 @@ DEVICES = { "Smartphone", "Cellphone", ], + "Drives & Storage": [ + "All DataStorage", + "HardDrives", + "SolidStageDrive", + ], } COMPUTERS = ['Desktop', 'Laptop', 'Server', 'Computer'] MONITORS = ["ComputerMonitor", "Monitor", "TelevisionSet", "Projector"] MOBILE = ["Mobile", "Tablet", "Smartphone", "Cellphone"] +STORAGE = ["HardDrive", "SolidStateDrive"] class AdvancedSearchForm(FlaskForm): @@ -175,9 +181,16 @@ class FilterForm(FlaskForm): elif "All Mobile" == self.device_type: filter_type = MOBILE + elif "All DataStorage" == self.device_type: + filter_type = STORAGE + if filter_type: self.devices = self.devices.filter(Device.type.in_(filter_type)) + # if self.device_type in STORAGE + ["All DataStorage"]: + # import pdb; pdb.set_trace() + # self.devices = self.devices.filter(Component.parent_id.is_(None)) + return self.devices.order_by(Device.updated.desc()) @@ -1259,6 +1272,12 @@ class TradeDocumentForm(FlaskForm): class TransferForm(FlaskForm): + lot_name = StringField( + 'Lot Name', + [validators.DataRequired()], + render_kw={'class': "form-control"}, + description="You need put a lot name", + ) code = StringField( 'Code', [validators.DataRequired()], @@ -1303,9 +1322,7 @@ class TransferForm(FlaskForm): return self._obj def set_obj(self): - name = self.code.data - if self._tmp_lot: - name = self._tmp_lot.name + name = self.lot_name.data self.newlot = Lot(name=name) if self._tmp_lot: self.newlot.devices = self._tmp_lot.devices @@ -1339,6 +1356,7 @@ class EditTransferForm(TransferForm): self.code.data = self._obj.code self.description.data = self._obj.description self.date.data = self._obj.date + self.lot_name.data = self._obj.lot.name def validate(self, extra_validators=None): is_valid = super().validate(extra_validators) @@ -1350,6 +1368,7 @@ class EditTransferForm(TransferForm): def set_obj(self, commit=True): self.populate_obj(self._obj) + self._obj.lot.name = self.lot_name.data class NotesForm(FlaskForm): diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 63d9294f..0267db00 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -296,6 +296,8 @@ class BindingView(GenericMixin): self.real_phid = self.new_placeholder.phid self.abstract_dhid = self.old_device.devicehub_id self.abstract_phid = self.old_placeholder.phid + if self.old_placeholder.kangaroo: + self.new_placeholder.kangaroo = True # to do a backup of abstract_dhid and abstract_phid in # workbench device @@ -383,6 +385,9 @@ class UnBindingView(GenericMixin): if device.binding.is_abstract: return + kangaroo = device.binding.kangaroo + device.binding.kangaroo = False + dict_device = copy.copy(device.__dict__) dict_device.pop('_sa_instance_state') dict_device.pop('id', None) @@ -402,7 +407,10 @@ class UnBindingView(GenericMixin): if c.binding: c.binding.device.parent = new_device - placeholder = Placeholder(device=new_device, binding=device, is_abstract=True) + placeholder = Placeholder( + device=new_device, binding=device, is_abstract=True, kangaroo=kangaroo + ) + if ( device.dhid_bk and not Device.query.filter_by(devicehub_id=device.dhid_bk).first() @@ -756,6 +764,8 @@ class NewTransferView(GenericMixin): def dispatch_request(self, type_id, lot_id=None): self.form = self.form_class(lot_id=lot_id, type=type_id) self.get_context() + referrer = request.referrer or url_for('inventory.devicelist') + self.context.update({'referrer': referrer}) if self.form.validate_on_submit(): self.form.save() @@ -767,7 +777,12 @@ class NewTransferView(GenericMixin): next_url = url_for('inventory.lotdevicelist', lot_id=str(new_lot_id)) return flask.redirect(next_url) - self.context.update({'form': self.form, 'title': self.title}) + self.context.update( + { + 'form': self.form, + 'title': self.title, + } + ) return flask.render_template(self.template_name, **self.context) diff --git a/ereuse_devicehub/migrations/versions/a13ed6ad0e3e_add_kangaroo_in_placeholder.py b/ereuse_devicehub/migrations/versions/a13ed6ad0e3e_add_kangaroo_in_placeholder.py new file mode 100644 index 00000000..bc3b6790 --- /dev/null +++ b/ereuse_devicehub/migrations/versions/a13ed6ad0e3e_add_kangaroo_in_placeholder.py @@ -0,0 +1,34 @@ +"""add kangaroo in placeholder + +Revision ID: a13ed6ad0e3e +Revises: 626c17026ca7 +Create Date: 2022-10-13 11:56:15.303218 + +""" +import sqlalchemy as sa +from alembic import context, op + +# revision identifiers, used by Alembic. +revision = 'a13ed6ad0e3e' +down_revision = '626c17026ca7' +branch_labels = None +depends_on = None + + +def get_inv(): + INV = context.get_x_argument(as_dictionary=True).get('inventory') + if not INV: + raise ValueError("Inventory value is not specified") + return INV + + +def upgrade(): + op.add_column( + 'placeholder', + sa.Column('kangaroo', sa.Boolean(), nullable=True), + schema=f'{get_inv()}', + ) + + +def downgrade(): + op.drop_column('placeholder', 'kangaroo', schema=f'{get_inv()}') diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 5f1ccb20..86d8c834 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -932,6 +932,7 @@ class Placeholder(Thing): ) id_device_internal = db.Column(CIText()) id_device_internal.comment = "Identification used internaly for the user" + kangaroo = db.Column(Boolean, default=False, nullable=True) device_id = db.Column( BigInteger, diff --git a/ereuse_devicehub/static/css/devicehub.css b/ereuse_devicehub/static/css/devicehub.css index 84771144..46fae783 100644 --- a/ereuse_devicehub/static/css/devicehub.css +++ b/ereuse_devicehub/static/css/devicehub.css @@ -29,4 +29,7 @@ .doTransfer { margin-top: -8px; margin-right: 15px;" +} +.printLabelForm { + margin-left: 10px; } \ No newline at end of file diff --git a/ereuse_devicehub/templates/inventory/device_list.html b/ereuse_devicehub/templates/inventory/device_list.html index 2132f7c7..3bb32fc5 100644 --- a/ereuse_devicehub/templates/inventory/device_list.html +++ b/ereuse_devicehub/templates/inventory/device_list.html @@ -357,6 +357,7 @@
{% for dev in devices %} + {% if dev.placeholder and (not dev.parent_id or dev.parent.placeholder.kangaroo) %}