def _auto_init(self): """Initialize the columns in dB and Create the GIST index only create and update supported We override the base methid because creation of fields in DB is not actually delegated to the field it self but to the ORM _auto_init function """ cr = self._cr geo_fields = {} for f_name, field in self._fields.items(): if field.type.startswith('geo_'): geo_fields[f_name] = field res = super(GeoModel, self)._auto_init() column_data = tools.table_columns(cr, self._table) for f_name, geo_field in geo_fields.items(): if geo_field.compute and not geo_field.store: continue fct = geo_field.create_geo_column if f_name in column_data: fct = geo_field.update_geo_column fct(cr, f_name, self._table, self._name) return res
def check_manual_fields(self, model): # check the fields we need are defined on self, to stop it going # early on install / startup - particularly problematic during upgrade if "group_operator" in table_columns( self.env.cr, "bi_sql_view_field") and model._name.startswith( self._model_prefix): # Use SQL instead of ORM, as ORM might not be fully initialised - # we have no control over the order that fields are defined! # We are not concerned about user security rules. self.env.cr.execute( """ SELECT f.name, f.ttype, f.group_operator FROM bi_sql_view v LEFT JOIN bi_sql_view_field f ON f.bi_sql_view_id = v.id WHERE v.model_name = %s ; """, (model._name, ), ) sql_fields = self.env.cr.fetchall() for sql_field in sql_fields: if (sql_field[0] in model._fields and sql_field[1] in ("integer", "float") and sql_field[2]): model._fields[sql_field[0]].group_operator = sql_field[2]
def _register_hook(self): columns = tools.table_columns(self._cr, self._table) if 'first_name' not in columns: tools.create_column(self._cr, self._table, 'first_name', 'VARCHAR') if 'last_name' not in columns: tools.create_column(self._cr, self._table, 'last_name', 'VARCHAR') if 'middle_name' not in columns: tools.create_column(self._cr, self._table, 'middle_name', 'VARCHAR') if 'nickname' not in columns: tools.create_column(self._cr, self._table, 'nickname', 'VARCHAR') if 'work_location_text' not in columns: tools.create_column(self._cr, self._table, 'work_location_text', 'VARCHAR') if 'start_date' not in columns: tools.create_column(self._cr, self._table, 'start_date', 'DATE') if 'bio' not in columns: tools.create_column(self._cr, self._table, 'bio', 'TEXT') if 'new_work_email' not in columns: tools.create_column(self._cr, self._table, 'new_work_email', 'VARCHAR') if 'fully_vaccinated' not in columns: tools.create_column(self._cr, self._table, 'fully_vaccinated', 'BOOLEAN') if 'pre_check_tsa' not in columns: tools.create_column(self._cr, self._table, 'pre_check_tsa', 'VARCHAR') if 'seat_preference' not in columns: tools.create_column(self._cr, self._table, 'seat_preference', 'VARCHAR') return super(Employee, self)._register_hook()
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))
def _register_hook(self): columns = tools.table_columns(self._cr, self._table) if 'mail_domain' not in columns: tools.create_column(self._cr, self._table, 'mail_domain', 'CHAR')