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 6, 2024
1 parent ea08560 commit e1f110e
Show file tree
Hide file tree
Showing 2 changed files with 32 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(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
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" />
<field name="date" />
<field name="date_done" />
<field name="success" />
<field name="auto_generated" />
</group>
Expand Down Expand Up @@ -138,6 +140,9 @@
<field name="arch" type="xml">
<tree>
<field name="name" />
<field name="create_date" optional="show" />
<field name="date" optional="show" />
<field name="date_done" optional="show" />
<field name="user" />
<field name="test" />
<field name="qty" />
Expand Down Expand Up @@ -171,6 +176,9 @@
domain="[('success', '=', False)]"
/>
<newline />
<separator />
<filter name="month" string="Plan Date" date="date" />
<filter name="month" string="Date Done" 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="Date Done"
name="groupby_date_done"
domain="[]"
context="{'group_by': 'date_done'}"
/>
</group>
</search>
</field>
Expand Down

0 comments on commit e1f110e

Please sign in to comment.