From 0454aebc95e1453698f6cc30e1fe51b819a452fe Mon Sep 17 00:00:00 2001 From: gitea Date: Sun, 6 Apr 2025 16:55:58 +0000 Subject: [PATCH] =?UTF-8?q?diese=20Version=20l=C3=A4sst=20sich=20mit=20ein?= =?UTF-8?q?er=20integrierten=20mirgration=20auf=20eine=20bestehende=20DB?= =?UTF-8?q?=20installieren,=20es=20fehlen=20noch=20die=20Einweisungen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __init__.py | 5 +++- __manifest__.py | 6 ++-- data/export_categories.py | 2 +- data/export_products.py | 2 +- data/export_products_and_categories.py | 2 ++ data/fix_missing_pos_partner.py | 40 ++++++++++++++++++++++++++ post_init_hook.py | 20 +++++++++++++ 7 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 data/fix_missing_pos_partner.py create mode 100644 post_init_hook.py diff --git a/__init__.py b/__init__.py index 369f620..6a137ce 100644 --- a/__init__.py +++ b/__init__.py @@ -1,2 +1,5 @@ from . import models -from . import controllers # <- hinzufügen \ No newline at end of file +from . import controllers +from . import post_init_hook +# damit run_migration sichtbar ist: +run_migration = post_init_hook.run_migration \ No newline at end of file diff --git a/__manifest__.py b/__manifest__.py index 9dc3c93..976ac68 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -8,6 +8,7 @@ 'category': 'Point of Sale', 'data': [ 'security/ir.model.access.csv', + 'views/machine_product_training_views.xml', 'views/menu_views.xml', 'views/machine_area_views.xml', 'views/machine_views.xml', @@ -16,8 +17,7 @@ 'views/machine_product_training_views.xml', 'data/data.xml', 'data/data_product_and_categories.xml', - 'data/machine_product_links.xml', - + 'data/machine_product_links.xml', ], 'qweb': [ @@ -33,5 +33,5 @@ #'static/src/js/debug.js', ], }, - + 'post_init_hook': 'run_migration', } diff --git a/data/export_categories.py b/data/export_categories.py index 9b2951b..1c1dec8 100644 --- a/data/export_categories.py +++ b/data/export_categories.py @@ -1,4 +1,4 @@ -# export_categories.py +# /opt/odoo/odoo/odoo-bin shell -d < export_categories.py import csv from odoo import api, SUPERUSER_ID import os diff --git a/data/export_products.py b/data/export_products.py index 8f413eb..f3aa4b2 100644 --- a/data/export_products.py +++ b/data/export_products.py @@ -1,4 +1,4 @@ -# export_products.py +# /opt/odoo/odoo/odoo-bin shell -d < export_products.py import csv from odoo import api, SUPERUSER_ID import os diff --git a/data/export_products_and_categories.py b/data/export_products_and_categories.py index c8d9514..c583527 100644 --- a/data/export_products_and_categories.py +++ b/data/export_products_and_categories.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +# /opt/odoo/odoo/odoo-bin shell -d < export_products_and_categories.py + import xml.etree.ElementTree as ET def xml_safe_id(name): diff --git a/data/fix_missing_pos_partner.py b/data/fix_missing_pos_partner.py new file mode 100644 index 0000000..c3d7bac --- /dev/null +++ b/data/fix_missing_pos_partner.py @@ -0,0 +1,40 @@ +from odoo import SUPERUSER_ID + +def fix_missing_pos_order_partners(cr, registry): + """ + Findet POS-Bestellungen mit fehlendem Partner und fügt Dummy-Partner + direkt per SQL mit der passenden ID ein. + """ + cr.execute(""" + SELECT DISTINCT partner_id FROM pos_order + WHERE partner_id IS NOT NULL + AND partner_id NOT IN (SELECT id FROM res_partner) + """) + missing_ids = [row[0] for row in cr.fetchall()] + print(f"Superuser: {SUPERUSER_ID}") + if not missing_ids: + print("✅ Keine fehlenden Partner gefunden.") + return + + print(f"🚧 Fehlende Partner-IDs: {missing_ids}") + + # Direkter SQL-Insert für res_partner + for pid in missing_ids: + print(f"➕ Erzeuge Dummy-Partner mit ID {pid}") + cr.execute(""" + INSERT INTO res_partner (id, name, customer_rank, create_uid, create_date, write_uid, write_date) + VALUES (%s, %s, %s, %s, now(), %s, now()) + ON CONFLICT (id) DO NOTHING + """, (pid, f"Fehlender Partner {pid}", 1, SUPERUSER_ID, SUPERUSER_ID)) + + # Sequenz zurücksetzen, um ID-Kollision zu verhindern + cr.execute(""" + SELECT setval('res_partner_id_seq', (SELECT MAX(id) FROM res_partner)) + """) + print("✅ Alle fehlenden Partner ergänzt.") + + + +# Automatischer Start in odoo-bin shell +if 'env' in globals(): + fix_missing_pos_order_partners(env.cr, env.registry) \ No newline at end of file diff --git a/post_init_hook.py b/post_init_hook.py new file mode 100644 index 0000000..be8ca98 --- /dev/null +++ b/post_init_hook.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from odoo import SUPERUSER_ID +from odoo.api import Environment +import logging + +_logger = logging.getLogger(__name__) + +def run_migration(cr, registry): + """ + Wird nach der Modulinstallation automatisch ausgeführt. + Migriert vorhandene res.partner-Einträge zu ows.user. + """ + env = Environment(cr, SUPERUSER_ID, {}) + + _logger.info("[OWS] Starte automatische Partner-Migration bei Modulinstallation...") + try: + env['res.partner'].migrate_existing_partners() + _logger.info("[OWS] Automatische Partner-Migration abgeschlossen.") + except Exception as e: + _logger.error(f"[OWS] Fehler bei automatischer Migration: {e}")