IMP: Open Workshop Base und POS, Gruppierung der Maschinen im POS nach Maschinen Namen

This commit is contained in:
Matthias Lotz 2026-05-16 15:14:44 +02:00
parent 90e52b269a
commit 945bf4074d
3 changed files with 70 additions and 15 deletions

View File

@ -725,17 +725,37 @@ class OwsMachine(models.Model):
access_by_area = []
for area in areas:
machines = self.search([('area_id', '=', area.id), ('category', '=', 'red'), ('equipment_id.status_id.name', '!=', 'Ausgemustert')], order="name")
machine_list = []
# Maschinen nach Namen gruppieren (gleicher Name = Gruppe)
name_groups = {}
for machine in machines:
has_access = bool(self.env['ows.machine.access'].search([
('partner_id', '=', partner_id),
('machine_id', '=', machine.id),
], limit=1))
name = machine.name
if name not in name_groups:
name_groups[name] = []
name_groups[name].append(machine)
machine_list = []
for group_name, group_machines in name_groups.items():
is_group = len(group_machines) > 1
machine_entries = []
for idx, machine in enumerate(group_machines):
has_access = bool(self.env['ows.machine.access'].search([
('partner_id', '=', partner_id),
('machine_id', '=', machine.id),
], limit=1))
machine_entries.append({
'id': machine.id,
'name': machine.name,
'label': machine.model or machine.serial_no or f'#{idx + 1}',
'has_access': has_access,
})
machine_list.append({
'id': machine.id,
'name': machine.name,
'has_access': has_access,
'group_name': group_name,
'is_group': is_group,
'machines': machine_entries,
'has_any_access': any(m['has_access'] for m in machine_entries),
})
if machine_list:
access_by_area.append({
'area': area.name,

View File

@ -19,6 +19,7 @@ export class OwsMachineAccessList extends Component {
security_id: '',
rfid_card: '',
birthday: '',
expanded_groups: {},
});
// 🔁 Reagiere auf Partnerwechsel über den Odoo-Bus
@ -34,6 +35,7 @@ export class OwsMachineAccessList extends Component {
const order = this.pos.get_order();
const partner = order?.get_partner?.();
this.state.client = partner || null;
this.state.expanded_groups = {};
if (!partner) {
this.state.grouped_accesses = [];
this.state.security_briefing = false;
@ -63,6 +65,11 @@ export class OwsMachineAccessList extends Component {
}
}
toggleGroup = (areaName, groupName) => {
const key = `${areaName}|${groupName}`;
this.state.expanded_groups[key] = !this.state.expanded_groups[key];
}
}

View File

@ -59,13 +59,41 @@
<t t-if="area.machines.length > 0">
<div class="client-details-area" t-att-style="'border: solid 3px ' + area.color_hex + '; margin: 5px;'">
<ul>
<t t-foreach="area.machines" t-as="machine" t-key="machine.id">
<li class="client-detail">
<span t-attf-class="detail {{ machine.has_access ? 'client-details-vvow_briefing' : 'client-details-vvow_briefing_error' }}">
<t t-esc="machine.has_access ? '✅' : '❌'" />
</span>
<span class="briefinglabel"><t t-esc="machine.name"/></span>
</li>
<t t-foreach="area.machines" t-as="group" t-key="group.group_name">
<!-- Einzelne Maschine (keine Gruppe) -->
<t t-if="!group.is_group">
<li class="client-detail">
<span t-attf-class="detail {{ group.machines[0].has_access ? 'client-details-vvow_briefing' : 'client-details-vvow_briefing_error' }}">
<t t-esc="group.machines[0].has_access ? '✅' : '❌'" />
</span>
<span class="briefinglabel"><t t-esc="group.group_name"/></span>
</li>
</t>
<!-- Gruppe (mehrere Maschinen mit gleichem Namen) -->
<t t-if="group.is_group">
<li class="client-detail" style="cursor:pointer" t-on-click="() => toggleGroup(area.area, group.group_name)">
<span t-attf-class="detail {{ group.has_any_access ? 'client-details-vvow_briefing' : 'client-details-vvow_briefing_error' }}">
<t t-esc="group.has_any_access ? '✅' : '❌'" />
</span>
<span class="briefinglabel">
<t t-esc="group.group_name"/> (<t t-esc="group.machines.length"/>)
<t t-esc="state.expanded_groups[area.area + '|' + group.group_name] ? ' ▼' : ' ▶'"/>
</span>
</li>
<t t-if="state.expanded_groups[area.area + '|' + group.group_name]">
<t t-foreach="group.machines" t-as="machine" t-key="machine.id">
<li class="client-detail" style="padding-left:1.5rem;">
<span t-attf-class="detail {{ machine.has_access ? 'client-details-vvow_briefing' : 'client-details-vvow_briefing_error' }}">
<t t-esc="machine.has_access ? '✅' : '❌'" />
</span>
<span class="briefinglabel"><t t-esc="machine.label"/></span>
</li>
</t>
</t>
</t>
</t>
</ul>
</div>