You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.3 KiB

[FIX] account_financial_report_webkit: Fix error if column exists The code comments say this should be happening before, but it was actually failing with: 2018-12-03 11:31:49,074 48 ERROR test openerp.sql_db: Programming error: column "last_rec_date" of relation "account_move_line" already exists , in query alter table account_move_line add column last_rec_date date 2018-12-03 11:31:49,074 48 CRITICAL test openerp.service.server: Failed to initialize database `test`. Traceback (most recent call last): File "/opt/odoo/custom/src/odoo/openerp/service/server.py", line 941, in preload_registries registry = RegistryManager.new(dbname, update_module=update_module) File "/opt/odoo/custom/src/odoo/openerp/modules/registry.py", line 370, in new openerp.modules.load_modules(registry._db, force_demo, status, update_module) File "/opt/odoo/custom/src/odoo/openerp/modules/loading.py", line 354, in load_modules loaded_modules, update_module) File "/opt/odoo/custom/src/odoo/openerp/modules/loading.py", line 255, in load_marked_modules loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks) File "/opt/odoo/custom/src/odoo/openerp/modules/loading.py", line 150, in load_module_graph getattr(py_module, pre_init)(cr) File "/opt/odoo/auto/addons/account_financial_report_webkit/hooks.py", line 11, in pre_init_hook 'alter table account_move_line add column last_rec_date date', File "/opt/odoo/custom/src/odoo/openerp/sql_db.py", line 171, in wrapper return f(self, *args, **kwargs) File "/opt/odoo/custom/src/odoo/openerp/sql_db.py", line 247, in execute res = self._obj.execute(query, params) ProgrammingError: column "last_rec_date" of relation "account_move_line" already exists
6 years ago
[FIX] account_financial_report_webkit: Fix error if column exists The code comments say this should be happening before, but it was actually failing with: 2018-12-03 11:31:49,074 48 ERROR test openerp.sql_db: Programming error: column "last_rec_date" of relation "account_move_line" already exists , in query alter table account_move_line add column last_rec_date date 2018-12-03 11:31:49,074 48 CRITICAL test openerp.service.server: Failed to initialize database `test`. Traceback (most recent call last): File "/opt/odoo/custom/src/odoo/openerp/service/server.py", line 941, in preload_registries registry = RegistryManager.new(dbname, update_module=update_module) File "/opt/odoo/custom/src/odoo/openerp/modules/registry.py", line 370, in new openerp.modules.load_modules(registry._db, force_demo, status, update_module) File "/opt/odoo/custom/src/odoo/openerp/modules/loading.py", line 354, in load_modules loaded_modules, update_module) File "/opt/odoo/custom/src/odoo/openerp/modules/loading.py", line 255, in load_marked_modules loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks) File "/opt/odoo/custom/src/odoo/openerp/modules/loading.py", line 150, in load_module_graph getattr(py_module, pre_init)(cr) File "/opt/odoo/auto/addons/account_financial_report_webkit/hooks.py", line 11, in pre_init_hook 'alter table account_move_line add column last_rec_date date', File "/opt/odoo/custom/src/odoo/openerp/sql_db.py", line 171, in wrapper return f(self, *args, **kwargs) File "/opt/odoo/custom/src/odoo/openerp/sql_db.py", line 247, in execute res = self._obj.execute(query, params) ProgrammingError: column "last_rec_date" of relation "account_move_line" already exists
6 years ago
  1. # -*- coding: utf-8 -*-
  2. # © 2017 Therp BV <http://therp.nl>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from psycopg2 import ProgrammingError
  5. from .models.account_move_line import AccountMoveLine
  6. def pre_init_hook(cr):
  7. # don't break if column exists
  8. try:
  9. with cr.savepoint():
  10. cr.execute(
  11. 'alter table account_move_line add column last_rec_date date',
  12. )
  13. cr.execute(
  14. 'comment on column account_move_line.last_rec_date is %s',
  15. (AccountMoveLine.last_rec_date.string,),
  16. )
  17. cr.execute(
  18. 'create index account_move_line_last_rec_date_index '
  19. 'on account_move_line (last_rec_date)',
  20. )
  21. except ProgrammingError:
  22. pass
  23. # but still do the initialization
  24. cr.execute(
  25. """update account_move_line
  26. set last_rec_date=ml_fr.date
  27. from account_move_line ml
  28. left join account_move_reconcile fr on ml.reconcile_id=fr.id
  29. join (
  30. select
  31. coalesce(reconcile_id, reconcile_partial_id) as reconcile_id,
  32. max(date) as date
  33. from account_move_line
  34. group by coalesce(reconcile_id, reconcile_partial_id)
  35. ) ml_fr on ml_fr.reconcile_id=fr.id
  36. where ml.id=account_move_line.id"""
  37. )