Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Why two identical blocks of code in _module_data_uninstall ?

By
yassine chaouche
on 3/2/14, 4:55 PM 557 views

This is from file openerp/addons/base/ir/ir_model.py, openerp 7.0, method _module_data_uninstall

        if typ == 'f':
            # test if FK exists on this table (it could be on a related m2m table, in which case we ignore it)
            cr.execute("""SELECT 1 from pg_constraint cs JOIN pg_class cl ON (cs.conrelid = cl.oid)
                          WHERE cs.contype=%s and cs.conname=%s and cl.relname=%s""", ('f', name, model_obj._table))
            if cr.fetchone():
                cr.execute('ALTER TABLE "%s" DROP CONSTRAINT "%s"' % (model_obj._table, name),)
                _logger.info('Dropped FK CONSTRAINT %s@%s', name, model)

        if typ == 'u':
            # test if constraint exists
            cr.execute("""SELECT 1 from pg_constraint cs JOIN pg_class cl ON (cs.conrelid = cl.oid)
                          WHERE cs.contype=%s and cs.conname=%s and cl.relname=%s""", ('u', name, model_obj._table))
            if cr.fetchone():
                cr.execute('ALTER TABLE "%s" DROP CONSTRAINT "%s"' % (model_obj._table, name),)
                _logger.info('Dropped CONSTRAINT %s@%s', name, model)

The code for typ == 'u' is identical to typ == 'f'.

Any particular reasons to have this distinction ?

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 3/2/14, 4:55 PM
Seen: 557 times
Last updated: 3/16/15, 8:10 AM