mirror of
https://github.com/bringout/oca-ocb-vertical-industry.git
synced 2026-04-22 06:51:58 +02:00
19.0 vanilla
This commit is contained in:
parent
4607ccbd2e
commit
825ff6514e
487 changed files with 184979 additions and 195262 deletions
|
|
@ -1,4 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import test_calendar_with_recurrence
|
||||
from . import test_maintenance
|
||||
from . import test_maintenance_multicompany
|
||||
|
|
|
|||
|
|
@ -0,0 +1,70 @@
|
|||
from odoo.tests import HttpCase, tagged
|
||||
from datetime import datetime, time
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
|
||||
@tagged('post_install', '-at_install')
|
||||
class TestCalendarWithRecurrence(HttpCase):
|
||||
|
||||
def test_dblclick_event_from_calendar(self):
|
||||
"""Make sure double clicking on an event and its recurrences lead to the correct record"""
|
||||
self.env['maintenance.team'].create({
|
||||
'name': 'the boys',
|
||||
})
|
||||
equipment = self.env['maintenance.equipment'].create({
|
||||
'name': 'room'
|
||||
})
|
||||
requests = self.env['maintenance.request'].create([{
|
||||
'name': 'send the mails',
|
||||
'schedule_date': datetime.now() + relativedelta(weeks=-2),
|
||||
}, {
|
||||
'name': 'wash the car',
|
||||
'schedule_date': datetime.now() + relativedelta(weeks=+3),
|
||||
}, {
|
||||
'name': 'clean the room',
|
||||
'schedule_date': datetime.now(),
|
||||
'equipment_id': equipment.id, # necessary for the tour to work with mrp_maintenance installed
|
||||
'maintenance_type': 'preventive',
|
||||
'recurring_maintenance': True,
|
||||
'repeat_until': datetime.now() + relativedelta(days=+8),
|
||||
'repeat_interval': 1,
|
||||
'repeat_unit': 'day',
|
||||
}])
|
||||
request = requests[2]
|
||||
|
||||
url = '/odoo/action-maintenance.hr_equipment_request_action_cal'
|
||||
self.start_tour(url, 'test_dblclick_event_from_calendar', login='admin')
|
||||
|
||||
self.assertEqual(request.name, 'make your bed', "The event modification should update the request")
|
||||
self.assertAlmostEqual(request.duration, 2, 2, "The event modification should update the request")
|
||||
|
||||
def test_drag_and_drop_calendar_event(self):
|
||||
"""
|
||||
Make sure dragging and dropping an event changes the correct record
|
||||
Occurences should be locked, drag and drop should have no effect
|
||||
"""
|
||||
self.env['maintenance.team'].create({
|
||||
'name': 'the boys',
|
||||
})
|
||||
requests = self.env['maintenance.request'].create([{
|
||||
'name': 'send the mails',
|
||||
'schedule_date': datetime.now() + relativedelta(months=-2),
|
||||
}, {
|
||||
'name': 'wash the car',
|
||||
'schedule_date': datetime.now() + relativedelta(months=+1),
|
||||
}, {
|
||||
'name': 'clean the room',
|
||||
'schedule_date': datetime.combine(datetime.now().replace(day=6), time.min.replace(hour=10)), # 6th of the month at 10 AM
|
||||
'maintenance_type': 'preventive',
|
||||
'recurring_maintenance': True,
|
||||
'repeat_interval': 1,
|
||||
'repeat_until': datetime.now() + relativedelta(weeks=+2),
|
||||
'repeat_unit': 'week',
|
||||
}])
|
||||
request = requests[2]
|
||||
|
||||
url = '/odoo/action-maintenance.hr_equipment_request_action_cal'
|
||||
self.start_tour(url, 'test_drag_and_drop_event_in_calendar', login='admin')
|
||||
|
||||
target_datetime = datetime.combine(datetime.now().replace(day=15), time.min.replace(hour=10)) # 15h of the month at 10 AM
|
||||
self.assertEqual(request.schedule_date, target_datetime, "The event modification should update the request")
|
||||
|
|
@ -3,15 +3,15 @@
|
|||
|
||||
import time
|
||||
|
||||
from odoo.tests.common import TransactionCase
|
||||
from dateutil import relativedelta
|
||||
import datetime
|
||||
from odoo.tests import Form
|
||||
from odoo.tests.common import tagged, TransactionCase
|
||||
from odoo import fields
|
||||
|
||||
class TestEquipment(TransactionCase):
|
||||
""" Test used to check that when doing equipment/maintenance_request/equipment_category creation."""
|
||||
|
||||
class TestEquipmentCommon(TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestEquipment, self).setUp()
|
||||
super().setUp()
|
||||
self.equipment = self.env['maintenance.equipment']
|
||||
self.maintenance_request = self.env['maintenance.request']
|
||||
self.res_users = self.env['res.users']
|
||||
|
|
@ -25,7 +25,7 @@ class TestEquipment(TransactionCase):
|
|||
company_id=self.main_company.id,
|
||||
login="emp",
|
||||
email="empuser@yourcompany.example.com",
|
||||
groups_id=[(6, 0, [res_user.id])]
|
||||
group_ids=[(6, 0, [res_user.id])]
|
||||
))
|
||||
|
||||
self.manager = self.res_users.create(dict(
|
||||
|
|
@ -33,13 +33,16 @@ class TestEquipment(TransactionCase):
|
|||
company_id=self.main_company.id,
|
||||
login="hm",
|
||||
email="eqmanager@yourcompany.example.com",
|
||||
groups_id=[(6, 0, [res_manager.id])]
|
||||
group_ids=[(6, 0, [res_manager.id])]
|
||||
))
|
||||
|
||||
self.equipment_monitor = self.env['maintenance.equipment.category'].create({
|
||||
'name': 'Monitors - Test',
|
||||
})
|
||||
|
||||
|
||||
class TestEquipment(TestEquipmentCommon):
|
||||
|
||||
def test_10_equipment_request_category(self):
|
||||
|
||||
# Create a new equipment
|
||||
|
|
@ -80,55 +83,103 @@ class TestEquipment(TransactionCase):
|
|||
# I check that maintenance request is in the "In Progress" stage
|
||||
self.assertEqual(maintenance_request_01.stage_id.id, self.ref('maintenance.stage_1'))
|
||||
|
||||
def test_20_cron(self):
|
||||
""" Check the cron creates the necessary preventive maintenance requests"""
|
||||
equipment_cron = self.equipment.create({
|
||||
'name': 'High Maintenance Monitor because of Color Calibration',
|
||||
'category_id': self.equipment_monitor.id,
|
||||
'technician_user_id': self.ref('base.user_root'),
|
||||
'owner_user_id': self.user.id,
|
||||
'assign_date': time.strftime('%Y-%m-%d'),
|
||||
'period': 7,
|
||||
'color': 3,
|
||||
})
|
||||
|
||||
maintenance_request_cron = self.maintenance_request.create({
|
||||
'name': 'Need a special calibration',
|
||||
'user_id': self.user.id,
|
||||
'request_date': (datetime.datetime.now() + relativedelta.relativedelta(days=7)).strftime('%Y-%m-%d'),
|
||||
def test_forever_maintenance_repeat_type(self):
|
||||
"""
|
||||
Test that a maintenance request with repeat_type = forever will be duplicated when it
|
||||
is moved to a 'done' stage, and the new request will be placed in the first stage.
|
||||
"""
|
||||
maintenance_request = self.env['maintenance.request'].create({
|
||||
'name': 'Test forever maintenance',
|
||||
'repeat_type': 'forever',
|
||||
'maintenance_type': 'preventive',
|
||||
'owner_user_id': self.user.id,
|
||||
'equipment_id': equipment_cron.id,
|
||||
'color': 7,
|
||||
'stage_id': self.ref('maintenance.stage_0'),
|
||||
'maintenance_team_id': self.ref('maintenance.equipment_team_maintenance')
|
||||
'recurring_maintenance': True,
|
||||
})
|
||||
|
||||
self.env['maintenance.equipment']._cron_generate_requests()
|
||||
# As it is generating the requests for one month in advance, we should have 4 requests in total
|
||||
tot_requests = self.maintenance_request.search([('equipment_id', '=', equipment_cron.id)])
|
||||
self.assertEqual(len(tot_requests), 1, 'The cron should have generated just 1 request for the High Maintenance Monitor.')
|
||||
|
||||
def test_21_cron(self):
|
||||
""" Check the creation of maintenance requests by the cron"""
|
||||
|
||||
team_test = self.maintenance_team.create({
|
||||
'name': 'team_test',
|
||||
})
|
||||
equipment = self.equipment.create({
|
||||
'name': 'High Maintenance Monitor because of Color Calibration',
|
||||
'category_id': self.equipment_monitor.id,
|
||||
'technician_user_id': self.ref('base.user_root'),
|
||||
'owner_user_id': self.user.id,
|
||||
'assign_date': time.strftime('%Y-%m-%d'),
|
||||
'period': 7,
|
||||
'color': 3,
|
||||
'maintenance_team_id': team_test.id,
|
||||
'maintenance_duration': 3.0,
|
||||
done_maintenance_stage = self.env['maintenance.stage'].create({
|
||||
'name': 'Test Done',
|
||||
'done': True,
|
||||
})
|
||||
maintenance_stages = self.env['maintenance.stage'].search([])
|
||||
maintenance_request.with_context(default_stage_id=maintenance_stages[1].id).stage_id = done_maintenance_stage
|
||||
new_maintenance = self.env['maintenance.request'].search([('name', '=', 'Test forever maintenance'), ('stage_id', '=', maintenance_stages[0].id)])
|
||||
self.assertTrue(new_maintenance)
|
||||
|
||||
self.env['maintenance.equipment']._cron_generate_requests()
|
||||
tot_requests = self.maintenance_request.search([('equipment_id', '=', equipment.id)])
|
||||
self.assertEqual(len(tot_requests), 1, 'The cron should have generated just 1 request for the High Maintenance Monitor.')
|
||||
self.assertEqual(tot_requests.maintenance_team_id.id, team_test.id, 'The maintenance team should be the same as equipment one')
|
||||
self.assertEqual(tot_requests.duration, 3.0, 'Equipement maintenance duration is not the same as the request one')
|
||||
def test_update_multiple_maintenance_request_record(self):
|
||||
"""
|
||||
Test that multiple records of the model 'maintenance.request' can be written simultaneously.
|
||||
"""
|
||||
maintenance_requests = self.env['maintenance.request'].create([
|
||||
{
|
||||
'name': 'm_1',
|
||||
'maintenance_type': 'preventive',
|
||||
'kanban_state': 'normal',
|
||||
},
|
||||
{
|
||||
'name': 'm_2',
|
||||
'maintenance_type': 'preventive',
|
||||
'kanban_state': 'normal',
|
||||
},
|
||||
])
|
||||
maintenance_requests.write({'kanban_state': 'blocked', 'stage_id': self.ref('maintenance.stage_0')})
|
||||
self.assertRecordValues(maintenance_requests, [
|
||||
{'kanban_state': 'blocked', 'stage_id': self.ref('maintenance.stage_0')},
|
||||
{'kanban_state': 'blocked', 'stage_id': self.ref('maintenance.stage_0')},
|
||||
])
|
||||
|
||||
|
||||
@tagged("post_install", "-at_install")
|
||||
class TestEquipmentPostInstall(TestEquipmentCommon):
|
||||
|
||||
def test_basic_access_and_new_equipment(self):
|
||||
"""
|
||||
Ensure that
|
||||
- a maintenance manager can create an equipment and assign it to a
|
||||
specific user
|
||||
- the user can open it
|
||||
"""
|
||||
equipment_name = "Super Equipment"
|
||||
|
||||
with self.with_user('hm'):
|
||||
form = Form(self.env['maintenance.equipment'])
|
||||
form.name = equipment_name
|
||||
equipment = form.save()
|
||||
|
||||
self.assertTrue(equipment)
|
||||
equipment.owner_user_id = self.user
|
||||
|
||||
with self.with_user('emp'):
|
||||
# Using browse to avoid the env of record `equipment`
|
||||
form = Form(self.env['maintenance.equipment'].browse(equipment.id))
|
||||
self.assertEqual(form.name, equipment_name)
|
||||
|
||||
def test_done_maintenance_no_close_or_request_date(self):
|
||||
"""
|
||||
Ensure equipment with done maintenance requests that have
|
||||
`close_date` or `request_date` set to False can still be opened.
|
||||
In theory this should never happen, but we should fail gracefully
|
||||
in case these dates are forced set to False.
|
||||
"""
|
||||
|
||||
form = Form(self.env['maintenance.equipment'].with_user(self.manager))
|
||||
form.name = "brain"
|
||||
equipment = form.save()
|
||||
form = Form(self.env['maintenance.request'].with_user(self.manager))
|
||||
form.name = "improve efficiency"
|
||||
form.equipment_id = equipment
|
||||
form.maintenance_type = 'corrective'
|
||||
maintenance = form.save()
|
||||
self.assertTrue(maintenance.request_date)
|
||||
self.assertFalse(maintenance.close_date)
|
||||
|
||||
maintenance.stage_id = self.ref('maintenance.stage_3')
|
||||
self.assertTrue(maintenance.request_date)
|
||||
self.assertTrue(maintenance.close_date)
|
||||
form = Form(equipment)
|
||||
|
||||
# this shouldn't happen unless it's forced
|
||||
maintenance.close_date = False
|
||||
form = Form(equipment)
|
||||
maintenance.close_date = fields.Date.today()
|
||||
maintenance.request_date = False
|
||||
form = Form(equipment)
|
||||
maintenance.close_date = False
|
||||
form = Form(equipment)
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class TestEquipmentMulticompany(TransactionCase):
|
|||
'company_id': company_a.id,
|
||||
'login': 'e_equipment_manager',
|
||||
'email': 'eqmanager@yourcompany.example.com',
|
||||
'groups_id': [(6, 0, [group_manager.id])],
|
||||
'group_ids': [(6, 0, [group_manager.id])],
|
||||
'company_ids': [(6, 0, [company_a.id, company_b.id])]
|
||||
})
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ class TestEquipmentMulticompany(TransactionCase):
|
|||
'company_id': company_b.id,
|
||||
'login': 'emp',
|
||||
'email': 'empuser@yourcompany.example.com',
|
||||
'groups_id': [(6, 0, [group_user.id])],
|
||||
'group_ids': [(6, 0, [group_user.id])],
|
||||
'company_ids': [(6, 0, [company_b.id])]
|
||||
})
|
||||
|
||||
|
|
@ -127,7 +127,7 @@ class TestEquipmentMulticompany(TransactionCase):
|
|||
'company_id': company_b.id,
|
||||
'owner_user_id': equipment_manager.id,
|
||||
})
|
||||
# Now there are total 2 equipments created and can view by equipment_manager user
|
||||
# Now there are total 2 equipment created and can view by equipment_manager user
|
||||
self.assertEqual(Equipment.with_user(equipment_manager).with_context(allowed_company_ids=cids).search_count([]), 2)
|
||||
|
||||
# And there is total 1 equipment can be view by Normal User ( Which user is followers)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue