diff --git a/quality_control_oca/models/qc_inspection.py b/quality_control_oca/models/qc_inspection.py
index 885d841b..8223085d 100644
--- a/quality_control_oca/models/qc_inspection.py
+++ b/quality_control_oca/models/qc_inspection.py
@@ -5,6 +5,8 @@
# Copyright 2017 Simone Rubino - Agile Business Group
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
+from datetime import datetime
+
from odoo import _, api, exceptions, fields, models
from odoo.tools import formatLang
@@ -43,12 +45,14 @@ def _compute_product_id(self):
copy=False,
)
date = fields.Datetime(
+ string="Plan Date",
required=True,
readonly=True,
copy=False,
default=fields.Datetime.now,
states={"draft": [("readonly", False)]},
)
+ date_done = fields.Datetime("Completion Date", readonly=True)
object_id = fields.Reference(
string="Reference",
selection="object_selection_values",
@@ -119,6 +123,14 @@ def create(self, val_list):
vals["name"] = self.env["ir.sequence"].next_by_code("qc.inspection")
return super().create(vals)
+ def write(self, vals):
+ if "state" in vals:
+ if vals["state"] in ["success", "failed"]:
+ vals["date_done"] = datetime.now()
+ elif vals["state"] == "draft":
+ vals["date_done"] = False
+ return super().write(vals)
+
def unlink(self):
for inspection in self:
if inspection.auto_generated:
diff --git a/quality_control_oca/tests/test_quality_control.py b/quality_control_oca/tests/test_quality_control.py
index 9dd08200..2dc20f89 100644
--- a/quality_control_oca/tests/test_quality_control.py
+++ b/quality_control_oca/tests/test_quality_control.py
@@ -67,6 +67,10 @@ def test_inspection_correct(self):
self.assertEqual(self.inspection1.state, "success")
self.inspection1.action_approve()
self.assertEqual(self.inspection1.state, "success")
+ self.assertTrue(bool(self.inspection1.date_done))
+ self.inspection1.action_cancel()
+ self.inspection1.action_draft()
+ self.assertFalse(self.inspection1.date_done)
def test_inspection_incorrect(self):
for line in self.inspection1.inspection_lines:
@@ -86,6 +90,7 @@ def test_inspection_incorrect(self):
self.assertEqual(self.inspection1.state, "waiting")
self.inspection1.action_approve()
self.assertEqual(self.inspection1.state, "failed")
+ self.assertTrue(bool(self.inspection1.date_done))
def test_actions_errors(self):
inspection2 = self.inspection1.copy()
diff --git a/quality_control_oca/views/qc_inspection_view.xml b/quality_control_oca/views/qc_inspection_view.xml
index b02e6cfa..e2079217 100644
--- a/quality_control_oca/views/qc_inspection_view.xml
+++ b/quality_control_oca/views/qc_inspection_view.xml
@@ -78,7 +78,9 @@
+
+
@@ -142,6 +144,9 @@
+
+
+
@@ -171,6 +176,9 @@
domain="[('success', '=', False)]"
/>
+
+
+
+
+