Skip to content

Commit e562fc7

Browse files
committed
[MIG] database_size: Migration to 19.0
- read_group override → _read_group (19.0 deprecated public read_group + web no longer routes through it). New signature (groupby/aggregates/having/order); still defaults the group order for the report views. - search view: dropped `expand`/`string` from the Group By <group> (19.0 RelaxNG rejects them on search-view groups). - _sql_constraints → models.Constraint (kept uniq_model_measurement_date name). - report: f-strings inside self.env._() → %(name)s placeholders (19.0 pylint translation-fstring-interpolation). - _compute_model_name: justified `# pylint: disable=no-search-all` (small ir.model registry load). Signed-off-by: Don Kendall <dkendall@ledoweb.com>
1 parent 4a93e54 commit e562fc7

3 files changed

Lines changed: 37 additions & 28 deletions

File tree

database_size/models/ir_model_size.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@ class IrModelSize(models.Model):
1313
_description = "Disk space usage per model"
1414
_order = "measurement_date desc, total_model_size desc"
1515
_rec_name = "model"
16-
_sql_constraints = [
17-
(
18-
"uniq_model_measurement_date",
19-
"unique(model, measurement_date)",
20-
"There is already a measurement for this model on the given date",
21-
),
22-
]
16+
_uniq_model_measurement_date = models.Constraint(
17+
"unique(model, measurement_date)",
18+
"There is already a measurement for this model on the given date",
19+
)
2320
model = fields.Char(index=True)
2421
model_name = fields.Char(
2522
compute="_compute_model_name",
@@ -84,32 +81,40 @@ class IrModelSize(models.Model):
8481
def _compute_model_name(self):
8582
"""Assign the model's label"""
8683
model2name = {
87-
model.model: model.name for model in self.env["ir.model"].sudo().search([])
84+
model.model: model.name
85+
for model in self.env["ir.model"].sudo().search([]) # pylint: disable=no-search-all
8886
}
8987
for size in self:
9088
size.model_name = model2name.get(size.model, "<removed>")
9189

9290
@api.model
93-
def read_group(
94-
self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True
91+
def _read_group(
92+
self,
93+
domain,
94+
groupby=(),
95+
aggregates=(),
96+
having=(),
97+
offset=0,
98+
limit=None,
99+
order=None,
95100
):
96101
"""Enforce that grouped results are ordered.
97102
98-
Odoo will happily use the grouping field for ordering unless groupby is a
99-
list, and as it happens the grouping is usually passed as a list, for
100-
example: ['measurement_date:day']
103+
When the caller doesn't pass an explicit order, default to the first
104+
groupby field descending (e.g. ['measurement_date:day']) so the
105+
size-report views stay sorted.
101106
"""
102-
if not orderby and groupby and isinstance(groupby, list | set):
107+
if not order and groupby:
103108
field = groupby[0].split(":")[0]
104-
orderby = f"{field} desc"
105-
return super().read_group(
109+
order = f"{field} desc"
110+
return super()._read_group(
106111
domain,
107-
fields,
108112
groupby,
113+
aggregates,
114+
having,
109115
offset=offset,
110116
limit=limit,
111-
orderby=orderby,
112-
lazy=lazy,
117+
order=order,
113118
)
114119

115120
@api.depends(

database_size/report/ir_model_size_report.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,21 @@ def _move_dates_to_context(self, domain):
8585
if field in values:
8686
raise UserError(
8787
self.env._(
88-
f"You cannot search on more than one value for {field} "
89-
"at the same time."
88+
"You cannot search on more than one value for"
89+
" %(field)s at the same time.",
90+
field=field,
9091
)
9192
)
9293
if clause[1] in ("=", "==") and clause[2]:
9394
values[field] = clause[2]
9495
else:
9596
raise UserError(
9697
self.env._(
97-
f"Searching {field} for '{clause[1]} {clause[2]}' is "
98-
"not supported."
98+
"Searching %(field)s for '%(operator)s %(value)s'"
99+
" is not supported.",
100+
field=field,
101+
operator=clause[1],
102+
value=clause[2],
99103
)
100104
)
101105
new_domain.append((1, "=", 1))
@@ -138,8 +142,8 @@ def _table_query(self):
138142
):
139143
raise UserError(
140144
self.env._(
141-
"There is no data from "
142-
f"{fields.Date.to_string(measurement_date)}"
145+
"There is no data from %(date)s",
146+
date=fields.Date.to_string(measurement_date),
143147
)
144148
)
145149
else:
@@ -165,8 +169,8 @@ def _table_query(self):
165169
):
166170
raise UserError(
167171
self.env._(
168-
"There is no data from "
169-
f"{fields.Date.to_string(historical_measurement_date)}"
172+
"There is no data from %(date)s",
173+
date=fields.Date.to_string(historical_measurement_date),
170174
)
171175
)
172176
else:

database_size/views/ir_model_size_views.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<field name="arch" type="xml">
66
<search>
77
<field name="model" />
8-
<group expand="0" string="Group By">
8+
<group>
99
<filter
1010
string="Date of Measurement"
1111
name="group_measurement_date"

0 commit comments

Comments
 (0)