Skip to content

Commit 52b1443

Browse files
[MIG] maintenance_plan: Migration to 19.0
1 parent aa905b2 commit 52b1443

File tree

12 files changed

+70
-81
lines changed

12 files changed

+70
-81
lines changed

maintenance_plan/README.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Maintenance Plan
1111
!! This file is generated by oca-gen-addon-readme !!
1212
!! changes will be overwritten. !!
1313
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
14-
!! source digest: sha256:222d80cfe136b8eb3f8e49710a9b76fdb27647e87145a28bfc621253f3581a22
14+
!! source digest: sha256:cd21f05e56ccccd12e88d22a3009fd970401a379a695813d5815b03ed56303a2
1515
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1616
1717
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
@@ -21,13 +21,13 @@ Maintenance Plan
2121
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
2222
:alt: License: AGPL-3
2323
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmaintenance-lightgray.png?logo=github
24-
:target: https://github.com/OCA/maintenance/tree/18.0/maintenance_plan
24+
:target: https://github.com/OCA/maintenance/tree/19.0/maintenance_plan
2525
:alt: OCA/maintenance
2626
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
27-
:target: https://translation.odoo-community.org/projects/maintenance-18-0/maintenance-18-0-maintenance_plan
27+
:target: https://translation.odoo-community.org/projects/maintenance-19-0/maintenance-19-0-maintenance_plan
2828
:alt: Translate me on Weblate
2929
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
30-
:target: https://runboat.odoo-community.org/builds?repo=OCA/maintenance&target_branch=18.0
30+
:target: https://runboat.odoo-community.org/builds?repo=OCA/maintenance&target_branch=19.0
3131
:alt: Try me on Runboat
3232

3333
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -115,7 +115,7 @@ Bug Tracker
115115
Bugs are tracked on `GitHub Issues <https://github.com/OCA/maintenance/issues>`_.
116116
In case of trouble, please check there if your issue has already been reported.
117117
If you spotted it first, help us to smash it by providing a detailed and welcomed
118-
`feedback <https://github.com/OCA/maintenance/issues/new?body=module:%20maintenance_plan%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
118+
`feedback <https://github.com/OCA/maintenance/issues/new?body=module:%20maintenance_plan%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
119119

120120
Do not contact contributors directly about support or help with technical issues.
121121

@@ -154,6 +154,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
154154
mission is to support the collaborative development of Odoo features and
155155
promote its widespread use.
156156

157-
This module is part of the `OCA/maintenance <https://github.com/OCA/maintenance/tree/18.0/maintenance_plan>`_ project on GitHub.
157+
This module is part of the `OCA/maintenance <https://github.com/OCA/maintenance/tree/19.0/maintenance_plan>`_ project on GitHub.
158158

159159
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

maintenance_plan/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"name": "Maintenance Plan",
55
"summary": "Extends preventive maintenance planning",
6-
"version": "18.0.1.0.0",
6+
"version": "19.0.1.0.0",
77
"author": "Camptocamp SA, ForgeFlow, Odoo Community Association (OCA)",
88
"license": "AGPL-3",
99
"category": "Maintenance",

maintenance_plan/hooks.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import logging
55

6-
from odoo import _
76
from odoo.exceptions import UserError
87

98

