Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
3
maintenance_plan_activity/models/__init__.py
Normal file
3
maintenance_plan_activity/models/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from . import maintenance_plan
|
||||
from . import maintenance_equipment
|
||||
from . import maintenance_planned_activity
|
||||
40
maintenance_plan_activity/models/maintenance_equipment.py
Normal file
40
maintenance_plan_activity/models/maintenance_equipment.py
Normal file
@@ -0,0 +1,40 @@
|
||||
# Copyright 2019-20 ForgeFlow S.L. (https://www.forgeflow.com)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from datetime import timedelta
|
||||
|
||||
from odoo import _, models
|
||||
|
||||
|
||||
class MaintenanceEquipment(models.Model):
|
||||
_inherit = "maintenance.equipment"
|
||||
|
||||
def _prepare_new_request_activity_values(self, request, activity):
|
||||
"""Prepare the values to create a new mail.activity for a maintenance request
|
||||
created from a maintenance plan.
|
||||
"""
|
||||
return {
|
||||
"activity_type_id": activity.activity_type_id.id,
|
||||
"note": _("Activity automatically generated from maintenance plan"),
|
||||
"user_id": activity.user_id.id or self.env.user.id,
|
||||
"res_id": request.id,
|
||||
"res_model_id": self.env.ref("maintenance.model_maintenance_request").id,
|
||||
"date_deadline": request.schedule_date
|
||||
- timedelta(days=activity.date_before_request),
|
||||
}
|
||||
|
||||
def _create_new_request(self, maintenance_plan):
|
||||
new_requests = super()._create_new_request(maintenance_plan)
|
||||
for request in new_requests:
|
||||
for planned_activity in maintenance_plan.planned_activity_ids:
|
||||
# In case mail_activity_team is installed this makes sure
|
||||
# the correct activity team is selected. If that module is
|
||||
# not installed the context does nothing
|
||||
activity_data = self._prepare_new_request_activity_values(
|
||||
request, planned_activity
|
||||
)
|
||||
if activity_data:
|
||||
self.env["mail.activity"].with_context(
|
||||
default_res_model="maintenance.request"
|
||||
).create(activity_data)
|
||||
return new_requests
|
||||
14
maintenance_plan_activity/models/maintenance_plan.py
Normal file
14
maintenance_plan_activity/models/maintenance_plan.py
Normal file
@@ -0,0 +1,14 @@
|
||||
# Copyright 2019-20 ForgeFlow S.L. (https://www.forgeflow.com)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class MaintenancePlan(models.Model):
|
||||
_inherit = "maintenance.plan"
|
||||
|
||||
planned_activity_ids = fields.One2many(
|
||||
comodel_name="maintenance.planned.activity",
|
||||
inverse_name="maintenance_plan_id",
|
||||
string="Planned Activities",
|
||||
)
|
||||
@@ -0,0 +1,29 @@
|
||||
# Copyright 2019-20 ForgeFlow S.L. (https://www.forgeflow.com)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class MaintenancePlannedActivity(models.Model):
|
||||
_name = "maintenance.planned.activity"
|
||||
_description = "Maintenance Planned Activity"
|
||||
|
||||
activity_type_id = fields.Many2one(
|
||||
comodel_name="mail.activity.type",
|
||||
string="Activity Type",
|
||||
required=True,
|
||||
)
|
||||
user_id = fields.Many2one(
|
||||
comodel_name="res.users",
|
||||
string="Responsible",
|
||||
default=lambda self: self.env.user,
|
||||
)
|
||||
date_before_request = fields.Integer(
|
||||
string="# Days before request",
|
||||
help="This is the number of days the due date of the activity will be"
|
||||
"set before the Maintenance request scheduled date",
|
||||
)
|
||||
maintenance_plan_id = fields.Many2one(
|
||||
comodel_name="maintenance.plan",
|
||||
string="Maintenance Plan",
|
||||
)
|
||||
Reference in New Issue
Block a user