[FIX] module: do not recreate categories when updating modules
bzr revid: chs@openerp.com-20121128183701-6d7p1jqu1hdlshcp
This commit is contained in:
parent
a8e2c0d622
commit
e03f111704
|
@ -31,6 +31,7 @@ import urllib
|
||||||
import zipimport
|
import zipimport
|
||||||
|
|
||||||
from openerp import modules, pooler, release, tools, addons
|
from openerp import modules, pooler, release, tools, addons
|
||||||
|
from openerp.modules.db import create_categories
|
||||||
from openerp.tools.parse_version import parse_version
|
from openerp.tools.parse_version import parse_version
|
||||||
from openerp.tools.translate import _
|
from openerp.tools.translate import _
|
||||||
from openerp.osv import fields, osv, orm
|
from openerp.osv import fields, osv, orm
|
||||||
|
@ -638,21 +639,8 @@ class module(osv.osv):
|
||||||
|
|
||||||
categs = category.split('/')
|
categs = category.split('/')
|
||||||
if categs != current_category_path:
|
if categs != current_category_path:
|
||||||
p_id = None
|
cat_id = create_categories(cr, categs)
|
||||||
while categs:
|
mod_browse.write({'category_id': cat_id})
|
||||||
if p_id is not None:
|
|
||||||
cr.execute('SELECT id FROM ir_module_category WHERE name=%s AND parent_id=%s', (categs[0], p_id))
|
|
||||||
else:
|
|
||||||
cr.execute('SELECT id FROM ir_module_category WHERE name=%s AND parent_id is NULL', (categs[0],))
|
|
||||||
c_id = cr.fetchone()
|
|
||||||
if not c_id:
|
|
||||||
cr.execute('INSERT INTO ir_module_category (name, parent_id) VALUES (%s, %s) RETURNING id', (categs[0], p_id))
|
|
||||||
c_id = cr.fetchone()[0]
|
|
||||||
else:
|
|
||||||
c_id = c_id[0]
|
|
||||||
p_id = c_id
|
|
||||||
categs = categs[1:]
|
|
||||||
self.write(cr, uid, [mod_browse.id], {'category_id': p_id})
|
|
||||||
|
|
||||||
def update_translations(self, cr, uid, ids, filter_lang=None, context=None):
|
def update_translations(self, cr, uid, ids, filter_lang=None, context=None):
|
||||||
if not filter_lang:
|
if not filter_lang:
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#
|
#
|
||||||
# OpenERP, Open Source Management Solution
|
# OpenERP, Open Source Management Solution
|
||||||
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
||||||
# Copyright (C) 2010 OpenERP s.a. (<http://openerp.com>).
|
# Copyright (C) 2010-2012 OpenERP s.a. (<http://openerp.com>).
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU Affero General Public License as
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
@ -119,21 +119,17 @@ def create_categories(cr, categories):
|
||||||
category = []
|
category = []
|
||||||
while categories:
|
while categories:
|
||||||
category.append(categories[0])
|
category.append(categories[0])
|
||||||
if p_id is not None:
|
xml_id = 'module_category_' + ('_'.join(map(lambda x: x.lower(), category))).replace('&', 'and').replace(' ', '_')
|
||||||
cr.execute('SELECT id \
|
# search via xml_id (because some categories are renamed)
|
||||||
FROM ir_module_category \
|
cr.execute("SELECT res_id FROM ir_model_data WHERE name=%s AND module=%s AND model=%s",
|
||||||
WHERE name=%s AND parent_id=%s', (categories[0], p_id))
|
(xml_id, "base", "ir.module.category"))
|
||||||
else:
|
|
||||||
cr.execute('SELECT id \
|
|
||||||
FROM ir_module_category \
|
|
||||||
WHERE name=%s AND parent_id IS NULL', (categories[0],))
|
|
||||||
c_id = cr.fetchone()
|
c_id = cr.fetchone()
|
||||||
if not c_id:
|
if not c_id:
|
||||||
cr.execute('INSERT INTO ir_module_category \
|
cr.execute('INSERT INTO ir_module_category \
|
||||||
(name, parent_id) \
|
(name, parent_id) \
|
||||||
VALUES (%s, %s) RETURNING id', (categories[0], p_id))
|
VALUES (%s, %s) RETURNING id', (categories[0], p_id))
|
||||||
c_id = cr.fetchone()[0]
|
c_id = cr.fetchone()[0]
|
||||||
xml_id = 'module_category_' + ('_'.join(map(lambda x: x.lower(), category))).replace('&', 'and').replace(' ', '_')
|
|
||||||
cr.execute('INSERT INTO ir_model_data (module, name, res_id, model) \
|
cr.execute('INSERT INTO ir_model_data (module, name, res_id, model) \
|
||||||
VALUES (%s, %s, %s, %s)', ('base', xml_id, c_id, 'ir.module.category'))
|
VALUES (%s, %s, %s, %s)', ('base', xml_id, c_id, 'ir.module.category'))
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue