140 lines
5.4 KiB
Python
140 lines
5.4 KiB
Python
from odoo import api, SUPERUSER_ID
|
|
|
|
|
|
def post_init_hook(env_or_cr, registry=None):
|
|
if registry is not None:
|
|
env = api.Environment(env_or_cr, SUPERUSER_ID, {})
|
|
else:
|
|
env = env_or_cr
|
|
OperatingSystemSetup(env).run()
|
|
|
|
|
|
class OperatingSystemSetup:
|
|
def __init__(self, env):
|
|
self.env = env
|
|
self.Partner = env["res.partner"].sudo()
|
|
self.Project = env["project.project"].sudo()
|
|
|
|
def run(self):
|
|
self._ensure_active_portfolio()
|
|
self._ensure_followup_cron_active()
|
|
|
|
def _ensure_active_portfolio(self):
|
|
specs = {
|
|
"ClicksToCart": [
|
|
("ERP Implementation", "fixed_project"),
|
|
("App Development", "fixed_project"),
|
|
("Social Media Handling", "recurring"),
|
|
],
|
|
"Wallaceton": [
|
|
("SEO", "recurring"),
|
|
("Social Media Handling", "recurring"),
|
|
("Ads Management", "recurring"),
|
|
],
|
|
"Maison de Treats": [("Social Media Handling", "recurring")],
|
|
"Lens and Frames": [
|
|
("SEO", "recurring"),
|
|
("Social Media Handling", "recurring"),
|
|
("Ads Management", "recurring"),
|
|
],
|
|
"TNCSC": [
|
|
("Ads Management", "recurring"),
|
|
("Videos", "fixed_project"),
|
|
("ERP", "fixed_project"),
|
|
],
|
|
"Infini": [("Social Media Handling", "recurring")],
|
|
"Organic Healthy Family": [("Shopify Store Development", "fixed_project")],
|
|
"Hondavert": [
|
|
("Website Development", "fixed_project"),
|
|
("App Development", "fixed_project"),
|
|
],
|
|
"RaceNation": [("Website Development", "fixed_project")],
|
|
"Racewerks": [("Website Development", "fixed_project")],
|
|
"Internal": [
|
|
("Shopify App for Revenue Generation", "internal_product"),
|
|
("Custom Product Development", "internal_r_and_d"),
|
|
],
|
|
}
|
|
for account_name, workstreams in specs.items():
|
|
partner = self._ensure_client_account(account_name)
|
|
for workstream, delivery_type in workstreams:
|
|
self._ensure_project(partner, workstream, delivery_type)
|
|
|
|
def _ensure_client_account(self, name):
|
|
partner = self.Partner.search([("name", "=", name)], limit=1)
|
|
if not partner:
|
|
partner = self.Partner.create(
|
|
{
|
|
"name": name,
|
|
"company_type": "company",
|
|
"mcs_is_client_account": True,
|
|
"mcs_account_status": "active",
|
|
}
|
|
)
|
|
else:
|
|
values = {}
|
|
if not partner.mcs_is_client_account:
|
|
values["mcs_is_client_account"] = True
|
|
if not partner.mcs_account_status:
|
|
values["mcs_account_status"] = "active"
|
|
if values:
|
|
partner.write(values)
|
|
return partner
|
|
|
|
def _ensure_project(self, partner, workstream, delivery_type):
|
|
project_name = "%s - %s" % (partner.name, workstream)
|
|
project = self.Project.search([("name", "=", project_name)], limit=1)
|
|
if not project:
|
|
project = self.Project.create(
|
|
{
|
|
"name": project_name,
|
|
"partner_id": partner.id if partner.name != "Internal" else False,
|
|
"allow_timesheets": True,
|
|
"allow_milestones": True,
|
|
"mcs_delivery_type": delivery_type,
|
|
"mcs_initiative_type": self._initiative_type(delivery_type),
|
|
"mcs_classification": "active"
|
|
if delivery_type != "internal_r_and_d"
|
|
else "parked",
|
|
"mcs_revenue_connected": delivery_type
|
|
not in ("internal_product", "internal_r_and_d", "sales_initiative"),
|
|
"mcs_next_action": "Confirm owner, target, scope, and next milestone.",
|
|
"mcs_next_milestone": "Operating setup",
|
|
}
|
|
)
|
|
return project
|
|
|
|
values = {}
|
|
if not project.partner_id and partner.name != "Internal":
|
|
values["partner_id"] = partner.id
|
|
if not project.mcs_delivery_type:
|
|
values["mcs_delivery_type"] = delivery_type
|
|
if not project.mcs_initiative_type:
|
|
values["mcs_initiative_type"] = self._initiative_type(delivery_type)
|
|
if not project.mcs_next_action:
|
|
values["mcs_next_action"] = "Confirm owner, target, scope, and next milestone."
|
|
if not project.mcs_next_milestone:
|
|
values["mcs_next_milestone"] = "Operating setup"
|
|
if values:
|
|
project.write(values)
|
|
return project
|
|
|
|
def _initiative_type(self, delivery_type):
|
|
mapping = {
|
|
"recurring": "client",
|
|
"fixed_project": "client",
|
|
"internal_product": "product",
|
|
"internal_r_and_d": "internal",
|
|
"sales_initiative": "sales",
|
|
"internal_operations": "internal",
|
|
}
|
|
return mapping.get(delivery_type, "client")
|
|
|
|
def _ensure_followup_cron_active(self):
|
|
cron = self.env.ref(
|
|
"mcs_operating_system.ir_cron_mcs_schedule_missing_followups",
|
|
raise_if_not_found=False,
|
|
)
|
|
if cron and not cron.active:
|
|
cron.sudo().write({"active": True})
|