[REM] base: remove column_format of Field class
The `column_format` of the `Field` class was unused and create useless noise in the ORM. Then remove it and simplify some flows. task-2735546 Part-of: odoo/odoo#82727
This commit is contained in:
committed by
Raphael Collet
parent
6000179384
commit
ae41be0c5c
@@ -60,8 +60,7 @@ class SaleOrder(models.Model):
|
||||
if value is not None:
|
||||
_logger.debug("Table '%s': setting default value of new column %s to %r",
|
||||
self._table, column_name, value)
|
||||
query = 'UPDATE "%s" SET "%s"=%s WHERE "%s" IS NULL' % (
|
||||
self._table, column_name, field.column_format, column_name)
|
||||
query = f'UPDATE "{self._table}" SET "{column_name}" = %s WHERE "{column_name}" IS NULL'
|
||||
self._cr.execute(query, (value,))
|
||||
|
||||
@api.depends('picking_ids.date_done')
|
||||
|
||||
@@ -1568,7 +1568,7 @@ class TestOne2many(TransactionCase):
|
||||
SELECT "res_partner_bank"."partner_id"
|
||||
FROM "res_partner_bank"
|
||||
WHERE ((
|
||||
"res_partner_bank"."id" IN (%s,%s,%s)
|
||||
"res_partner_bank"."id" IN %s
|
||||
) AND (
|
||||
"res_partner_bank"."sanitized_acc_number"::text LIKE %s
|
||||
))
|
||||
|
||||
@@ -3402,11 +3402,8 @@ class TestFieldParametersValidation(common.TransactionCase):
|
||||
def insert(model, *fnames):
|
||||
""" Return the expected query string to INSERT the given columns. """
|
||||
columns = sorted(fnames + ('create_uid', 'create_date', 'write_uid', 'write_date'))
|
||||
return 'INSERT INTO "{}" ({}) VALUES ({}) RETURNING id'.format(
|
||||
model._table,
|
||||
", ".join('"{}"'.format(column) for column in columns),
|
||||
", ".join('%s' for column in columns),
|
||||
)
|
||||
header = ", ".join(f'"{column}"' for column in columns)
|
||||
return f'INSERT INTO "{model._table}" ({header}) VALUES %s RETURNING id'
|
||||
|
||||
|
||||
def update(model, *fnames):
|
||||
|
||||
@@ -239,7 +239,6 @@ class Field(MetaField('DummyField', (object,), {})):
|
||||
translate = False # whether the field is translated
|
||||
|
||||
column_type = None # database column type (ident, spec)
|
||||
column_format = '%s' # placeholder for value in queries
|
||||
column_cast_from = () # column types that may be cast to this
|
||||
write_sequence = 0 # field ordering for write()
|
||||
|
||||
|
||||
+12
-18
@@ -2774,8 +2774,7 @@ class BaseModel(metaclass=MetaModel):
|
||||
if necessary:
|
||||
_logger.debug("Table '%s': setting default value of new column %s to %r",
|
||||
self._table, column_name, value)
|
||||
query = 'UPDATE "%s" SET "%s"=%s WHERE "%s" IS NULL' % (
|
||||
self._table, column_name, field.column_format, column_name)
|
||||
query = f'UPDATE "{self._table}" SET "{column_name}" = %s WHERE "{column_name}" IS NULL'
|
||||
self._cr.execute(query, (value,))
|
||||
|
||||
@ormcache()
|
||||
@@ -3940,7 +3939,7 @@ Fields:
|
||||
vals.setdefault('write_date', self.env.cr.now())
|
||||
|
||||
# determine SQL values
|
||||
columns = [] # list of (column_name, format, value)
|
||||
columns = {} # {column_name: value}
|
||||
|
||||
for name, val in sorted(vals.items()):
|
||||
if self._log_access and name in LOG_ACCESS_COLUMNS and not val:
|
||||
@@ -3952,14 +3951,13 @@ Fields:
|
||||
_logger.warning('Field %s is deprecated: %s', field, field.deprecated)
|
||||
|
||||
assert field.column_type
|
||||
columns.append((name, field.column_format, val))
|
||||
columns[name] = val
|
||||
|
||||
# update columns
|
||||
if columns:
|
||||
query = 'UPDATE "%s" SET %s WHERE id IN %%s' % (
|
||||
self._table, ','.join('"%s"=%s' % (column[0], column[1]) for column in columns),
|
||||
)
|
||||
params = [column[2] for column in columns]
|
||||
template = ', '.join(f'"{name}" = %s' for name in columns)
|
||||
query = f'UPDATE "{self._table}" SET {template} WHERE id IN %s'
|
||||
params = list(columns.values())
|
||||
for sub_ids in cr.split_for_in_conditions(set(self.ids)):
|
||||
cr.execute(query, params + [sub_ids])
|
||||
if cr.rowcount != len(sub_ids):
|
||||
@@ -4207,14 +4205,14 @@ Fields:
|
||||
for data in data_list:
|
||||
# determine column values
|
||||
stored = data['stored']
|
||||
columns = []
|
||||
columns = {}
|
||||
for name, val in sorted(stored.items()):
|
||||
field = self._fields[name]
|
||||
assert field.store
|
||||
|
||||
if field.column_type:
|
||||
col_val = field.convert_to_column(val, self, stored)
|
||||
columns.append((name, field.column_format, col_val))
|
||||
columns[name] = col_val
|
||||
if field.translate is True:
|
||||
translated_fields.add(field)
|
||||
else:
|
||||
@@ -4242,15 +4240,11 @@ Fields:
|
||||
#
|
||||
# That said, we haven't closed the door completely.
|
||||
if not columns: # Manage the case where we create empty record
|
||||
columns = [('id', '%s', psycopg2.extensions.AsIs('DEFAULT'))]
|
||||
columns = {'id': psycopg2.extensions.AsIs('DEFAULT')}
|
||||
|
||||
query = "INSERT INTO {} ({}) VALUES ({}) RETURNING id".format(
|
||||
quote(self._table),
|
||||
", ".join(quote(name) for name, fmt, val in columns),
|
||||
", ".join(fmt for name, fmt, val in columns),
|
||||
)
|
||||
params = [val for name, fmt, val in columns]
|
||||
cr.execute(query, params)
|
||||
header = ", ".join(quote(name) for name in columns)
|
||||
query = f'INSERT INTO "{self._table}" ({header}) VALUES %s RETURNING id'
|
||||
cr.execute(query, [tuple(columns.values())])
|
||||
ids.append(cr.fetchone()[0])
|
||||
|
||||
# put the new records in cache, and update inverse fields, for many2one
|
||||
|
||||
@@ -1018,13 +1018,11 @@ class expression(object):
|
||||
params = [it for it in right if it != False]
|
||||
check_null = len(params) < len(right)
|
||||
if params:
|
||||
if left == 'id':
|
||||
instr = ','.join(['%s'] * len(params))
|
||||
else:
|
||||
if left != 'id':
|
||||
field = model._fields[left]
|
||||
instr = ','.join([field.column_format] * len(params))
|
||||
params = [field.convert_to_column(p, model, validate=False) for p in params]
|
||||
query = '(%s."%s" %s (%s))' % (table_alias, left, operator, instr)
|
||||
query = f'({table_alias}."{left}" {operator} %s)'
|
||||
params = [tuple(params)]
|
||||
else:
|
||||
# The case for (left, 'in', []) or (left, 'not in', []).
|
||||
query = 'FALSE' if operator == 'in' else 'TRUE'
|
||||
@@ -1069,10 +1067,9 @@ class expression(object):
|
||||
sql_operator = {'=like': 'like', '=ilike': 'ilike'}.get(operator, operator)
|
||||
cast = '::text' if sql_operator.endswith('like') else ''
|
||||
|
||||
column_format = '%s' if need_wildcard else field.column_format
|
||||
unaccent = self._unaccent(field) if sql_operator.endswith('like') else lambda x: x
|
||||
column = '%s.%s' % (table_alias, _quote(left))
|
||||
query = '(%s %s %s)' % (unaccent(column + cast), sql_operator, unaccent(column_format))
|
||||
query = f'({unaccent(column + cast)} {sql_operator} {unaccent("%s")})'
|
||||
|
||||
if (need_wildcard and not right) or (right and operator in NEGATIVE_TERM_OPERATORS):
|
||||
query = '(%s OR %s."%s" IS NULL)' % (query, table_alias, left)
|
||||
|
||||
Reference in New Issue
Block a user