[IMP] open_workshop: trigger-based update of machine access list on partner change

- Replaced reactive `effect()` with `env.bus` event handling for partner changes
- `OwsPosCustomerSidebar` emits `partner-changed` when order is selected
- `OwsMachineAccessList` listens to `partner-changed` and updates access list
- Refactored to use `.get_partner()` instead of deprecated `.get_client()`
- Improved robustness and consistency of partner-based sidebar refresh
This commit is contained in:
Matthias Lotz 2025-06-02 23:35:49 +02:00
parent b7d98a999a
commit a1b98c41eb
2 changed files with 22 additions and 19 deletions

View File

@ -1,18 +1,17 @@
// @odoo-module // @odoo-module
import { Component, useState, onMounted } from "@odoo/owl"; import { Component, useState } from "@odoo/owl";
import { useBus } from "@web/core/utils/hooks"; import { useBus } from "@web/core/utils/hooks";
import { usePos } from "@point_of_sale/app/store/pos_hook"; import { usePos } from "@point_of_sale/app/store/pos_hook";
import { jsonrpc } from "@web/core/network/rpc_service"; import { jsonrpc } from "@web/core/network/rpc_service";
export class OwsMachineAccessList extends Component { export class OwsMachineAccessList extends Component {
static template = "open_workshop.OwsMachineAccessList"; static template = 'open_workshop.OwsMachineAccessList';
setup() { setup() {
this.pos = usePos(); this.pos = usePos();
this.state = useState({ this.state = useState({
client: null,
grouped_accesses: [], grouped_accesses: [],
security_briefing: false, security_briefing: false,
security_id: '', security_id: '',
@ -20,28 +19,31 @@ export class OwsMachineAccessList extends Component {
birthday: '', birthday: '',
}); });
// Initialer Client bei Komponentenerstellung (z.B. bei Seiten-Refresh) // 🔁 Reagiere auf Partnerwechsel über den Odoo-Bus
const initial_order = this.pos.get_order?.(); useBus(this.env.bus, 'partner-changed', () => {
const initial_client = initial_order?.get_client?.() || null;
this.state.client = initial_client;
// OWL-idiomatisch: Bus-Events mit useBus() registrieren
useBus(this.env.bus, "order-changed", () => this.updateAccessList());
useBus(this.env.bus, "client-selected", () => this.updateAccessList());
// Beim Initial-Render Zugriffsdaten laden
onMounted(() => {
this.updateAccessList(); this.updateAccessList();
}); });
// 🔃 Beim Mounten initiale Daten laden
this.updateAccessList();
} }
async updateAccessList() { async updateAccessList() {
const partner = this.pos.get_order?.()?.get_client?.() || null; const order = this.pos.get_order();
this.state.client = partner; const partner = order?.get_partner?.();
if (!partner) {
this.state.grouped_accesses = [];
this.state.security_briefing = false;
this.state.security_id = '';
this.state.rfid_card = '';
this.state.birthday = '';
return;
}
try { try {
const data = await jsonrpc("/open_workshop/partner_access", { const data = await jsonrpc("/open_workshop/partner_access", {
partner_id: partner?.id || 0, partner_id: partner.id,
}); });
this.state.grouped_accesses = data.access_by_area || []; this.state.grouped_accesses = data.access_by_area || [];
@ -49,7 +51,6 @@ export class OwsMachineAccessList extends Component {
this.state.security_id = data.security_id; this.state.security_id = data.security_id;
this.state.rfid_card = data.rfid_card; this.state.rfid_card = data.rfid_card;
this.state.birthday = data.birthday; this.state.birthday = data.birthday;
} catch (error) { } catch (error) {
console.error("Fehler beim Laden der Einweisungen:", error); console.error("Fehler beim Laden der Einweisungen:", error);
this.state.grouped_accesses = []; this.state.grouped_accesses = [];
@ -60,4 +61,3 @@ export class OwsMachineAccessList extends Component {
} }
} }
} }

View File

@ -6,12 +6,14 @@ import { usePos } from "@point_of_sale/app/store/pos_hook";
import { _t } from "@web/core/l10n/translation"; import { _t } from "@web/core/l10n/translation";
import { ConfirmPopup } from "@point_of_sale/app/utils/confirm_popup/confirm_popup"; import { ConfirmPopup } from "@point_of_sale/app/utils/confirm_popup/confirm_popup";
export class OwsPosCustomerSidebar extends Component { export class OwsPosCustomerSidebar extends Component {
static template = "open_workshop.OwsPosCustomerSidebar"; static template = "open_workshop.OwsPosCustomerSidebar";
setup() { setup() {
this.pos = usePos(); this.pos = usePos();
this.popup = useService("popup"); this.popup = useService("popup");
} }
addOrder() { addOrder() {
@ -66,5 +68,6 @@ export class OwsPosCustomerSidebar extends Component {
selectOrder(order) { selectOrder(order) {
this.pos.set_order(order); this.pos.set_order(order);
this.env.bus.trigger('partner-changed'); // ✅ korrektes Event feuern
} }
} }