Files
Odoo-Modules/fusion_accounting_reports/wizards/period_picker_wizard.py
gsinghpal 8de4beb46a feat(fusion_accounting_reports): period picker wizard with common presets
Adds fusion.period.picker.wizard - a guided entry point that lets users
pick a report type and a common period preset (this/last month, quarter,
YTD, last year, or custom range). The wizard uses the existing date_periods
service helpers (month_bounds, quarter_bounds, fiscal_year_bounds) to
pre-fill date_from / date_to via @api.onchange.

action_open_report returns a client action that launches the OWL reports
viewer with default_report_type / default_date_from / default_date_to /
default_comparison in the context.

Tests: 3 new (test_period_picker.py). Net 111 -> 114.
Made-with: Cursor
2026-04-19 16:17:46 -04:00

78 lines
2.9 KiB
Python

"""Period selection + comparison wizard.
Pre-fills date ranges for common report periods (current month, YTD, etc.)."""
from datetime import timedelta
from odoo import api, fields, models
from ..services.date_periods import (
fiscal_year_bounds, month_bounds, quarter_bounds,
)
class FusionPeriodPickerWizard(models.TransientModel):
_name = "fusion.period.picker.wizard"
_description = "Period Selection Wizard"
report_type = fields.Selection([
('pnl', 'P&L'),
('balance_sheet', 'Balance Sheet'),
('trial_balance', 'Trial Balance'),
('general_ledger', 'General Ledger'),
], required=True, default='pnl')
period_preset = fields.Selection([
('this_month', 'This Month'),
('last_month', 'Last Month'),
('this_quarter', 'This Quarter'),
('last_quarter', 'Last Quarter'),
('this_year', 'This Year (YTD)'),
('last_year', 'Last Year'),
('custom', 'Custom Range'),
], default='this_month', required=True)
date_from = fields.Date()
date_to = fields.Date()
comparison = fields.Selection([
('none', 'No Comparison'),
('previous_period', 'Previous Period'),
('previous_year', 'Previous Year'),
], default='none')
@api.onchange('period_preset')
def _onchange_period_preset(self):
today = fields.Date.today()
if self.period_preset == 'this_month':
p = month_bounds(today)
self.date_from, self.date_to = p.date_from, p.date_to
elif self.period_preset == 'last_month':
p = month_bounds(today.replace(day=1) - timedelta(days=1))
self.date_from, self.date_to = p.date_from, p.date_to
elif self.period_preset == 'this_quarter':
p = quarter_bounds(today)
self.date_from, self.date_to = p.date_from, p.date_to
elif self.period_preset == 'last_quarter':
this_q = quarter_bounds(today)
p = quarter_bounds(this_q.date_from - timedelta(days=1))
self.date_from, self.date_to = p.date_from, p.date_to
elif self.period_preset == 'this_year':
p = fiscal_year_bounds(today)
self.date_from, self.date_to = p.date_from, today
elif self.period_preset == 'last_year':
last_year = today.replace(year=today.year - 1)
p = fiscal_year_bounds(last_year)
self.date_from, self.date_to = p.date_from, p.date_to
def action_open_report(self):
"""Open the fusion reports viewer pre-filled with selected period."""
self.ensure_one()
return {
'type': 'ir.actions.client',
'tag': 'fusion_reports',
'context': {
'default_report_type': self.report_type,
'default_date_from': str(self.date_from),
'default_date_to': str(self.date_to),
'default_comparison': self.comparison,
},
}