Add timesheet / AI-audit time tracking (wraps account.analytic.line)

- fl.timesheet via delegation inheritance on account.analytic.line so billable
  hours flow through standard Odoo Accounting; duration_hours maps to unit_amount
- Fields: case_id, employee_id, is_billable, ai_agent, duration_hours, computed
  hourly_rate/billable_amount (rate from hr.employee.fl_hourly_rate, else firm
  default ir.config_parameter fl_timesheet.default_hourly_rate)
- _resolve_analytic_account: prefers the case project's analytic account
  (version-agnostic field lookup), falls back to a cached firm account under any
  available analytic plan — handles the required account_id on the wrapped line
- Add 'analytic' to manifest depends; ACL for fl.timesheet and account.analytic.line
  (admin + paralegal) so non-admins can post entries
- fl.case: timesheet_ids + total_billable_hours/amount + total_ai_audit_hours +
  currency_id; new Time & Billing tab; Timesheets menu + standalone views
- Both AI agents now log non-billable audit entries via sudo() (paralegal +
  attorney, ai_agent set); logging stays a guarded no-op if creation fails

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-29 00:26:00 +00:00
parent 465c049251
commit 70c951a7ef
10 changed files with 315 additions and 1 deletions

View File

@@ -472,6 +472,28 @@ class FlCase(models.Model):
compute='_compute_total_expenses', store=True
)
# ══════════════════════════════════════════════════════════════════════
# TIME & BILLING
# ══════════════════════════════════════════════════════════════════════
currency_id = fields.Many2one(
'res.currency', string='Currency',
default=lambda self: self.env.company.currency_id
)
timesheet_ids = fields.One2many(
'fl.timesheet', 'case_id', string='Timesheet Entries'
)
total_billable_hours = fields.Float(
string='Billable Hours', compute='_compute_timesheet_totals'
)
total_billable_amount = fields.Monetary(
string='Billable Amount', compute='_compute_timesheet_totals',
currency_field='currency_id'
)
total_ai_audit_hours = fields.Float(
string='AI Audit Hours', compute='_compute_timesheet_totals'
)
# ══════════════════════════════════════════════════════════════════════
# POST-ORDER
# ══════════════════════════════════════════════════════════════════════
@@ -804,6 +826,22 @@ class FlCase(models.Model):
for rec in self:
rec.total_expenses = sum(rec.expense_ids.mapped('total_amount'))
@api.depends(
'timesheet_ids.duration_hours',
'timesheet_ids.is_billable',
'timesheet_ids.billable_amount',
'timesheet_ids.ai_agent',
)
def _compute_timesheet_totals(self):
for rec in self:
billable = rec.timesheet_ids.filtered(lambda t: t.is_billable)
rec.total_billable_hours = sum(billable.mapped('duration_hours'))
rec.total_billable_amount = sum(billable.mapped('billable_amount'))
rec.total_ai_audit_hours = sum(
rec.timesheet_ids.filtered(lambda t: t.ai_agent)
.mapped('duration_hours')
)
@api.depends('filing_date')
def _compute_retroactivity_date(self):
"""