43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Copyright 2026 Nexa Systems Inc.
|
|
# License OPL-1 (Odoo Proprietary License v1.0)
|
|
"""Sort the Print-menu report bindings by `sequence`.
|
|
|
|
Odoo 19 returns `ir.actions.report` bindings in raw insertion order, which
|
|
pushes third-party reports to the bottom even when they are the primary
|
|
customer-facing document. Adding a sequence field and sorting inside
|
|
`ir.actions.actions._get_bindings` restores the expected ordering.
|
|
"""
|
|
from odoo import api, fields, models
|
|
from odoo.tools import frozendict
|
|
|
|
|
|
class IrActionsReport(models.Model):
|
|
_inherit = 'ir.actions.report'
|
|
|
|
sequence = fields.Integer(
|
|
default=100,
|
|
help='Order in which this report appears in the Print menu '
|
|
'(lower = higher in the list).',
|
|
)
|
|
|
|
|
|
class IrActionsActions(models.Model):
|
|
_inherit = 'ir.actions.actions'
|
|
|
|
@api.model
|
|
def _get_bindings(self, model_name):
|
|
result = super()._get_bindings(model_name)
|
|
if not result.get('report'):
|
|
return result
|
|
sorted_reports = tuple(sorted(
|
|
result['report'],
|
|
key=lambda vals: (
|
|
vals.get('sequence', 100),
|
|
(vals.get('name') or '').lower(),
|
|
),
|
|
))
|
|
new_result = dict(result)
|
|
new_result['report'] = sorted_reports
|
|
return frozendict(new_result)
|