Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][IMP] oxigen_maintenance: don't duplicate project and add a delete restriction to the parent equipment #154

Open
wants to merge 1 commit into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions oxigen_maintenance/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"maintenance_equipment_hierarchy",
"maintenance_team_hierarchy",
"base_maintenance_group",
"maintenance_project",
],
"installable": True,
"license": "AGPL-3",
Expand Down
20 changes: 15 additions & 5 deletions oxigen_maintenance/i18n/es.po
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * oxigen_maintenance
# * oxigen_maintenance
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-11-24 09:57+0000\n"
"PO-Revision-Date: 2021-11-24 09:57+0000\n"
"Last-Translator: <>\n"
"POT-Creation-Date: 2024-08-09 16:21+0000\n"
"PO-Revision-Date: 2024-08-09 16:21+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand Down Expand Up @@ -52,6 +52,16 @@ msgstr "Equipo de Mantenimiento"
msgid "Unspecified kind"
msgstr "Tipo sin especificar"

#. module: oxigen_maintenance
#: code:addons/oxigen_maintenance/models/maintenance_equipment.py:0
#, python-format
msgid ""
"Cannot create a new project for this equipment because it is already linked "
"to a project."
msgstr ""
"No se puede crear un nuevo proyecto para este equipo porque ya está vinculado "
"a un proyecto."

#. module: oxigen_maintenance
#: model:ir.model.fields,field_description:oxigen_maintenance.field_maintenance_plan_employee_id
#: model:ir.ui.view,arch_db:oxigen_maintenance.maintenance_request_view_form_inherit
Expand Down
71 changes: 71 additions & 0 deletions oxigen_maintenance/models/maintenance_equipment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)

from odoo import _, fields, models
from odoo.exceptions import ValidationError


class MaintenanceEquipment(models.Model):
Expand Down Expand Up @@ -86,6 +87,17 @@ def _compute_my_team_equipment(self):
selection_add=[("customer", "Customer")], ondelete={"customer": "set default"}
)
customer_id = fields.Many2one("res.partner")
parent_id = fields.Many2one(
"maintenance.equipment",
"Parent Equipment",
index=True,
ondelete="restrict",
tracking=True,
)
create_project_from_equipment = fields.Boolean(default=False, copy=False)
project_id = fields.Many2one(
comodel_name="project.project", ondelete="restrict", copy=False
)

def _prepare_request_from_plan(self, maintenance_plan, next_maintenance_date):

Expand All @@ -99,3 +111,62 @@ def _prepare_request_from_plan(self, maintenance_plan, next_maintenance_date):
res["employee_id"] = maintenance_plan.employee_id.id

return res

# def check_create_project_from_equipment_restrictions(self):
# """
# (
# old - create_project_from_equipment,
# old - project_id,
# new - create_project_from_equipment,
# new - project_id,
# )
# """
# return {
# (False, False, True, True): True,
# (False, True, True, True or False): True,
# (True, False, True, True): True,
# (True, True, True, False): True,
# }

def write(self, values):
# key = (
# self.create_project_from_equipment,
# self.project_id,
# values.get("create_project_from_equipment", None),
# values.get("project_id", None)
# )
# maintenance_error = (
# self.check_create_project_from_equipment_restrictions().get(key, False)
# )
# if maintenance_error:
# if "project_id" in values:
# if self.project_id == values["project_id"]:
# maintenance_error = False
# if maintenance_error:
# raise ValidationError(
# _(
# "You can't change the project of the equipment because "
# "it would generate inconsistencies."
# )
# )
if values.get("create_project_from_equipment"):
if self.env["project.project"].search_count(
[("equipment_ids", "in", self.id)]
):
raise ValidationError(
_(
"Cannot create a new project for this equipment because it "
"is already linked to a project."
)
)
new_project = self.env["project.project"].create(
self._prepare_project_from_equipment_values(values)
)
values["project_id"] = new_project.id
return super().write(values)

def _prepare_project_from_equipment_values(self, values):
res = super()._prepare_project_from_equipment_values(values)
if self.name:
res["name"] = self.name
return res
10 changes: 10 additions & 0 deletions oxigen_maintenance/views/maintenance_equipment_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@
</notebook>
</field>
</record>
<record id="project_hr_equipment_view_form" model="ir.ui.view">
<field name="name">equipment.form</field>
<field name="model">maintenance.equipment</field>
<field name="inherit_id" ref="maintenance_project.hr_equipment_view_form" />
<field name="arch" type="xml">
<field name="create_project_from_equipment" position="attributes">
<attribute name="attrs" />
</field>
</field>
</record>

<record id="maintenance_equipment_view_form_inherit_hr" model="ir.ui.view">
<field name="name">equipment.form</field>
Expand Down
Loading