Skip to content

Commit

Permalink
[IMP] quality_control_oca: add date_done field, update views, and add…
Browse files Browse the repository at this point in the history
… filters
  • Loading branch information
AungKoKoLin1997 committed Jun 7, 2024
1 parent ea08560 commit b290d21
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
12 changes: 12 additions & 0 deletions quality_control_oca/models/qc_inspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions quality_control_oca/tests/test_quality_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()
Expand Down
20 changes: 20 additions & 0 deletions quality_control_oca/views/qc_inspection_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@
<field name="product_id" />
</group>
<group>
<field name="create_date" string="Create Date" />
<field name="date" />
<field name="date_done" />
<field name="success" />
<field name="auto_generated" />
</group>
Expand Down Expand Up @@ -142,6 +144,9 @@
<field name="test" />
<field name="qty" />
<field name="product_id" />
<field name="create_date" optional="show" />
<field name="date" optional="show" />
<field name="date_done" optional="show" />
<field name="success" />
<field name="state" />
</tree>
Expand Down Expand Up @@ -171,6 +176,9 @@
domain="[('success', '=', False)]"
/>
<newline />
<separator />
<filter name="plan_date" string="Plan Date" date="date" />
<filter name="date_done" string="Completion Date" date="date_done" />
<group expand="0" string="Group by...">
<filter
string="Reference"
Expand Down Expand Up @@ -214,6 +222,18 @@
domain="[]"
context="{'group_by': 'auto_generated'}"
/>
<filter
string="Plan Date"
name="groupby_date"
domain="[]"
context="{'group_by': 'date'}"
/>
<filter
string="Completion Date"
name="groupby_date_done"
domain="[]"
context="{'group_by': 'date_done'}"
/>
</group>
</search>
</field>
Expand Down

0 comments on commit b290d21

Please sign in to comment.