[FIX] open_workshop: Mehrere Maschinenfreigaben pro Einweisungsprodukt im POS
All checks were successful
odoo-restore-open_workshop-install / run-odoo-backup-in-docker (push) Successful in 4m48s

Beim Kauf eines Einweisungsprodukts wurden bisher nur eine Maschinenfreigabe erstellt,
selbst wenn das Produkt mehreren Maschinen zugeordnet war.
Dieser Fix passt _process_order an, sodass alle zugehörigen Maschinen erfasst und
ggf. neue Freigaben für den Kunden erstellt werden.

+ Nutzung von defaultdict zur besseren Produkt-Maschine-Zuordnung
+ Klares Logging zur Nachvollziehbarkeit
+ Verhindert doppelte Freigaben
This commit is contained in:
gitea 2025-05-06 17:19:57 +00:00
parent b40e2f7837
commit 31b4f7e7a2

View File

@ -1,4 +1,5 @@
from odoo import models, fields, api
from collections import defaultdict
#import debugpy
import logging
@ -7,9 +8,9 @@ _logger = logging.getLogger(__name__)
_logger.info("✅ pos_order.py geladen")
# debugpy.listen(("0.0.0.0", 5678))
print("✅ debugpy wartet auf Verbindung (Port 5678) ...")
# print("✅ debugpy wartet auf Verbindung (Port 5678) ...")
# Optional: Starte erst, wenn VS Code verbunden ist
#debugpy.wait_for_client()
# debugpy.wait_for_client()
class PosOrder(models.Model):
_inherit = 'pos.order'
@ -19,10 +20,9 @@ class PosOrder(models.Model):
pos_order = self.browse(pos_order_id)
training_products = self.env['ows.machine.training'].search([])
product_map = {
tp.training_id.product_tmpl_id.id: tp.machine_id.id
for tp in training_products
}
product_map = defaultdict(list)
for tp in training_products:
product_map[tp.training_id.product_tmpl_id.id].append(tp.machine_id.id)
partner = pos_order.partner_id
if not partner:
@ -31,15 +31,13 @@ class PosOrder(models.Model):
for line in pos_order.lines:
product_tmpl_id = line.product_id.product_tmpl_id.id
machine_id = product_map.get(product_tmpl_id)
_logger.info("🔍 Prüfe Produkt %s → Maschine ID: %s", line.product_id.display_name, machine_id)
if machine_id:
machine_ids = product_map.get(product_tmpl_id, [])
_logger.info("🔍 Prüfe Produkt %s → Maschinen IDs: %s", line.product_id.display_name, machine_ids)
for machine_id in machine_ids:
already_exists = self.env['ows.machine.access'].search([
('partner_id', '=', partner.id),
('machine_id', '=', machine_id)
])
], limit=1)
if not already_exists:
self.env['ows.machine.access'].create({
'partner_id': partner.id,