Skip to content

Commit

Permalink
Merge pull request #118 from opencdms/dev
Browse files Browse the repository at this point in the history
Sync with dev
  • Loading branch information
AbnerBissolli authored Jun 26, 2023
2 parents d3da8be + 07495cc commit 4a93107
Show file tree
Hide file tree
Showing 6 changed files with 298 additions and 85 deletions.
5 changes: 3 additions & 2 deletions api/wx/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,13 @@ class ManufacturerAdmin(admin.ModelAdmin):
class EquipmentTypeAdmin(admin.ModelAdmin):
list_display = ("name",)

@admin.register(models.FoundingSource)
class FoundingSourceAdmin(admin.ModelAdmin):
@admin.register(models.FundingSource)
class FundingSourceAdmin(admin.ModelAdmin):
list_display = ("name",)

@admin.register(models.Equipment)
class EquipmentAdmin(admin.ModelAdmin):
list_display = ("equipment_type", "manufacturer", "model", "serial_number", "acquisition_date", "first_deploy_date", "last_calibration_date")
readonly_fields=('location',)


Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 3.2.13 on 2023-06-20 14:33
# Generated by Django 3.2.13 on 2023-06-20 21:31

import ckeditor.fields
from django.db import migrations, models
Expand Down Expand Up @@ -63,7 +63,7 @@ class Migration(migrations.Migration):
('first_deploy_date', models.DateField(blank=True, null=True)),
('last_calibration_date', models.DateField(blank=True, null=True)),
('next_calibration_date', models.DateField(blank=True, null=True)),
('decomission_date', models.DateField(blank=True, null=True)),
('decommission_date', models.DateField(blank=True, null=True)),
('equipment_type', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='wx.equipmenttype')),
('founding_source', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='wx.foundingsource')),
('manufacturer', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='wx.manufacturer')),
Expand Down
42 changes: 42 additions & 0 deletions api/wx/migrations/0025_auto_20230621_1744.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Generated by Django 3.2.13 on 2023-06-21 17:44

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('wx', '0024_equipment_equipmenttype_foundingsource_manufacturer'),
]

operations = [
migrations.RenameModel(
old_name='FoundingSource',
new_name='FundingSource',
),
migrations.AlterModelOptions(
name='equipment',
options={'verbose_name': 'equipment', 'verbose_name_plural': 'equipment'},
),
migrations.RenameField(
model_name='equipment',
old_name='founding_source',
new_name='funding_source',
),
migrations.AddField(
model_name='equipment',
name='condition',
field=models.CharField(choices=[('F', 'Fully Functional'), ('P', 'Partially Functional'), ('N', 'Not Functional')], max_length=1, null=True),
),
migrations.AddField(
model_name='equipment',
name='last_deploy_date',
field=models.DateField(blank=True, null=True),
),
migrations.AddField(
model_name='equipment',
name='location',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='wx.station'),
),
]
19 changes: 15 additions & 4 deletions api/wx/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1394,22 +1394,33 @@ class Meta:
def __str__(self):
return self.name

class FoundingSource(BaseModel):
class FundingSource(BaseModel):
name = models.CharField(max_length=128)

def __str__(self):
return self.name

class Equipment(BaseModel):
class EquipmentCondition(models.TextChoices):
FULLY_FUNCTIONAL = 'F', gettext_lazy('Fully Functional')
PARTIALLY_FUNCTIONAL = 'P', gettext_lazy('Partially Functional')
NOT_FUNCTIONAL = 'N', gettext_lazy('Not Functional')

equipment_type = models.ForeignKey(EquipmentType, on_delete=models.DO_NOTHING)
manufacturer = models.ForeignKey(Manufacturer, on_delete=models.DO_NOTHING)
founding_source = models.ForeignKey(FoundingSource, on_delete=models.DO_NOTHING)
funding_source = models.ForeignKey(FundingSource, on_delete=models.DO_NOTHING)
model = models.CharField(max_length=64)
serial_number = models.CharField(max_length=64)
acquisition_date = models.DateField()
first_deploy_date = models.DateField(blank=True, null=True)
last_deploy_date = models.DateField(blank=True, null=True)
last_calibration_date = models.DateField(blank=True, null=True)
next_calibration_date = models.DateField(blank=True, null=True)
decomission_date = models.DateField(blank=True, null=True)
decommission_date = models.DateField(blank=True, null=True)
location = models.ForeignKey(Station, on_delete=models.DO_NOTHING, null=True)
condition = models.CharField(max_length=1, choices=EquipmentCondition.choices, null=True)

