Skip to content

Commit 78e3e0d

Browse files
[IMP] repair_quality_control: Auto-generate inspections
1 parent ba54624 commit 78e3e0d

16 files changed

+534
-36
lines changed

repair_quality_control/README.rst

+38-7
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,16 @@ Repair Quality Control
2929
|badge1| |badge2| |badge3| |badge4| |badge5|
3030

3131
This module allows to create quality control inspections from repair
32-
order when that one is done. One repair order is linked to many
33-
different inspections.
32+
orders. One repair order can be linked to many different inspections.
33+
34+
The related inspections can be created either on the confirmation of the
35+
repair order, or when it is done. The creation can be executed manually
36+
or automatically. Both of these aspects are configurable at a company
37+
level.
38+
39+
Moreover, you can configure trigger lines at a Product, Product Template
40+
or Product Category level (using the 'Repair' trigger) to set the QC
41+
Test to use when creating the inspections.
3442

3543
**Table of contents**
3644

@@ -42,12 +50,31 @@ Usage
4250

4351
To use this module, you need to:
4452

53+
Configure the QC repair behavior for the company:
54+
55+
1. Go to Settings > Repair.
56+
2. Configure the two settings related to QC Inspections.
57+
58+
Configure the triggers:
59+
60+
1. Go to Products > Products.
61+
2. Select a product (this product must then be used in a repair order).
62+
3. Go to the 'Inventory' tab.
63+
4. In the 'Quality Control' section, select the QC Test to use when
64+
creating the inspections, for the 'Repair' trigger.
65+
4566
Create a repair order:
4667

4768
1. Go to Repairs > Repair Orders.
48-
2. Create new repair order and repair that.
49-
3. Create an inspection from the header button called "Create
50-
Inspection".
69+
2. Create new repair order.
70+
3. Set the repair order to 'Done' or 'Confirmed' state.
71+
4. An inspection should be created automatically or a button should
72+
appear to allow creating it manually.
73+
74+
- The states where this should happen can slightly vary depending on
75+
the Invoice Method of the repair order.
76+
- For example, when the Invoice Method is 'Before Repair', the order
77+
never goes to 'Confirmed' state.
5178

5279
You can access from repair order to inspection directly with a smart
5380
button and the same backwards.
@@ -73,9 +100,13 @@ Authors
73100
Contributors
74101
------------
75102

76-
- `APSL-Nagarro <https://www.apsl.tech>`__:
103+
- `APSL-Nagarro <https://www.apsl.tech>`__:
104+
105+
- Antoni Marroig <[email protected]>
106+
107+
- `ForgeFlow <https://www.forgeflow.com>`__:
77108

78-
- Antoni Marroig <[email protected]>
109+
- Laura Cazorla <[email protected]>
79110

80111
Maintainers
81112
-----------

repair_quality_control/__manifest__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
"application": False,
1313
"installable": True,
1414
"depends": [
15-
"repair",
15+
"base_repair_config",
1616
"quality_control_stock_oca",
1717
],
1818
"data": [
19+
"data/repair_quality_control_data.xml",
20+
"views/res_config_settings_views.xml",
1921
"views/repair_views.xml",
2022
"views/qc_inspection_views.xml",
2123
],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!-- Copyright 2024 ForgeFlow, S.L.
3+
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0) -->
4+
<odoo>
5+
<record model="qc.trigger" id="qc_trigger_repair">
6+
<field name="name">Repairs</field>
7+
<field name="partner_selectable" eval="True" />
8+
<field name="company_id" eval="False" />
9+
</record>
10+
</odoo>

repair_quality_control/models/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22

33
from . import qc_inspection
44
from . import repair
5+
from . import res_company
6+
from . import res_config_settings

repair_quality_control/models/qc_inspection.py

+36-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,47 @@
11
# Copyright 2024 Antoni Marroig(APSL-Nagarro)<[email protected]>
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
33

4-
from odoo import fields, models
4+
from odoo import api, fields, models
55

66

77
class QcInspection(models.Model):
88
_inherit = "qc.inspection"
99