@@ -27,7 +26,7 @@ def post_init_hook(env):
2726
)
2827
if len(request) > 1:
2928
raise UserError(
30-
_(
29+
env._(
3130
"You have multiple preventive maintenance requests on "
3231
"equipment %(name)s next action date (%(date)s). "
3332
"Please leave only one preventive request on the "

maintenance_plan/migrations/18.0.1.0.0/pre-migrate.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

maintenance_plan/models/maintenance_equipment.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Copyright 2019-20 ForgeFlow S.L. (https://www.forgeflow.com)
33
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
44

5-
from odoo import _, api, fields, models
5+
from odoo import api, fields, models
66
from odoo.exceptions import ValidationError
77

88

@@ -59,7 +59,7 @@ def _check_company_id(self):
5959
rec.company_id == p.company_id for p in rec.maintenance_plan_ids
6060
):
6161
raise ValidationError(
62-
_(
62+
self.env._(
6363
"Some maintenance plan's company is incompatible with "
6464
"the company of this equipment."
6565
)
@@ -85,8 +85,10 @@ def _prepare_request_from_plan(self, maintenance_plan, next_maintenance_date):
8585
team_id = request_model._get_default_team_id()
8686

8787
description = self.name if self else maintenance_plan.name
88-
kind = maintenance_plan.maintenance_kind_id.name or _("Unspecified kind")
89-
name = _(
88+
kind = maintenance_plan.maintenance_kind_id.name or self.env._(
89+
"Unspecified kind"
90+
)
91+
name = self.env._(
9092
"Preventive Maintenance (%(kind)s) - %(description)s",
9193
kind=kind,
9294
description=description,

maintenance_plan/models/maintenance_kind.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ class MaintenanceKind(models.Model):
1212
name = fields.Char(required=True, translate=True)
1313
active = fields.Boolean("Active Kind", required=True, default=True)
1414

15-
_sql_constraints = [
16-
("name_uniq", "unique (name)", "Maintenance kind name already exists.")
17-
]
15+
_name_uniq = models.Constraint(
16+
"unique (name)", "Maintenance kind name already exists."
17+
)

maintenance_plan/models/maintenance_plan.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from dateutil.relativedelta import relativedelta
66

7-
from odoo import _, api, fields, models
7+
from odoo import api, fields, models
88
from odoo.exceptions import UserError, ValidationError
99
from odoo.tools import safe_eval
1010

@@ -102,7 +102,7 @@ class MaintenancePlan(models.Model):
102102
@api.model
103103
def _search_search_equipment(self, operator, value):
104104
if operator != "=" or (not value and not isinstance(value, models.NewId)):
105-
raise ValueError(_("Unsupported search operator"))
105+
raise ValueError(self.env._("Unsupported search operator"))
106106
plans = self.search([("generate_with_domain", "=", True)])
107107
plan_ids = []
108108
equipment = self.env["maintenance.equipment"].browse(value)
@@ -133,7 +133,7 @@ def _get_eval_context(self):
133133
@api.depends("maintenance_kind_id.name", "equipment_id.name")
134134
def _compute_display_name(self):
135135
for plan in self:
136-
plan.display_name = plan.name or _(
136+
plan.display_name = plan.name or self.env._(
137137
"Unnamed %(kind)s plan (%(eqpmt)s)",
138138
kind=plan.maintenance_kind_id.name or "",
139139
eqpmt=plan.equipment_id.name,
@@ -210,7 +210,9 @@ def _check_company_id(self):
210210
and rec.company_id != rec.equipment_id.company_id
211211
):
212212
raise ValidationError(
213-
_("Maintenace Equipment must belong to the equipment's company")
213+
self.env._(
214+
"Maintenace Equipment must belong to the equipment's company"
215+
)
214216
)
215217

216218
def unlink(self):
@@ -225,8 +227,8 @@ def unlink(self):
225227
)
226228
)
227229
if request:
228-
raise UserError(
229-
_(
230+
raise UserError( # pylint: disable=no-raise-unlink
231+
self.env._(
230232
"The maintenance plan %(kind)s of equipment %(eqpmnt)s "
231233
"has generated a request which is not done "
232234
"yet. You should either set the request as "
@@ -238,14 +240,11 @@ def unlink(self):
238240
)
239241
return super().unlink()
240242

241-
_sql_constraints = [
242-
(
243-
"equipment_kind_uniq",
244-
"unique (equipment_id, maintenance_kind_id)",
245-
"You cannot define multiple times the same maintenance kind on an "
246-
"equipment maintenance plan.",
247-
)
248-
]
243+
_equipment_kind_uniq = models.Constraint(
244+
"unique (equipment_id, maintenance_kind_id)",
245+
"You cannot define multiple times the same maintenance kind on an "
246+
"equipment maintenance plan.",
247+
)
249248

250249
def button_manual_request_generation(self):
251250
"""Call the same method that the cron for generating manually the maintenance

maintenance_plan/static/description/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,9 @@ <h1>Maintenance Plan</h1>
372372
!! This file is generated by oca-gen-addon-readme !!
373373
!! changes will be overwritten. !!
374374
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
375-
!! source digest: sha256:222d80cfe136b8eb3f8e49710a9b76fdb27647e87145a28bfc621253f3581a22
375+
!! source digest: sha256:cd21f05e56ccccd12e88d22a3009fd970401a379a695813d5815b03ed56303a2
376376
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
377-
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/maintenance/tree/18.0/maintenance_plan"><img alt="OCA/maintenance" src="https://img.shields.io/badge/github-OCA%2Fmaintenance-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/maintenance-18-0/maintenance-18-0-maintenance_plan"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/maintenance&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
377+
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/maintenance/tree/19.0/maintenance_plan"><img alt="OCA/maintenance" src="https://img.shields.io/badge/github-OCA%2Fmaintenance-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/maintenance-19-0/maintenance-19-0-maintenance_plan"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/maintenance&amp;target_branch=19.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
378378
<p>This module extends the functionality of Odoo Maintenance module by
379379
allowing an equipment to have different preventive maintenance kinds.</p>
380380
<p><strong>Table of contents</strong></p>
@@ -456,7 +456,7 @@ <h2><a class="toc-backref" href="#toc-entry-4">Bug Tracker</a></h2>
456456
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/maintenance/issues">GitHub Issues</a>.
457457
In case of trouble, please check there if your issue has already been reported.
458458
If you spotted it first, help us to smash it by providing a detailed and welcomed
459-
<a class="reference external" href="https://github.com/OCA/maintenance/issues/new?body=module:%20maintenance_plan%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
459+
<a class="reference external" href="https://github.com/OCA/maintenance/issues/new?body=module:%20maintenance_plan%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
460460
<p>Do not contact contributors directly about support or help with technical issues.</p>
461461
</div>
462462
<div class="section" id="credits">
@@ -491,7 +491,7 @@ <h3><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h3>
491491
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
492492
mission is to support the collaborative development of Odoo features and
493493
promote its widespread use.</p>
494-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/maintenance/tree/18.0/maintenance_plan">OCA/maintenance</a> project on GitHub.</p>
494+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/maintenance/tree/19.0/maintenance_plan">OCA/maintenance</a> project on GitHub.</p>
495495
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
496496
</div>
497497
</div>

maintenance_plan/tests/test_maintenance_plan.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from dateutil.relativedelta import relativedelta
55

6-
from odoo import _, fields
6+
from odoo import fields
77

88
from .common import TestMaintenancePlanBase
99

@@ -17,15 +17,15 @@ def setUpClass(cls):
1717
def test_display_name(self):
1818
self.assertEqual(
1919
self.maintenance_plan_1.display_name,
20-
_(
20+
self.env._(
2121
"Unnamed %(void)s plan (%(eqpmnt)s)",
2222
void="",
2323
eqpmnt=self.maintenance_plan_1.equipment_id.name,
2424
),
2525
)
2626
self.assertEqual(
2727
self.maintenance_plan_2.display_name,
28-
_(
28+
self.env._(
2929
"Unnamed %(kind)s plan (%(eqpmnt)s)",
3030
kind=self.maintenance_plan_2.maintenance_kind_id.name,
3131
eqpmnt=self.maintenance_plan_2.equipment_id.name,
@@ -46,7 +46,8 @@ def test_next_maintenance_date_01(self):
4646
)
4747

4848
def test_next_maintenance_date_02(self):
49-
self.cron.method_direct_trigger()
49+
with self.enter_registry_test_mode():
50+
self.cron.method_direct_trigger()
5051
# Check maintenance plan dates
5152
self.assertEqual(
5253
self.maintenance_plan_1.start_maintenance_date, self.today_date
@@ -98,7 +99,8 @@ def test_next_maintenance_date_02(self):
9899
)
99100

100101
def test_generate_requests(self):
101-
self.cron.method_direct_trigger()
102+
with self.enter_registry_test_mode():
103+
self.cron.method_direct_trigger()
102104
generated_requests = self.maintenance_request_obj.search(
103105
[("maintenance_plan_id", "=", self.maintenance_plan_1.id)],
104106
order="schedule_date asc",
@@ -120,15 +122,16 @@ def test_generate_requests(self):
120122
)
121123
self.assertEqual(
122124
generated_request.name,
123-
_(
125+
self.env._(
124126
"Preventive Maintenance (%(kind)s) - %(plan)s",
125127
kind=self.weekly_kind.name,
126128
plan=self.maintenance_plan_4.name,
127129
),
128130
)
129131

130132
def test_generate_requests2(self):
131-
self.cron.method_direct_trigger()
133+
with self.enter_registry_test_mode():
134+
self.cron.method_direct_trigger()
132135
generated_requests = self.maintenance_request_obj.search(
133136
[("maintenance_plan_id", "=", self.maintenance_plan_1.id)],
134137
order="schedule_date asc",
@@ -140,7 +143,8 @@ def test_generate_requests2(self):
140143
new_date = fields.Date.from_string("2023-04-25")
141144
self.maintenance_plan_1.next_maintenance_date = new_date
142145
self.maintenance_plan_1.maintenance_plan_horizon = 3
143-
self.cron.method_direct_trigger()
146+
with self.enter_registry_test_mode():
147+
self.cron.method_direct_trigger()
144148
generated_requests = self.maintenance_request_obj.search(
145149
[("maintenance_plan_id", "=", self.maintenance_plan_1.id)],
146150
order="schedule_date asc",
@@ -149,7 +153,8 @@ def test_generate_requests2(self):
149153
self.assertEqual(generated_requests[-1].request_date, new_date)
150154

151155
def test_generate_requests_no_equipment(self):
152-
self.cron.method_direct_trigger()
156+
with self.enter_registry_test_mode():
157+
self.cron.method_direct_trigger()
153158
generated_requests = self.maintenance_request_obj.search(
154159
[("maintenance_plan_id", "=", self.maintenance_plan_5.id)],
155160
order="schedule_date asc",
@@ -168,8 +173,8 @@ def test_generate_requests_no_equipment(self):
168173
"maintenance_plan_horizon": 3,
169174
}
170175
)
171-
172-
self.cron.method_direct_trigger()
176+
with self.enter_registry_test_mode():
177+
self.cron.method_direct_trigger()
173178

174179
generated_requests = self.maintenance_request_obj.search(
175180
[("maintenance_plan_id", "=", self.maintenance_plan_5.id)],
@@ -196,22 +201,25 @@ def test_get_relativedelta(self):
196201

197202
def test_generate_requests_inactive_equipment(self):
198203
self.equipment_1.active = False
199-
self.cron.method_direct_trigger()
204+
with self.enter_registry_test_mode():
205+
self.cron.method_direct_trigger()
200206
generated_requests = self.maintenance_request_obj.search(
201207
[("maintenance_plan_id", "=", self.maintenance_plan_1.id)],
202208
order="schedule_date asc",
203209
)
204210
self.assertEqual(len(generated_requests), 0)
205211
self.equipment_1.active = True
206-
self.cron.method_direct_trigger()
212+
with self.enter_registry_test_mode():
213+
self.cron.method_direct_trigger()
207214
generated_requests = self.maintenance_request_obj.search(
208215
[("maintenance_plan_id", "=", self.maintenance_plan_1.id)],
209216
order="schedule_date asc",
210217
)
211218
self.assertEqual(len(generated_requests), 3)
212219

213220
def test_maintenance_request_report(self):
214-
self.cron.method_direct_trigger()
221+
with self.enter_registry_test_mode():
222+
self.cron.method_direct_trigger()
215223
generated_request = self.maintenance_request_obj.search(
216224
[("maintenance_plan_id", "=", self.maintenance_plan_1.id)],
217225
order="schedule_date asc",

maintenance_plan/tests/test_maintenance_plan_domain.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
class TestMaintenancePlanDomain(TestMaintenancePlanBase):
1010
def test_generate_requests_no_domain(self):
11-
self.cron.method_direct_trigger()
11+
with self.enter_registry_test_mode():
12+
self.cron.method_direct_trigger()
1213
generated_requests = self.maintenance_request_obj.search(
1314
[("maintenance_plan_id", "=", self.maintenance_plan_5.id)],
1415
order="schedule_date asc",
@@ -27,7 +28,8 @@ def test_generate_requests_domain(self):
2728
),
2829
}
2930
)
30-
self.cron.method_direct_trigger()
31+
with self.enter_registry_test_mode():
32+
self.cron.method_direct_trigger()
3133
generated_requests = self.maintenance_request_obj.search(
3234
[("maintenance_plan_id", "=", self.maintenance_plan_5.id)],
3335
order="schedule_date asc",

0 commit comments

Comments
 (0)