diff --git a/__manifest__.py b/__manifest__.py
index 6529af3..e0005ad 100644
--- a/__manifest__.py
+++ b/__manifest__.py
@@ -23,6 +23,8 @@
'open_workshop/static/src/css/pos.css',
'open_workshop/static/src/js/ows_pos_customer_sidebar.js',
'open_workshop/static/src/xml/ows_pos_customer_sidebar.xml',
+ 'open_workshop/static/src/js/ows_machine_access_list.js',
+ 'open_workshop/static/src/xml/ows_machine_access_list.xml',
'open_workshop/static/src/xml/ows_product_screen.xml',
],
},
diff --git a/models/ows_models.py b/models/ows_models.py
index 7032fa3..e2fea6e 100644
--- a/models/ows_models.py
+++ b/models/ows_models.py
@@ -424,10 +424,10 @@ class OwsMachine(models.Model):
@api.model
def get_access_list_grouped(self, partner_id):
+ partner = self.env['res.partner'].browse(partner_id)
areas = self.env['ows.machine.area'].search([], order="name")
- _logger.info("🔍 Maschinenbereiche: %s", areas.mapped('name'))
- _logger.info("🔍 Partner_id: %s", partner_id)
- res = []
+
+ access_by_area = []
for area in areas:
machines = self.search([('area_id', '=', area.id)], order="name")
machine_list = []
@@ -440,12 +440,22 @@ class OwsMachine(models.Model):
'name': machine.name,
'has_access': has_access,
})
- res.append({
- 'area': area.name,
- 'color_hex': area.color_hex or '#000000',
- 'machines': machine_list
- })
- return res
+ if machine_list:
+ access_by_area.append({
+ 'area': area.name,
+ 'color_hex': area.color_hex or '#000000',
+ 'machines': machine_list
+ })
+
+ user = partner.ows_user_id[:1]
+ return {
+ 'access_by_area': access_by_area,
+ 'security_briefing': user.security_briefing if user else False,
+ 'security_id': user.security_id if user else '',
+ 'rfid_card': user.rfid_card if user else '',
+ 'birthday': user.birthday if user else '',
+ }
+
class OwsMachineAccess(models.Model):
diff --git a/static/src/js/machine_access_sidebar.js b/static/src/js/machine_access_sidebar.js
deleted file mode 100644
index f94cb2b..0000000
--- a/static/src/js/machine_access_sidebar.js
+++ /dev/null
@@ -1,132 +0,0 @@
-/* This file is based on the original code from the OrderWidget in Odoo Point of Sale module (screen.js).
- * It has been modified to create a sidebar that displays machine access information for the selected customer.*/
-
-odoo.define('open_workshop.machine_access_sidebar', function (require) {
- "use strict";
-
- const DUMMY_PARTNER = {
- id: 1,
- name: "AAAA Max Mustermann",
- security_briefing: false,
- security_id: null,
- create_date: null,
- };
-
- var rpc = require('web.rpc');
- var screens = require('point_of_sale.screens');
- var chrome = require('point_of_sale.chrome');
- var core = require('web.core');
- var QWeb = core.qweb;
-
-
-
- var MachineAccessSidebar = screens.ScreenWidget.extend({
- template: 'MachineAccessSidebar',
-
- init: function(parent, options) {
- this._super(parent, options);
- this.partner = null;
- this.pos.bind('change:selectedOrder', this.bind_order_events, this);
- },
-
- show: function() {
- this._super();
- this.render_access();
- },
-
- update_machine_access: function(partner) {
- console.log("🔁 Sidebar aktualisiert Maschinenfreigaben für Partner:", partner);
- this.partner = partner;
- this.render_access();
- },
-
- render_access: function() {
- var self = this;
- var partner = this.partner || DUMMY_PARTNER;
-
-
-
- rpc.query({
- model: 'ows.machine',
- method: 'get_access_list_grouped',
- args: [partner.id],
- }).then(function (result) {
- partner.create_date = partner.create_date && partner.create_date.substring(0, 10);
- var html = QWeb.render('PartnerMachineAccessList', {
- areas: result || [],
- partner: partner,
- });
- self.$('.access-content').html(html);
- });
- },
-
- bind_order_events: function () {
- var order = this.pos.get_order();
- if (!order) return;
-
- /*order.unbind('change:client', this);
- order.bind('change:client', this, function () {
- this.update_machine_access(order.get_client());
- });*/
-
- this.update_machine_access(order.get_client());
- }
- });
-
- // Sidebar aktualisieren bei Klick im ClientListScreenWidget (Vorschau)
- screens.ClientListScreenWidget.include({
- show: function () {
- this._super();
- $('.order-selector').hide(); // ← wird hier versteckt
- },
- hide: function () {
- this._super();
- $('.order-selector').show(); // ← beim Verlassen wieder zeigen
- },
- display_client_details: function (visibility, partner, clickpos) {
- this._super(visibility, partner, clickpos);
-
- try {
- if (partner && typeof partner === 'object' && 'id' in partner) {
- var sidebar = this.pos.chrome.sidebar_widget;
- if (sidebar) {
- console.log("👤 ClientListScreen: Vorschau für", partner.name);
- sidebar.update_machine_access(partner);
- }
- }
- } catch (e) {
- console.warn("⚠️ Fehler beim Update der Sidebar nach Kundenauswahl:", e);
- }
- }
- });
-
- chrome.Chrome.include({
- build_widgets: function () {
- this._super();
-
- var sidebar = new MachineAccessSidebar(this, {});
- this.sidebar_widget = sidebar;
- sidebar.appendTo(this.$el);
-
- //this.pos.bind('change:selectedOrder', sidebar.bind_order_events, sidebar);
-
- if (this.pos.get_order()) {
- sidebar.bind_order_events();
- }
- }
- });
-});
-
-
-odoo.define('open_workshop.models', function (require) {
- "use strict";
- var models = require('point_of_sale.models');
- var field_utils = require('web.field_utils');
- models.load_fields('res.partner', 'create_date');
- models.load_fields('res.partner', 'birthday');
- models.load_fields('res.partner', 'security_briefing');
- models.load_fields('res.partner', 'security_id');
- models.load_fields('res.partner', 'rfid_card');
-
-
-});
\ No newline at end of file
diff --git a/static/src/js/ows_machine_access_list.js b/static/src/js/ows_machine_access_list.js
new file mode 100644
index 0000000..f209071
--- /dev/null
+++ b/static/src/js/ows_machine_access_list.js
@@ -0,0 +1,63 @@
+// @odoo-module
+
+import { Component, useState, onMounted } 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";
+
+ setup() {
+ this.pos = usePos();
+
+ this.state = useState({
+ client: null,
+ grouped_accesses: [],
+ security_briefing: false,
+ security_id: '',
+ rfid_card: '',
+ 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(() => {
+ this.updateAccessList();
+ });
+ }
+
+ async updateAccessList() {
+ const partner = this.pos.get_order?.()?.get_client?.() || null;
+ this.state.client = partner;
+
+ try {
+ const data = await jsonrpc("/open_workshop/partner_access", {
+ partner_id: partner?.id || 0,
+ });
+
+ this.state.grouped_accesses = data.access_by_area || [];
+ this.state.security_briefing = data.security_briefing;
+ 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 = [];
+ this.state.security_briefing = false;
+ this.state.security_id = '';
+ this.state.rfid_card = '';
+ this.state.birthday = '';
+ }
+ }
+}
+
diff --git a/static/src/js/product_screen_template_patch.js b/static/src/js/product_screen_template_patch.js
index c86c55a..d478e56 100644
--- a/static/src/js/product_screen_template_patch.js
+++ b/static/src/js/product_screen_template_patch.js
@@ -3,12 +3,14 @@
import { ProductScreen } from "@point_of_sale/app/screens/product_screen/product_screen";
import { registry } from "@web/core/registry";
import { OwsPosCustomerSidebar } from "@open_workshop/js/ows_pos_customer_sidebar";
+import { OwsMachineAccessList } from "@open_workshop/js/ows_machine_access_list";
export class OwsProductScreen extends ProductScreen {
static template = "open_workshop.ProductScreen";
static components = {
...ProductScreen.components,
OwsPosCustomerSidebar,
+ OwsMachineAccessList,
};
}
diff --git a/static/src/xml/ows_machine_access_list.xml b/static/src/xml/ows_machine_access_list.xml
new file mode 100644
index 0000000..787441b
--- /dev/null
+++ b/static/src/xml/ows_machine_access_list.xml
@@ -0,0 +1,76 @@
+
+
+
+
+
+
+ ‼️Bitte Prüfen‼️
+
+
+
+
+
+
-
-
-
-
- ‼️Bitte Prüfen‼️
-
-
-
-
-