Merge pull request #341 from eReuse/changes/3743-parth-number

Changes/3743 parth number
This commit is contained in:
cayop 2022-09-14 12:46:22 +02:00 committed by GitHub
commit 44c22898c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 94 additions and 15 deletions

View File

@ -326,9 +326,10 @@ class NewDeviceForm(FlaskForm):
pallet = StringField('Identity of pallet', [validators.Optional()])
components = TextAreaField('Components', [validators.Optional()])
info = TextAreaField('Info', [validators.Optional()])
serial_number = StringField('Serial Number', [validators.Optional()])
model = StringField('Model', [validators.Optional()])
manufacturer = StringField('Manufacturer', [validators.Optional()])
part_number = StringField('Part Number', [validators.Optional()])
serial_number = StringField('Serial Number', [validators.Optional()])
appearance = StringField('Appearance', [validators.Optional()])
functionality = StringField('Functionality', [validators.Optional()])
brand = StringField('Brand')
@ -390,6 +391,7 @@ class NewDeviceForm(FlaskForm):
self.info.data = self._obj.placeholder.info
self.components.data = self._obj.placeholder.components
self.serial_number.data = self._obj.serial_number
self.part_number.data = self._obj.part_number
self.model.data = self._obj.model
self.manufacturer.data = self._obj.manufacturer
self.appearance.data = appearance
@ -419,6 +421,7 @@ class NewDeviceForm(FlaskForm):
self.info.render_kw = disabled
self.components.render_kw = disabled
self.serial_number.render_kw = disabled
self.part_number.render_kw = disabled
self.model.render_kw = disabled
self.manufacturer.render_kw = disabled
self.appearance.render_kw = disabled
@ -516,6 +519,8 @@ class NewDeviceForm(FlaskForm):
self.model.data = self.model.data.lower()
if self.serial_number.data:
self.serial_number.data = self.serial_number.data.lower()
if self.part_number.data:
self.part_number.data = self.part_number.data.lower()
return True
@ -541,6 +546,7 @@ class NewDeviceForm(FlaskForm):
'model': self.model.data,
'manufacturer': self.manufacturer.data,
'serialNumber': self.serial_number.data,
'partNumber': self.part_number.data,
'brand': self.brand.data,
'version': self.version.data,
'generation': self.generation.data,
@ -587,6 +593,7 @@ class NewDeviceForm(FlaskForm):
self.phid.data = None
self.id_device_supplier.data = None
self.serial_number.data = None
self.part_number.data = None
self.sku.data = None
self.imei.data = None
self.meid.data = None
@ -616,6 +623,7 @@ class NewDeviceForm(FlaskForm):
self._obj.model = self.model.data
self._obj.manufacturer = self.manufacturer.data
self._obj.serial_number = self.serial_number.data
self._obj.part_number = self.part_number.data
self._obj.brand = self.brand.data
self._obj.version = self.version.data
self._obj.generation = self.generation.data
@ -1538,6 +1546,7 @@ class UploadPlaceholderForm(FlaskForm):
'Model',
'Manufacturer',
'Serial Number',
'Part Number',
'Id device Supplier',
'Pallet',
'Info',
@ -1565,6 +1574,7 @@ class UploadPlaceholderForm(FlaskForm):
device.model = "{}".format(data['Model'][i]).lower()
device.manufacturer = "{}".format(data['Manufacturer'][i]).lower()
device.serial_number = "{}".format(data['Serial Number'][i]).lower()
device.part_number = "{}".format(data['Part Number'][i]).lower()
placeholder.id_device_supplier = "{}".format(
data['Id device Supplier'][i]
)
@ -1587,6 +1597,7 @@ class UploadPlaceholderForm(FlaskForm):
'model': "{}".format(data['Model'][i]),
'manufacturer': "{}".format(data['Manufacturer'][i]),
'serialNumber': "{}".format(data['Serial Number'][i]),
'partNumber': "{}".format(data['Part Number'][i]),
},
}
json_placeholder = {
@ -1626,6 +1637,7 @@ class EditPlaceholderForm(FlaskForm):
manufacturer = StringField('Manufacturer', [validators.Optional()])
model = StringField('Model', [validators.Optional()])
serial_number = StringField('Serial Number', [validators.Optional()])
part_number = StringField('Part Number', [validators.Optional()])
id_device_supplier = StringField('Id Supplier', [validators.Optional()])
phid = StringField('Phid', [validators.DataRequired()])
pallet = StringField('Pallet', [validators.Optional()])

View File

@ -528,9 +528,14 @@ class DeviceCreateView(GenericMixin):
amount = form.amount.data
tpy = form.type.data
txt = f'{amount} real Device "{tpy}" created successfully.'
if amount == 1:
phid = form.placeholder.phid
dhid = form.placeholder.device.devicehub_id
placeholder = (
Placeholder.query.filter_by(owner=g.user)
.order_by(Placeholder.id.desc())
.first()
)
if amount == 1 and placeholder:
phid = placeholder.phid
dhid = placeholder.device.devicehub_id
txt = f'Device "{tpy}" real with PHID {phid} and DHID {dhid} '
txt += 'created successfully'
messages.success(txt)

View File

@ -0,0 +1,35 @@
"""add part number to device
Revision ID: bcfda54aaf2f
Revises: 6b0880832b78
Create Date: 2022-09-13 16:29:35.403897
"""
import citext
import sqlalchemy as sa
from alembic import context, op
# revision identifiers, used by Alembic.
revision = 'bcfda54aaf2f'
down_revision = '6b0880832b78'
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(
'device',
sa.Column('part_number', citext.CIText(), nullable=True),
schema=f'{get_inv()}',
)
def downgrade():
op.drop_column('device', 'part_number', schema=f'{get_inv()}')

View File

@ -128,6 +128,8 @@ class Device(Thing):
"""
serial_number = Column(Unicode(), check_lower('serial_number'))
serial_number.comment = """The serial number of the device in lower case."""
part_number = Column(Unicode(), check_lower('part_number'))
part_number.comment = """The part number of the device in lower case."""
brand = db.Column(CIText())
brand.comment = """A naming for consumers. This field can represent
several models, so it can be ambiguous, and it is not used to

View File

@ -52,6 +52,9 @@ class Device(Thing):
serial_number = SanitizedStr(
lower=True, validate=Length(max=STR_BIG_SIZE), data_key='serialNumber'
)
part_number = SanitizedStr(
lower=True, validate=Length(max=STR_BIG_SIZE), data_key='partNumber'
)
brand = SanitizedStr(
validate=Length(max=STR_BIG_SIZE), description=m.Device.brand.comment
)

View File

@ -259,6 +259,7 @@ class BaseDeviceRow(OrderedDict):
self['Real Components'] = ''
self['Real Type'] = ''
self['Real Serial Number'] = ''
self['Real Part Number'] = ''
self['Real Model'] = ''
self['Real Manufacturer'] = ''
@ -513,6 +514,7 @@ class DeviceRow(BaseDeviceRow):
self['Real Type'] = none2str(self.placeholder.device.type)
self['Real Manufacturer'] = none2str(self.placeholder.device.manufacturer)
self['Real Model'] = none2str(self.placeholder.device.model)
self['Real Part Number'] = none2str(self.placeholder.device.part_number)
self['Real Serial Number'] = none2str(self.placeholder.device.serial_number)

View File

@ -155,6 +155,19 @@
{% endif %}
</div>
<div class="from-group has-validation mb-2" id="Part_number">
<label for="partNumber" class="form-label">{{ form.part_number.label }}</label>
{{ form.part_number(class_="form-control") }}
<small class="text-muted form-text">Part number of this device</small>
{% if form.part_number.errors %}
<p class="text-danger">
{% for error in form.part_number.errors %}
{{ error }}<br/>
{% endfor %}
</p>
{% endif %}
</div>
<div class="from-group has-validation mb-2" id="Serial_number">
<label for="serialNumber" class="form-label">{{ form.serial_number.label }}</label>
{{ form.serial_number(class_="form-control") }}

View File

@ -113,6 +113,11 @@
<div class="col-lg-9 col-md-8">{{ placeholder.device.model or ''}}</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-4 label">Part Number</div>
<div class="col-lg-9 col-md-8">{{ placeholder.device.part_number or ''}}</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-4 label">Serial Number</div>
<div class="col-lg-9 col-md-8">{{ placeholder.device.serial_number or ''}}</div>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
Phid;Model;Manufacturer;Serial Number;Id device Supplier;Pallet;Info
a123;Vaio;Sony;12345678;TTT;24A;Good conditions
a124;Vaio;Sony;12345679;TTT;24A;Good conditions
a125;Vaio;Sony;12345680;TTT;24A;Good conditions
Phid;Model;Manufacturer;Serial Number;Part Number;Id device Supplier;Pallet;Info
a123;Vaio;Sony;12345678;;TTT;24A;Good conditions
a124;Vaio;Sony;12345679;;TTT;24A;Good conditions
a125;Vaio;Sony;12345680;;TTT;24A;Good conditions

1 Phid Model Manufacturer Serial Number Part Number Id device Supplier Pallet Info
2 a123 Vaio Sony 12345678 TTT 24A Good conditions
3 a124 Vaio Sony 12345679 TTT 24A Good conditions
4 a125 Vaio Sony 12345680 TTT 24A Good conditions

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@ -113,6 +113,7 @@ def test_physical_properties():
assert c.physical_properties == {
'usb': 3,
'serial_number': 'sn',
'part_number': None,
'pcmcia': None,
'model': 'ml',
'slots': 2,
@ -130,6 +131,7 @@ def test_physical_properties():
'model': 'foo',
'receiver_id': None,
'serial_number': 'foo-bar',
'part_number': None,
'transfer_state': TransferState.Initial
}