10-
repair_id = fields.Many2one("repair.order")
10+
repair_id = fields.Many2one(
11+
comodel_name="repair.order",
12+
compute="_compute_repair_id",
13+
store=True,
14+
)
15+
16+
@api.depends("object_id")
17+
def _compute_repair_id(self):
18+
self.repair_id = False
19+
for rec in self:
20+
if rec.object_id and rec.object_id._name == "repair.order":
21+
rec.repair_id = rec.object_id
22+
23+
@api.depends("object_id")
24+
def _compute_product_id(self):
25+
result = super()._compute_product_id()
26+
self.product_id = False
27+
for rec in self:
28+
if rec.object_id and rec.object_id._name == "repair.order":
29+
rec.product_id = rec.object_id.product_id
30+
return result
31+
32+
@api.depends("object_id")
33+
def _compute_lot(self):
34+
result = super()._compute_lot()
35+
self.lot_id = False
36+
for rec in self:
37+
if rec.object_id and rec.object_id._name == "repair.order":
38+
rec.lot_id = rec.object_id.lot_id
39+
return result
40+
41+
def object_selection_values(self):
42+
objects = super().object_selection_values()
43+
objects.append(("repair.order", "Repair Order"))
44+
return objects
1145

1246
def action_view_qc_repair_order(self):
1347
return {

repair_quality_control/models/repair.py

+89-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Copyright 2024 Antoni Marroig(APSL-Nagarro)<[email protected]>
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
33

4-
from odoo import _, fields, models
4+
from odoo import _, api, fields, models
5+
6+
from odoo.addons.quality_control_oca.models.qc_trigger_line import _filter_trigger_lines
57

68

79
class RepairOrder(models.Model):
@@ -13,6 +15,91 @@ class RepairOrder(models.Model):
1315
"Inspections",
1416
)
1517

