feat(fusion_accounting_assets): depreciation board line model

- period_index, scheduled_date, amount, accumulated, book_value_at_end
- is_posted / posted_date / move_id (set when engine posts the entry)
- action_post() marks the line as posted (idempotent)
- UNIQUE(asset_id, period_index) constraint via models.Constraint
- 5 new tests (52 total)

Made-with: Cursor
This commit is contained in:
gsinghpal
2026-04-19 16:56:47 -04:00
parent 70e4404d9b
commit 0439d81675
4 changed files with 95 additions and 9 deletions

View File

@@ -1,8 +1,4 @@
"""Per-period depreciation board lines for an asset.
Stub created with Task 8 (so fusion.asset One2many resolves). Fully
elaborated in Task 9.
"""
"""Per-period depreciation board lines for an asset."""
from odoo import fields, models
@@ -13,7 +9,34 @@ class FusionAssetDepreciationLine(models.Model):
_order = "asset_id, scheduled_date"
asset_id = fields.Many2one('fusion.asset', required=True, ondelete='cascade')
scheduled_date = fields.Date(required=True)
amount = fields.Monetary()
company_id = fields.Many2one(related='asset_id.company_id', store=True)
currency_id = fields.Many2one(related='asset_id.currency_id', store=True)
is_posted = fields.Boolean(default=False)
period_index = fields.Integer(required=True)
scheduled_date = fields.Date(required=True)
amount = fields.Monetary(required=True)
accumulated = fields.Monetary()
book_value_at_end = fields.Monetary()
is_posted = fields.Boolean(default=False, copy=False)
posted_date = fields.Date(copy=False)
move_id = fields.Many2one(
'account.move', copy=False,
help="Journal entry created when this line was posted.",
)
def action_post(self):
"""Mark this line as posted (without creating the journal entry yet —
engine method post_depreciation_entry handles the actual entry creation)."""
for line in self:
if line.is_posted:
continue
line.write({
'is_posted': True,
'posted_date': fields.Date.today(),
})
_unique_period_per_asset = models.Constraint(
'UNIQUE(asset_id, period_index)',
'A depreciation line for that period already exists.',
)