Exemplo n.º 1
0
    def init_models(self, cr, model_names, context):
        """ Initialize a list of models (given by their name). Call methods
            ``_auto_init`` and ``init`` on each model to create or update the
            database tables supporting the models.

            The ``context`` may contain the following items:
             - ``module``: the name of the module being installed/updated, if any;
             - ``update_custom_fields``: whether custom fields should be updated.
        """
        if 'module' in context:
            _logger.info('module %s: creating or updating database tables',
                         context['module'])

        env = odoo.api.Environment(cr, SUPERUSER_ID, context)
        models = [env[model_name] for model_name in model_names]

        for model in models:
            model._auto_init()
            model.init()

        while self._post_init_queue:
            func = self._post_init_queue.popleft()
            func()

        if models:
            models[0].recompute()
        cr.commit()

        # make sure all tables are present
        missing = [
            name for name, model in env.items()
            if not model._abstract and not table_exists(cr, model._table)
        ]
        if missing:
            _logger.warning("Models have no table: %s.", ", ".join(missing))
            # recreate missing tables following model dependencies
            deps = {name: model._depends for name, model in env.items()}
            for name in topological_sort(deps):
                if name in missing:
                    _logger.info("Recreate table of model %s.", name)
                    env[name].init()
            cr.commit()
            # check again, and log errors if tables are still missing
            for name, model in env.items():
                if not model._abstract and not table_exists(cr, model._table):
                    _logger.error("Model %s has no table.", name)
Exemplo n.º 2
0
 def _setup_base(self):
     super()._setup_base()
     name = 'old_id'
     if self._auto and name not in self._fields:
         field = fields.Integer(readonly=True)
         self._add_field(name, field)
         if tools.table_exists(self._cr, self._table):
             columns = tools.table_columns(self._cr, self._table)
             field.update_db_column(self, columns.get(name))
Exemplo n.º 3
0
    def _default_fiscal_dummy_id(self):
        if tools.table_exists(self.env.cr, "l10n_br_fiscal_document"):
            # happens during res.company#auto_init() when setting
            # the default fiscal_dummy_id value
            dummy_doc = self.env["l10n_br_fiscal.document"].search(
                self._fiscal_dummy_doc_domain(), limit=1)
        else:
            self.env["l10n_br_fiscal.document"]._auto_init()
            dummy_doc = False

        if not dummy_doc:
            if not tools.table_exists(self.env.cr,
                                      "l10n_br_fiscal_document_line"):
                self.env["l10n_br_fiscal.document.line"]._auto_init()

            dummy_doc = self.env["l10n_br_fiscal.document"].create(
                self._prepare_create_fiscal_dummy_doc())
        return dummy_doc
Exemplo n.º 4
0
    def init_models(self, cr, model_names, context):
        """ Initialize a list of models (given by their name). Call methods
            ``_auto_init`` and ``init`` on each model to create or update the
            database tables supporting the models.

            The ``context`` may contain the following items:
             - ``module``: the name of the module being installed/updated, if any;
             - ``update_custom_fields``: whether custom fields should be updated.
        """
        if 'module' in context:
            _logger.info('module %s: creating or updating database tables', context['module'])

        env = odoo.api.Environment(cr, SUPERUSER_ID, context)
        models = [env[model_name] for model_name in model_names]

        for model in models:
            model._auto_init()
            model.init()

        while self._post_init_queue:
            func = self._post_init_queue.popleft()
            func()

        if models:
            models[0].recompute()
        cr.commit()

        # make sure all tables are present
        missing = [name
                   for name, model in env.items()
                   if not model._abstract and not table_exists(cr, model._table)]
        if missing:
            _logger.warning("Models have no table: %s.", ", ".join(missing))
            # recreate missing tables following model dependencies
            deps = {name: model._depends for name, model in env.items()}
            for name in topological_sort(deps):
                if name in missing:
                    _logger.info("Recreate table of model %s.", name)
                    env[name].init()
            cr.commit()
            # check again, and log errors if tables are still missing
            for name, model in env.items():
                if not model._abstract and not table_exists(cr, model._table):
                    _logger.error("Model %s has no table.", name)
Exemplo n.º 5
0
def drop_table_model_company_country(cr):
    tablename = "company_country_config_settings"
    if tools.table_exists(cr, tablename):
        _logger.info("Dropping table %s", tablename)
        cr.execute("DROP TABLE IF EXISTS %s;", (AsIs(tablename), ))