18+
auto_generate_qc_inspection = fields.Boolean(
19+
related="company_id.repair_auto_generate_qc_inspection",
20+
)
21+
generate_qc_inspection_state = fields.Selection(
22+
related="company_id.repair_generate_qc_inspection_state",
23+
)
24+
show_button_create_qc_inspection = fields.Boolean(
25+
compute="_compute_show_button_create_qc_inspection"
26+
)
27+
28+
@api.depends(
29+
"auto_generate_qc_inspection",
30+
"generate_qc_inspection_state",
31+
"state",
32+
"invoice_method",
33+
)
34+
def _compute_show_button_create_qc_inspection(self):
35+
self.show_button_create_qc_inspection = False
36+
for repair in self.filtered(lambda r: not r.auto_generate_qc_inspection):
37+
if repair.generate_qc_inspection_state == "confirmed":
38+
if repair.state == "confirmed":
39+
self.show_button_create_qc_inspection = True
40+
elif repair.state == "ready" and repair.invoice_method == "b4repair":
41+
self.show_button_create_qc_inspection = True
42+
elif (
43+
repair.generate_qc_inspection_state == "done" and repair.state == "done"
44+
):
45+
self.show_button_create_qc_inspection = True
46+
47+
def create_qc_inspection(self):
48+
self.ensure_one()
49+
inspection_model = self.env["qc.inspection"].sudo()
50+
qc_trigger = self.sudo().env.ref("repair_quality_control.qc_trigger_repair")
51+
trigger_lines = set()
52+
for model in [
53+
"qc.trigger.product_category_line",
54+
"qc.trigger.product_template_line",
55+
"qc.trigger.product_line",
56+
]:
57+
partner = self.partner_id if qc_trigger.partner_selectable else False
58+
trigger_lines = trigger_lines.union(
59+
self.env[model]
60+
.sudo()
61+
.get_trigger_line_for_product(
62+
qc_trigger, self.product_id.sudo(), partner=partner
63+
)
64+
)
65+
for trigger_line in _filter_trigger_lines(trigger_lines):
66+
inspection_model._make_inspection(self, trigger_line)
67+
68+
def action_repair_confirm(self):
69+
result = super().action_repair_confirm()
70+
for rep in self:
71+
auto_generate = rep.auto_generate_qc_inspection
72+
if auto_generate and rep.generate_qc_inspection_state == "confirmed":
73+
rep.create_qc_inspection()
74+
return result
75+
76+
def action_repair_done(self):
77+
result = super().action_repair_done()
78+
for rep in self:
79+
auto_generate = rep.auto_generate_qc_inspection
80+
if auto_generate and rep.generate_qc_inspection_state == "done":
81+
if rep.invoice_method != "after_repair":
82+
rep.create_qc_inspection()
83+
return result
84+
85+
def action_repair_invoice_create(self):
86+
result = super().action_repair_invoice_create()
87+
for rep in self:
88+
if rep.state == "done":
89+
auto_generate = rep.auto_generate_qc_inspection
90+
if auto_generate and rep.generate_qc_inspection_state == "done":
91+
if rep.invoice_method == "after_repair":
92+
rep.create_qc_inspection()
93+
return result
94+
95+
def action_repair_cancel(self):
96+
inspections = self.sudo().inspection_ids
97+
draft_inspections = inspections.filtered(lambda i: i.state == "draft")
98+
draft_inspections.unlink()
99+
inspections -= draft_inspections
100+
inspections.action_cancel()
101+
return super().action_repair_cancel()
102+
16103
def action_create_qc_inspection(self):
17104
self.ensure_one()
18105
action = self.env["ir.actions.act_window"]._for_xml_id(
@@ -22,14 +109,10 @@ def action_create_qc_inspection(self):
22109
action["views"] = [(False, "form")]
23110
action["target"] = "current"
24111
action["name"] = _("Create Inspection")
25-
26112
action["context"] = {
27113
"default_qty": self.product_qty,
28-
"default_repair_id": self.id,
29-
"default_object_id": f"product.product,{self.product_id.id}",
114+
"default_object_id": f"repair.order,{self.id}",
30115
}
31-
if self.lot_id:
32-
action["context"]["default_object_id"] = f"stock.lot,{self.lot_id.id}"
33116
return action
34117

35118
def action_view_repair_inspections(self):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright 2024 ForgeFlow (http://www.forgeflow.com)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
3+
4+
from odoo import fields, models
5+
6+
7+
class ResCompany(models.Model):
8+
_inherit = "res.company"
9+
10+
repair_auto_generate_qc_inspection = fields.Boolean(
11+
string="Auto-generate QC Inspection",
12+
help="If checked, QC Inspections will be automatically "
13+
"created for Repair Order, on state changes.",
14+
)
15+
16+
repair_generate_qc_inspection_state = fields.Selection(
17+
[
18+
("confirmed", "On Confirm"),
19+
("done", "On Done"),
20+
],
21+
string="Generate QC Inspection State",
22+
default="done",
23+
required=True,
24+
help="This field allows you to select the state of the Repair "
25+
"Order in which the QC Inspection will be generated.",
26+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2024 ForgeFlow (http://www.forgeflow.com)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
3+
4+
from odoo import fields, models
5+
6+
7+
class ResConfigSettings(models.TransientModel):
8+
_inherit = "res.config.settings"
9+
10+
repair_auto_generate_qc_inspection = fields.Boolean(
11+
related="company_id.repair_auto_generate_qc_inspection",
12+
readonly=False,
13+
)
14+
repair_generate_qc_inspection_state = fields.Selection(
15+
related="company_id.repair_generate_qc_inspection_state",
16+
readonly=False,
17+
)
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
- [APSL-Nagarro](https://www.apsl.tech):
2-
- Antoni Marroig \<<[email protected]>\>
2+
- Antoni Marroig \<<[email protected]>\>
3+
- [ForgeFlow](https://www.forgeflow.com):
4+
- Laura Cazorla \<<[email protected]>\>
+10-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
1-
This module allows to create quality control inspections from repair order
2-
when that one is done. One repair order is linked to many different inspections.
1+
This module allows to create quality control inspections from repair orders.
2+
One repair order can be linked to many different inspections.
3+
4+
The related inspections can be created either on the confirmation of the repair
5+
order, or when it is done. The creation can be executed manually or
6+
automatically. Both of these aspects are configurable at a company level.
7+
8+
Moreover, you can configure trigger lines at a Product, Product Template or
9+
Product Category level (using the 'Repair' trigger) to set the QC Test to use
10+
when creating the inspections.
+21-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
To use this module, you need to:
22

3+
Configure the QC repair behavior for the company:
4+
5+
1. Go to Settings > Repair.
6+
2. Configure the two settings related to QC Inspections.
7+
8+
Configure the triggers:
9+
10+
1. Go to Products > Products.
11+
2. Select a product (this product must then be used in a repair order).
12+
3. Go to the 'Inventory' tab.
13+
4. In the 'Quality Control' section, select the QC Test to use when creating the
14+
inspections, for the 'Repair' trigger.
15+
316
Create a repair order:
417

518
1. Go to Repairs > Repair Orders.
6-
2. Create new repair order and repair that.
7-
3. Create an inspection from the header button called "Create Inspection".
19+
2. Create new repair order.
20+
3. Set the repair order to 'Done' or 'Confirmed' state.
21+
4. An inspection should be created automatically or a button should appear to
22+
allow creating it manually.
23+
* The states where this should happen can slightly vary depending on the
24+
Invoice Method of the repair order.
25+
* For example, when the Invoice Method is 'Before Repair', the order never
26+
goes to 'Confirmed' state.
827

928
You can access from repair order to inspection directly with a
1029
smart button and the same backwards.

0 commit comments

Comments
 (0)