[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:
parent
b7d98a999a
commit
a1b98c41eb
|
|
@ -1,18 +1,17 @@
|
|||
// @odoo-module
|
||||
|
||||
import { Component, useState, onMounted } from "@odoo/owl";
|
||||
import { Component, useState } from "@odoo/owl";
|
||||
import { useBus } from "@web/core/utils/hooks";
|
||||
import { usePos } from "@point_of_sale/app/store/pos_hook";
|
||||
import { jsonrpc } from "@web/core/network/rpc_service";
|
||||
|
||||
export class OwsMachineAccessList extends Component {
|
||||
static template = "open_workshop.OwsMachineAccessList";
|
||||
static template = 'open_workshop.OwsMachineAccessList';
|
||||
|
||||
setup() {
|
||||
this.pos = usePos();
|
||||
|
||||
this.state = useState({
|
||||
client: null,
|
||||
grouped_accesses: [],
|
||||
security_briefing: false,
|
||||
security_id: '',
|
||||
|
|
@ -20,28 +19,31 @@ export class OwsMachineAccessList extends Component {
|
|||
birthday: '',
|
||||
});
|
||||
|
||||
// Initialer Client bei Komponentenerstellung (z. B. bei Seiten-Refresh)
|
||||
const initial_order = this.pos.get_order?.();
|
||||
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(() => {
|
||||
// 🔁 Reagiere auf Partnerwechsel über den Odoo-Bus
|
||||
useBus(this.env.bus, 'partner-changed', () => {
|
||||
this.updateAccessList();
|
||||
});
|
||||
|
||||
// 🔃 Beim Mounten initiale Daten laden
|
||||
this.updateAccessList();
|
||||
}
|
||||
|
||||
async updateAccessList() {
|
||||
const partner = this.pos.get_order?.()?.get_client?.() || null;
|
||||
this.state.client = partner;
|
||||
const order = this.pos.get_order();
|
||||
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 {
|
||||
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 || [];
|
||||
|
|
@ -49,7 +51,6 @@ export class OwsMachineAccessList extends Component {
|
|||
this.state.security_id = data.security_id;
|
||||
this.state.rfid_card = data.rfid_card;
|
||||
this.state.birthday = data.birthday;
|
||||
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Laden der Einweisungen:", error);
|
||||
this.state.grouped_accesses = [];
|
||||
|
|
@ -60,4 +61,3 @@ export class OwsMachineAccessList extends Component {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,12 +6,14 @@ import { usePos } from "@point_of_sale/app/store/pos_hook";
|
|||
import { _t } from "@web/core/l10n/translation";
|
||||
import { ConfirmPopup } from "@point_of_sale/app/utils/confirm_popup/confirm_popup";
|
||||
|
||||
|
||||
export class OwsPosCustomerSidebar extends Component {
|
||||
static template = "open_workshop.OwsPosCustomerSidebar";
|
||||
|
||||
setup() {
|
||||
this.pos = usePos();
|
||||
this.popup = useService("popup");
|
||||
|
||||
}
|
||||
|
||||
addOrder() {
|
||||
|
|
@ -66,5 +68,6 @@ export class OwsPosCustomerSidebar extends Component {
|
|||
|
||||
selectOrder(order) {
|
||||
this.pos.set_order(order);
|
||||
this.env.bus.trigger('partner-changed'); // ✅ korrektes Event feuern
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user