mirror of
https://github.com/OCA/reporting-engine.git
synced 2025-02-16 16:30:38 +02:00
pre-commit
This commit is contained in:
@@ -3,20 +3,17 @@
|
||||
|
||||
import logging
|
||||
|
||||
from odoo import SUPERUSER_ID
|
||||
from odoo import api, modules
|
||||
|
||||
from odoo import SUPERUSER_ID, api, modules
|
||||
from odoo.tools import existing_tables, topological_sort
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _bi_view(_name):
|
||||
return _name.startswith('x_bve.')
|
||||
return _name.startswith("x_bve.")
|
||||
|
||||
|
||||
def post_load():
|
||||
|
||||
def check_tables_exist(self, cr):
|
||||
"""
|
||||
Verify that all tables are present and try to initialize
|
||||
@@ -28,11 +25,11 @@ def post_load():
|
||||
|
||||
env = api.Environment(cr, SUPERUSER_ID, {})
|
||||
table2model = {
|
||||
model._table: name for name, model in env.items()
|
||||
model._table: name
|
||||
for name, model in env.items()
|
||||
if not model._abstract and not _bi_view(name) # here is the patch
|
||||
}
|
||||
missing_tables = set(table2model).difference(
|
||||
existing_tables(cr, table2model))
|
||||
missing_tables = set(table2model).difference(existing_tables(cr, table2model))
|
||||
|
||||
if missing_tables:
|
||||
missing = {table2model[table] for table in missing_tables}
|
||||
@@ -45,7 +42,8 @@ def post_load():
|
||||
env[name].init()
|
||||
# check again, and log errors if tables are still missing
|
||||
missing_tables = set(table2model).difference(
|
||||
existing_tables(cr, table2model))
|
||||
existing_tables(cr, table2model)
|
||||
)
|
||||
for table in missing_tables:
|
||||
_logger.error("Model %s has no table.", table2model[table])
|
||||
|
||||
@@ -55,18 +53,24 @@ def post_load():
|
||||
def uninstall_hook(cr, registry):
|
||||
# delete dirty data that could cause problems
|
||||
# while re-installing the module
|
||||
cr.execute("""
|
||||
cr.execute(
|
||||
"""
|
||||
delete from ir_model where model like 'x_bve.%'
|
||||
""")
|
||||
cr.execute("""
|
||||
"""
|
||||
)
|
||||
cr.execute(
|
||||
"""
|
||||
delete from bve_view where model_name like 'x_bve.%'
|
||||
""")
|
||||
cr.execute("""
|
||||
"""
|
||||
)
|
||||
cr.execute(
|
||||
"""
|
||||
SELECT 'DROP VIEW ' || table_name
|
||||
FROM information_schema.views
|
||||
WHERE table_schema NOT IN ('pg_catalog', 'information_schema')
|
||||
AND table_name like 'x_bve_%'
|
||||
""")
|
||||
"""
|
||||
)
|
||||
results = list(cr.fetchall())
|
||||
for result in results:
|
||||
cr.execute(result[0])
|
||||
|
||||
Reference in New Issue
Block a user