open_workshop/scripts/uninstall_vvow_einweisungen.py
gitea 42faa68903
Some checks failed
odoo-restore-open_workshop-install / run-odoo-backup-in-docker (push) Failing after 4m37s
alter table vvow_einweisungen
2025-04-12 08:04:30 +00:00

44 lines
1.6 KiB
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# scripts/uninstall_vvow_einweisungen.py
# Auszug aus der gitea action:
'''
- name: Uninstall vvow_einweisungen
run: |
docker exec hobbyhimmel_odoo_${{ env.CONTAINER_NAME_EXTENSION }} /bin/bash -c "
cd /home/odoo/custom_addons/open_workshop/scripts && \
/opt/odoo/odoo/odoo-bin shell -d ${{ env.DB_NAME }} < uninstall_vvow_einweisungen.py"
docker restart hobbyhimmel_odoo_${{ env.CONTAINER_NAME_EXTENSION }}
'''
from odoo import api, SUPERUSER_ID
from odoo.modules.registry import Registry
modules_to_uninstall = [
'vvow_einweisungen'
]
with api.Environment.manage():
registry = Registry("hobbyhimmel") # wird beim odoo-bin shell überschrieben
with registry.cursor() as cr:
env = api.Environment(cr, SUPERUSER_ID, {})
# 🛠 Versuch, FK-Constraint manuell zu entfernen (vorheriger Fehlerursache)
try:
cr.execute("""
ALTER TABLE res_partner DROP CONSTRAINT IF EXISTS res_partner_vvow_document_id_fkey
""")
print("✅ Foreign Key 'res_partner_vvow_document_id_fkey' erfolgreich (oder schon) entfernt.")
except Exception as e:
print(f"⚠️ Konnte FK nicht entfernen: {e}")
for module_name in modules_to_uninstall:
module = env['ir.module.module'].search([('name', '=', module_name)], limit=1)
if module and module.state == 'installed':
print(f"📦 Deinstalliere Modul: {module_name}")
module.button_immediate_uninstall()
else:
print(f" Modul nicht gefunden oder nicht installiert: {module_name}")
cr.commit()