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
This commit is contained in:
@@ -1 +1,2 @@
|
||||
from . import xlsx_export_wizard
|
||||
from . import period_picker_wizard
|
||||
|
||||
77
fusion_accounting_reports/wizards/period_picker_wizard.py
Normal file
77
fusion_accounting_reports/wizards/period_picker_wizard.py
Normal file
@@ -0,0 +1,77 @@
|
||||
"""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,
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record id="view_fusion_period_picker_wizard_form" model="ir.ui.view">
|
||||
<field name="name">fusion.period.picker.wizard.form</field>
|
||||
<field name="model">fusion.period.picker.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Pick Reporting Period">
|
||||
<group>
|
||||
<field name="report_type"/>
|
||||
<field name="period_preset"/>
|
||||
<field name="date_from" invisible="period_preset != 'custom'"
|
||||
required="period_preset == 'custom'"/>
|
||||
<field name="date_to" invisible="period_preset != 'custom'"
|
||||
required="period_preset == 'custom'"/>
|
||||
<field name="comparison"/>
|
||||
</group>
|
||||
<footer>
|
||||
<button name="action_open_report" type="object" string="Open Report"
|
||||
class="btn-primary"/>
|
||||
<button special="cancel" string="Cancel"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_fusion_period_picker_wizard" model="ir.actions.act_window">
|
||||
<field name="name">Open Financial Report</field>
|
||||
<field name="res_model">fusion.period.picker.wizard</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user