feat(fusion_accounting_assets): depreciation run wizard

Made-with: Cursor
This commit is contained in:
gsinghpal
2026-04-19 20:06:25 -04:00
parent 92f445eb8f
commit 3efef7efc7
7 changed files with 156 additions and 1 deletions

View File

@@ -1,3 +1,4 @@
from . import create_asset_wizard
from . import disposal_wizard
from . import partial_sale_wizard
from . import depreciation_run_wizard

View File

@@ -0,0 +1,72 @@
"""Manual depreciation run wizard.
Operator picks a period_date and the wizard posts all running assets'
unposted lines whose scheduled_date <= period_date."""
from odoo import fields, models
class FusionDepreciationRunWizard(models.TransientModel):
_name = "fusion.depreciation.run.wizard"
_description = "Manual Depreciation Run Wizard"
period_date = fields.Date(
required=True, default=fields.Date.today,
help="Post all unposted lines whose scheduled_date is on or before this date.",
)
state_filter = fields.Selection([
('all_running', 'All Running Assets'),
('selected', 'Selected Asset(s) Only'),
], default='all_running', required=True)
asset_ids = fields.Many2many(
'fusion.asset', domain=[('state', '=', 'running')],
)
state = fields.Selection(
[('draft', 'Draft'), ('done', 'Done')], default='draft',
)
posted_count = fields.Integer(readonly=True)
skipped_count = fields.Integer(readonly=True)
error_count = fields.Integer(readonly=True)
summary = fields.Text(readonly=True)
def action_run(self):
self.ensure_one()
if self.state_filter == 'all_running':
assets = self.env['fusion.asset'].search([
('state', '=', 'running'),
('company_id', '=', self.env.company.id),
])
else:
assets = self.asset_ids
engine = self.env['fusion.asset.engine']
posted = 0
skipped = 0
errors = []
for asset in assets:
try:
with self.env.cr.savepoint():
result = engine.post_depreciation_entry(
asset, period_date=self.period_date,
)
posted += result.get('posted_count', 0)
if result.get('posted_count', 0) == 0:
skipped += 1
except Exception as e: # noqa: BLE001
errors.append(f"{asset.name}: {e}")
self.write({
'state': 'done',
'posted_count': posted,
'skipped_count': skipped,
'error_count': len(errors),
'summary': '\n'.join(errors[:20]) if errors else False,
})
return {
'type': 'ir.actions.act_window',
'res_model': self._name,
'res_id': self.id,
'view_mode': 'form',
'target': 'new',
}

View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_fusion_depreciation_run_wizard_form" model="ir.ui.view">
<field name="name">fusion.depreciation.run.wizard.form</field>
<field name="model">fusion.depreciation.run.wizard</field>
<field name="arch" type="xml">
<form string="Run Depreciation">
<group invisible="state == 'done'">
<field name="period_date"/>
<field name="state_filter" widget="radio"/>
<field name="asset_ids" widget="many2many_tags"
invisible="state_filter != 'selected'"/>
</group>
<group invisible="state != 'done'" string="Results">
<field name="posted_count"/>
<field name="skipped_count"/>
<field name="error_count"/>
<field name="summary"/>
</group>
<field name="state" invisible="1"/>
<footer>
<button name="action_run" type="object" string="Run"
class="btn-primary" invisible="state == 'done'"/>
<button special="cancel" string="Close"/>
</footer>
</form>
</field>
</record>
<record id="action_fusion_depreciation_run_wizard" model="ir.actions.act_window">
<field name="name">Run Depreciation</field>
<field name="res_model">fusion.depreciation.run.wizard</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</odoo>