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