99 lines
3.5 KiB
Python
99 lines
3.5 KiB
Python
from odoo import api, fields, models
|
|
|
|
|
|
class ResPartner(models.Model):
|
|
_inherit = "res.partner"
|
|
|
|
mcs_is_client_account = fields.Boolean(string="MCS Client Account", tracking=True)
|
|
mcs_account_status = fields.Selection(
|
|
[
|
|
("active", "Active"),
|
|
("watch", "Watch"),
|
|
("paused", "Paused"),
|
|
("completed", "Completed"),
|
|
("lost", "Lost"),
|
|
],
|
|
string="Account Status",
|
|
default="active",
|
|
tracking=True,
|
|
)
|
|
mcs_account_health = fields.Selection(
|
|
[
|
|
("healthy", "Healthy"),
|
|
("watch", "Watch"),
|
|
("at_risk", "At Risk"),
|
|
("blocked", "Blocked"),
|
|
("completed", "Completed"),
|
|
],
|
|
string="Account Health",
|
|
compute="_compute_mcs_account_metrics",
|
|
store=True,
|
|
tracking=True,
|
|
)
|
|
mcs_currency_id = fields.Many2one(
|
|
"res.currency",
|
|
string="MCS Currency",
|
|
default=lambda self: self.env.company.currency_id,
|
|
)
|
|
mcs_monthly_revenue = fields.Monetary(
|
|
string="Monthly Revenue",
|
|
currency_field="mcs_currency_id",
|
|
compute="_compute_mcs_account_metrics",
|
|
store=True,
|
|
)
|
|
mcs_contracted_value = fields.Monetary(
|
|
string="Contracted Value",
|
|
currency_field="mcs_currency_id",
|
|
compute="_compute_mcs_account_metrics",
|
|
store=True,
|
|
)
|
|
mcs_monthly_hours = fields.Float(
|
|
string="Monthly Hours",
|
|
compute="_compute_mcs_account_metrics",
|
|
store=True,
|
|
)
|
|
mcs_effective_hourly_revenue = fields.Monetary(
|
|
string="Effective Hourly Revenue",
|
|
currency_field="mcs_currency_id",
|
|
compute="_compute_mcs_account_metrics",
|
|
store=True,
|
|
)
|
|
mcs_account_owner_id = fields.Many2one(
|
|
"res.users", string="Account Owner", tracking=True
|
|
)
|
|
mcs_next_account_action = fields.Char(string="Next Account Action", tracking=True)
|
|
mcs_account_risk_reason = fields.Text(string="Account Risk Reason", tracking=True)
|
|
mcs_project_ids = fields.One2many(
|
|
"project.project", "partner_id", string="MCS Workstreams"
|
|
)
|
|
|
|
@api.depends(
|
|
"mcs_project_ids.mcs_monthly_revenue_target",
|
|
"mcs_project_ids.mcs_contracted_revenue",
|
|
"mcs_project_ids.mcs_actual_hours",
|
|
"mcs_project_ids.mcs_portfolio_health",
|
|
"mcs_project_ids.active",
|
|
)
|
|
def _compute_mcs_account_metrics(self):
|
|
for partner in self:
|
|
projects = partner.mcs_project_ids.filtered(lambda project: project.active)
|
|
partner.mcs_monthly_revenue = sum(projects.mapped("mcs_monthly_revenue_target"))
|
|
partner.mcs_contracted_value = sum(projects.mapped("mcs_contracted_revenue"))
|
|
partner.mcs_monthly_hours = sum(projects.mapped("mcs_actual_hours"))
|
|
partner.mcs_effective_hourly_revenue = (
|
|
partner.mcs_monthly_revenue / partner.mcs_monthly_hours
|
|
if partner.mcs_monthly_hours
|
|
else 0
|
|
)
|
|
health_values = set(projects.mapped("mcs_portfolio_health"))
|
|
if "blocked" in health_values:
|
|
partner.mcs_account_health = "blocked"
|
|
elif "at_risk" in health_values:
|
|
partner.mcs_account_health = "at_risk"
|
|
elif "watch" in health_values:
|
|
partner.mcs_account_health = "watch"
|
|
elif projects and health_values == {"completed"}:
|
|
partner.mcs_account_health = "completed"
|
|
else:
|
|
partner.mcs_account_health = "healthy"
|