add part number

This commit is contained in:
Cayo Puigdefabregas 2022-09-13 18:15:50 +02:00
parent d9d0dc533a
commit d215008927
7 changed files with 76 additions and 4 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") }}