From 24a02a61dc2bd8a9aa68ccff6c9f7a30cc9ae1f7 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Wed, 17 Dec 2008 10:25:54 +0100 Subject: [PATCH] [FIX] fix crash when updating crm_configuration module bzr revid: christophe@cobalt-20081217092554-71f72u61bp5rbpil --- addons/crm_configuration/report/crm_report.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/addons/crm_configuration/report/crm_report.py b/addons/crm_configuration/report/crm_report.py index 775eb7ec5cc..156f7c21a44 100644 --- a/addons/crm_configuration/report/crm_report.py +++ b/addons/crm_configuration/report/crm_report.py @@ -28,6 +28,13 @@ AVAILABLE_STATES = [ ('done', 'Closed'), ('pending','Pending') ] + +def drop_view_if_exists(cr, viewname): + cr.execute("select count(1) from pg_class where relkind=%s and relname=%s", ('v', viewname,)) + if cr.fetchone(): + cr.execute("DROP view %s" % (viewname,)) + cr.commit() + class report_crm_case_section_categ2(osv.osv): _name = "report.crm.case.section.categ2" _description = "Cases by section and category2" @@ -46,8 +53,9 @@ class report_crm_case_section_categ2(osv.osv): _order = 'category2_id, section_id' def init(self, cr): + drop_view_if_exists(cr, "report_crm_case_section_categ2") cr.execute(""" - create or replace view report_crm_case_section_categ2 as ( + create view report_crm_case_section_categ2 as ( select min(c.id) as id, to_char(c.create_date,'YYYY-MM')||'-01' as name, @@ -84,8 +92,9 @@ class report_crm_case_section_stage(osv.osv): _order = 'stage_id, section_id' def init(self, cr): + drop_view_if_exists(cr, "report_crm_case_section_stage") cr.execute(""" - create or replace view report_crm_case_section_stage as ( + create view report_crm_case_section_stage as ( select min(c.id) as id, to_char(c.create_date,'YYYY-MM')||'-01' as name, @@ -120,8 +129,9 @@ class report_crm_case_section_categ_stage(osv.osv): _order = 'stage_id, section_id, categ_id' def init(self, cr): + drop_view_if_exists(cr, "report_crm_case_section_categ_stage") cr.execute(""" - create or replace view report_crm_case_section_categ_stage as ( + create view report_crm_case_section_categ_stage as ( select min(c.id) as id, to_char(c.create_date,'YYYY-MM')||'-01' as name, @@ -157,8 +167,9 @@ class report_crm_case_section_categ_categ2(osv.osv): _order = 'section_id, categ_id, category2_id' def init(self, cr): + drop_view_if_exists(cr, "report_crm_case_section_categ_categ2") cr.execute(""" - create or replace view report_crm_case_section_categ_categ2 as ( + create view report_crm_case_section_categ_categ2 as ( select min(c.id) as id, to_char(c.create_date, 'YYYY-MM')||'-01' as name,