class Meta:
unique_together = ("equipment_type", "serial_number")
verbose_name = "equipment"
verbose_name_plural = "equipments"
verbose_name_plural = "equipment"
144 changes: 120 additions & 24 deletions api/wx/templates/wx/maintenance_reports/equipment_inventory.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@
<v-layout ma-2 mb-2>
<v-flex mr-2>
<v-autocomplete
:items="founding_sources"
:items="funding_sources"
item-text="name"
item-value="id"
v-model="equipment.founding_source_id"
label="Founding Source"
v-model="equipment.funding_source_id"
label="Funding Source"
required
hint="*Required"
persistent-hint
Expand Down Expand Up @@ -149,23 +149,23 @@
<v-flex>
<v-menu
:close-on-content-click="false"
v-model="equipment.decomission_date_menu"
v-model="equipment.decommission_date_menu"
transition="scale-transition"
offset-y
class="max-50"
>
<template v-slot:activator="{ on }">
<v-text-field
v-model="equipment.decomission_date"
v-model="equipment.decommission_date"
label="Date of Decomission"
v-on="on"
clearable
prepend-icon="event"
></v-text-field>
</template>
<v-date-picker
v-model="equipment.decomission_date"
@input="equipment.decomission_date_menu = false"
v-model="equipment.decommission_date"
@input="equipment.decommission_date_menu = false"
></v-date-picker>
</v-menu>
</v-flex>
Expand Down Expand Up @@ -220,12 +220,76 @@
</v-flex>
</v-layout>

<v-layout mx-2 mb-2>
<v-flex mr-2>
<v-menu
:close-on-content-click="false"
v-model="equipment.last_deploy_date_menu"
transition="scale-transition"
offset-y
class="max-50"
>
<template v-slot:activator="{ on }">
<v-text-field
v-model="equipment.last_deploy_date"
label="Date of Last Calibration"
v-on="on"
clearable
prepend-icon="event"
></v-text-field>
</template>
<v-date-picker
v-model="equipment.last_deploy_date"
@input="equipment.last_deploy_date_menu = false"
></v-date-picker>
</v-menu>
</v-flex>
<v-flex>
<v-autocomplete
:items="equipment_conditions"
item-text="name"
item-value="id"
v-model="equipment.condition_id"
label="Condition of the equipment"
autocomplete="off"
clearable
></v-autocomplete>
</v-flex>
</v-layout>
</v-layout>

<v-layout mx-2 mb-2>
<v-flex >
<v-autocomplete
:items="stations"
item-text="name"
item-value="id"
v-model="equipment.location_id"
label="Location of the equipment"
autocomplete="off"
clearable
></v-autocomplete>
</v-flex>
</v-layout>
</v-layout>

