|
| 1 | +# Copyright 2020, Brian McMaster <[email protected]> |
| 2 | +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) |
| 3 | + |
| 4 | +from odoo.tests import SavepointCase |
| 5 | + |
| 6 | + |
| 7 | +class TestFSMSkill(SavepointCase): |
| 8 | + @classmethod |
| 9 | + def setUpClass(cls): |
| 10 | + super(TestFSMSkill, cls).setUpClass() |
| 11 | + |
| 12 | + cls.skill = cls.env["hr.skill"] |
| 13 | + cls.skill_type = cls.env["hr.skill.type"] |
| 14 | + cls.fsm_person = cls.env["fsm.person"] |
| 15 | + cls.fsm_person_skill = cls.env["fsm.person.skill"] |
| 16 | + cls.fsm_order = cls.env["fsm.order"] |
| 17 | + cls.fsm_location = cls.env["fsm.location"] |
| 18 | + cls.fsm_template = cls.env["fsm.template"] |
| 19 | + cls.fsm_category = cls.env["fsm.category"] |
| 20 | + |
| 21 | + cls.skill_type_01 = cls.skill_type.create({"name": "Field Service Skills"}) |
| 22 | + |
| 23 | + # Create some great skills |
| 24 | + cls.skill_01 = cls.skill.create( |
| 25 | + {"name": "Nunchuck Skills", "skill_type_id": cls.skill_type_01.id} |
| 26 | + ) |
| 27 | + cls.skill_02 = cls.skill.create( |
| 28 | + {"name": "Bow Hunting Skills", "skill_type_id": cls.skill_type_01.id} |
| 29 | + ) |
| 30 | + cls.skill_03 = cls.skill.create( |
| 31 | + {"name": "Computer Hacking Skills", "skill_type_id": cls.skill_type_01.id} |
| 32 | + ) |
| 33 | + cls.skill_04 = cls.skill.create( |
| 34 | + {"name": "Sweet Bike Owning Skills", "skill_type_id": cls.skill_type_01.id} |
| 35 | + ) |
| 36 | + cls.skill_05 = cls.skill.create( |
| 37 | + { |
| 38 | + "name": "Hooking Up with Chicks Skills", |
| 39 | + "skill_type_id": cls.skill_type_01.id, |
| 40 | + } |
| 41 | + ) |
| 42 | + cls.skill_06 = cls.skill.create( |
| 43 | + {"name": "Moustache Growing Skills", "skill_type_id": cls.skill_type_01.id} |
| 44 | + ) |
| 45 | + |
| 46 | + # Create some great workers with their own great skills |
| 47 | + # Our first worker, Napoleon, has nunchuck skills and bow hunting |
| 48 | + # skills, which he learned while in Alaska hunting wolverines with his |
| 49 | + # uncle. |
| 50 | + cls.person_01 = cls.fsm_person.create({"name": "Napoleon"}) |
| 51 | + cls.person_01_skill_01 = cls.fsm_person_skill.create( |
| 52 | + {"person_id": cls.person_01.id, "skill_id": cls.skill_01.id} |
| 53 | + ) |
| 54 | + cls.person_01_skill_02 = cls.fsm_person_skill.create( |
| 55 | + {"person_id": cls.person_01.id, "skill_id": cls.skill_02.id} |
| 56 | + ) |
| 57 | + |
| 58 | + # Our second worker, Pedro, has a lot of really good skills which he |
| 59 | + # learned from his cousins that have all the sweet hookups |
| 60 | + cls.person_02 = cls.fsm_person.create({"name": "Pedro"}) |
| 61 | + cls.person_02_skill_04 = cls.fsm_person_skill.create( |
| 62 | + {"person_id": cls.person_02.id, "skill_id": cls.skill_04.id} |
| 63 | + ) |
| 64 | + cls.person_02_skill_05 = cls.fsm_person_skill.create( |
| 65 | + {"person_id": cls.person_02.id, "skill_id": cls.skill_05.id} |
| 66 | + ) |
| 67 | + cls.person_02_skill_06 = cls.fsm_person_skill.create( |
| 68 | + {"person_id": cls.person_02.id, "skill_id": cls.skill_06.id} |
| 69 | + ) |
| 70 | + |
| 71 | + # Create a location for an order |
| 72 | + cls.location_01 = cls.fsm_location.create( |
| 73 | + { |
| 74 | + "name": "Summer's House", |
| 75 | + "owner_id": cls.env["res.partner"] |
| 76 | + .create({"name": "Summer's Parents"}) |
| 77 | + .id, |
| 78 | + } |
| 79 | + ) |
| 80 | + |
| 81 | + # Create a category that requires great skills |
| 82 | + cls.category_01_skills = [cls.skill_04.id, cls.skill_05.id, cls.skill_06.id] |
| 83 | + cls.category_01 = cls.fsm_category.create( |
| 84 | + {"name": "Sales", "skill_ids": [(6, 0, cls.category_01_skills)]} |
| 85 | + ) |
| 86 | + |
| 87 | + # Create a template that requires great skills |
| 88 | + cls.template_01_skills = [cls.skill_01.id, cls.skill_02.id] |
| 89 | + cls.template_01 = cls.fsm_template.create( |
| 90 | + {"name": "Template Name", "skill_ids": [(6, 0, cls.template_01_skills)]} |
| 91 | + ) |
| 92 | + |
| 93 | + # Create an order that requires no skills |
| 94 | + cls.order_no_skills = cls.fsm_order.create({"location_id": cls.location_01.id}) |
| 95 | + |
| 96 | + # Create an order with a category |
| 97 | + cls.order_category_skills = cls.fsm_order.create( |
| 98 | + { |
| 99 | + "location_id": cls.location_01.id, |
| 100 | + "category_ids": [(6, 0, [cls.category_01.id])], |
| 101 | + } |
| 102 | + ) |
| 103 | + |
| 104 | + # Create an order with a template |
| 105 | + cls.order_template_skills = cls.fsm_order.create( |
| 106 | + {"location_id": cls.location_01.id, "template_id": cls.template_01.id} |
| 107 | + ) |
| 108 | + |
| 109 | + def test_fsm_skills(self): |
| 110 | + |
| 111 | + # Validate the order without skills can be done by all workers |
| 112 | + self.assertEqual( |
| 113 | + self.order_no_skills.skill_worker_ids.ids, |
| 114 | + self.fsm_person.search([]).ids, |
| 115 | + "FSM Order without skills should allow all workers", |
| 116 | + ) |
| 117 | + |
| 118 | + # Trigger the category onchange and validate skill_ids get set |
| 119 | + self.order_category_skills._onchange_category_ids() |
| 120 | + self.assertEqual( |
| 121 | + self.order_category_skills.skill_ids.ids, |
| 122 | + self.category_01_skills, |
| 123 | + "The order should have skills based on the category", |
| 124 | + ) |
| 125 | + |
| 126 | + # Trigger the template onchange and validate skill_ids get set |
| 127 | + self.order_template_skills._onchange_template_id() |
| 128 | + self.assertEqual( |
| 129 | + self.order_template_skills.skill_ids.ids, |
| 130 | + self.template_01_skills, |
| 131 | + "The order should have skills based on the template", |
| 132 | + ) |
| 133 | + |
| 134 | + # Validate the skilled order can be done by Pedro who has the skills |
| 135 | + self.assertEqual( |
| 136 | + self.order_category_skills.skill_worker_ids, |
| 137 | + self.person_02.id, |
| 138 | + "FSM Order should only allow workers with all skills required", |
| 139 | + ) |
0 commit comments