<v-card-actions>
<v-btn v-if="is_new_equipment" width="50%" color="primary" @click="dialog_new = false; createEquipment()">
<v-btn
v-if="is_new_equipment"
width="50%"
color="primary"
@click="dialog_new = false; createEquipment()"
:disabled="$v.equipment.$invalid"
>
Create Equipment
</v-btn>
<v-btn v-if="!is_new_equipment" width="50%" color="primary" @click="dialog_new = false; updateEquipment()">
<v-btn
v-if="!is_new_equipment"
width="50%"
color="primary"
@click="dialog_new = false; updateEquipment()"
:disabled="$v.equipment.$invalid"
>
Update Equipment
</v-btn>
<v-btn width="50%" @click="dialog_new = false">
Expand Down Expand Up @@ -336,6 +400,16 @@
el: "#app",
vuetify: new Vuetify(),
delimiters: ["[[", "]]"],
validations: {
equipment: {
equipment_type_id: { required },
funding_source_id: { required },
manufacturer_id: { required },
model: { required },
serial_number: { required },
acquisition_date: { required },
},
},
data:{
search: '',
loading: false,
Expand All @@ -346,14 +420,16 @@
equipments: [],
equipment_types: [],
manufacturers: [],
founding_sources: [],
funding_sources: [],
stations: [],
equipment_conditions: [],
is_new_equipment: true,
equipment: {
equipment_id: null,
equipment_type: null,
equipment_type_id: null,
founding_source: null,
founding_source_id: null,
funding_source: null,
funding_source_id: null,
manufacturer: null,
manufacturer_id: null,
model: null,
Expand All @@ -366,8 +442,14 @@
last_calibration_date_menu: false,
next_calibration_date: moment().format('YYYY-MM-DD'),
next_calibration_date_menu: false,
decomission_date: moment().format('YYYY-MM-DD'),
decomission_date_menu: false,
decommission_date: moment().format('YYYY-MM-DD'),
decommission_date_menu: false,
location: null,
location_id: null,
condition: null,
condition_id: null,
last_deploy_date: moment().format('YYYY-MM-DD'),
last_deploy_date_menu: false
},
headers: [
{ text: 'Equipment Type', align: 'left', value: 'equipment_type' },
Expand All @@ -376,7 +458,7 @@
{ text: 'Serial Number', align: 'center', value: 'serial_number' },
{ text: 'Acquired', align: 'center', value: 'acquisition_date' },
{ text: 'First Deployed', align: 'center', value: 'first_deploy_date' },
{ text: 'Last Deployed', align: 'center', value: 'last_deployed' },
{ text: 'Last Deployed', align: 'center', value: 'last_deploy_date' },
{ text: 'Location', align: 'center', value: 'location' },
{ text: 'Condition', align: 'center', value: 'condition' },
{ text: 'Actions', align: 'center', value: 'actions', sortable: false },
Expand All @@ -395,8 +477,8 @@
equipment_id: null,
equipment_type: null,
equipment_type_id: null,
founding_source: null,
founding_source_id: null,
funding_source: null,
funding_source_id: null,
manufacturer: null,
manufacturer_id: null,
model: null,
Expand All @@ -409,8 +491,14 @@
last_calibration_date_menu: false,
next_calibration_date: moment().format('YYYY-MM-DD'),
next_calibration_date_menu: false,
decomission_date: moment().format('YYYY-MM-DD'),
decomission_date_menu: false,
decommission_date: moment().format('YYYY-MM-DD'),
decommission_date_menu: false,
location: null,
location_id: null,
condition: null,
condition_id: null,
last_deploy_date: moment().format('YYYY-MM-DD'),
last_deploy_date_menu: false
};
}
}
Expand All @@ -426,7 +514,9 @@
this.equipments = res.data['equipments'];
this.equipment_types = res.data['equipment_types'];
this.manufacturers = res.data['manufacturers'];
this.founding_sources = res.data['founding_sources']
this.funding_sources = res.data['funding_sources'];
this.stations = res.data['stations'];
this.equipment_conditions = res.data['equipment_conditions'];
});
},
createEquipment(){
Expand All @@ -437,14 +527,17 @@
params: {
'equipment_type': this.equipment.equipment_type_id,
'manufacturer': this.equipment.manufacturer_id,
'founding_source': this.equipment.founding_source_id,
'funding_source': this.equipment.funding_source_id,
'model': this.equipment.model,
'serial_number': this.equipment.serial_number,
'acquisition_date': this.equipment.acquisition_date,
'first_deploy_date': this.equipment.first_deploy_date,
'last_calibration_date': this.equipment.last_calibration_date,
'next_calibration_date': this.equipment.next_calibration_date,
'decomission_date': this.equipment.decomission_date,
'decommission_date': this.equipment.decommission_date,
'location': this.equipment.location_id,
'condition': this.equipment.condition_id,
'last_deploy_date': this.equipment.last_deploy_date,
},
})
.then(
Expand All @@ -469,14 +562,17 @@
'equipment_id': this.equipment.equipment_id,
'equipment_type': this.equipment.equipment_type_id,
'manufacturer': this.equipment.manufacturer_id,
'founding_source': this.equipment.founding_source_id,
'funding_source': this.equipment.funding_source_id,
'model': this.equipment.model,
'serial_number': this.equipment.serial_number,
'acquisition_date': this.equipment.acquisition_date,
'first_deploy_date': this.equipment.first_deploy_date,
'last_calibration_date': this.equipment.last_calibration_date,
'next_calibration_date': this.equipment.next_calibration_date,
'decomission_date': this.decomission_date
'decommission_date': this.equipment.decommission_date,
'location': this.equipment.location_id,
'condition': this.equipment.condition_id,
'last_deploy_date': this.equipment.last_deploy_date,
},
})
.then(
Expand Down
Loading

0 comments on commit 4a93107

Please sign in to comment.