Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mgmtsystem_nonconformity_quality_control_oca/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ This module contains some new features for Management System modules.
Nonconformity (NC)

* Quality Control Inspection: add a field to link a specific quality control inspection.
* Activating "Create Nonconformity" flag on products, for every failed inspection, a new Nonconformity will be opened.

**Table of contents**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"data": [
"views/qc_inspection.xml",
"views/mgmtsystem_nonconformity.xml",
"views/product_template.xml",
],
"demo": [],
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import mgmtsystem_nonconformity
from . import product_template
from . import qc_inspection
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from odoo import fields, models


class ProductTemplate(models.Model):
_inherit = "product.template"

create_nonconformity = fields.Boolean(
string="Create Non-Conformity",
help="If selected, automatically creates Nonconformity when inspections fail",
)
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,24 @@ def action_view_nonconformities(self):
"default_company_id": self.company_id.id,
}
return action

def action_approve(self):
res = super().action_approve()

if self.state == "failed" and self.product_id.create_nonconformity:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: if self is a recordset, accessing self.state raises the error

  [...]
  File "/opt/odoo/custom/src/odoo/odoo/fields.py", line 1154, in __get__
    record.ensure_one()
  File "/opt/odoo/custom/src/odoo/odoo/models.py", line 5222, in ensure_one
    raise ValueError("Expected singleton: %s" % self)

please loop on self and call create_nonconformity only on appropriate inspections.
A test checking approval of multiple inspections would also prevent a regression.

self.create_nonconformity()

return res

def create_nonconformity(self):
self.env["mgmtsystem.nonconformity"].create(
{
"name": self.name,
"partner_id": self.user.partner_id.id,
"origin_ids": self.env.ref("mgmtsystem_nonconformity.nc_origin_qc"),
"responsible_user_id": self.user.id,
"manager_user_id": self.user.id,
"description": "Automatically created due to failure of the linked inspection.",
"qc_inspection_id": self.id,
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ This module contains some new features for Management System modules.
Nonconformity (NC)

* Quality Control Inspection: add a field to link a specific quality control inspection.
* Activating "Create Nonconformity" flag on products, for every failed inspection, a new Nonconformity will be opened.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Since this is a configuration, it could be also mentioned in a CONFIGURE fragment.

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand All @@ -9,10 +8,11 @@

/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -275,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -301,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -375,6 +375,7 @@ <h1 class="title">Mgmtsystem Nonconformity Quality Control Oca</h1>
<p>Nonconformity (NC)</p>
<ul class="simple">
<li>Quality Control Inspection: add a field to link a specific quality control inspection.</li>
<li>Activating “Create Nonconformity” flag on products, for every failed inspection, a new Nonconformity will be opened.</li>
</ul>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
Expand Down Expand Up @@ -427,7 +428,9 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
Expand Down

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: Thanks for covering this improvement with tests 🙏

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ def setUpClass(cls):
{"name": "Test Inspection", "inspection_lines": inspection_lines}
)

cls.product = cls.env["product.product"].create({"name": "Test product"})
cls.inspection2 = cls.inspection_model.create(
{
"name": "Test Inspection 2",
"inspection_lines": inspection_lines,
"object_id": cls.product,
}
)

cls.nc_model = cls.env["mgmtsystem.nonconformity"]
cls.partner = cls.env["res.partner"].search([])[0]
cls.nc_test = cls.nc_model.create(
Expand Down Expand Up @@ -56,3 +65,31 @@ def test_action_view_nonconformities(self):
nc_ids.append(nc.id)

self.assertEqual(nc_ids, action["domain"][0][2])

def test_no_create_nonconformity(self):
"""
Test Nonconformity creation when inspection fails
if relative flag is off
Comment on lines +71 to +72

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: I don't understand this docstring: this says it is testing nonconformity creation, but there is no nonconformity record being created in the test; on the contrary: the test is actually checking that no nonconformity record is being created.
Could you please clarify the docstring?

"""
self.inspection2.write({"state": "failed"})
self.inspection2.action_approve()

nc = self.env["mgmtsystem.nonconformity"].search(
[("qc_inspection_id", "=", self.inspection2.id)]
)
self.assertFalse(nc)

def test_create_nonconformity(self):
"""
Test Nonconformity doesn't create when inspection fails
if relative flag is on
"""
Comment on lines +83 to +86

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: This test actually checks that the the nonconfromity record is created.

Suggested change
"""
Test Nonconformity doesn't create when inspection fails
if relative flag is on
"""
"""
Test Nonconformity is created when inspection fails
if relative flag is on
"""

self.product.create_nonconformity = True
self.inspection2.write({"state": "failed"})
self.inspection2.action_approve()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Please check there are no nonconformities before approval, otherwise this test might pass for a false positive.


nc = self.env["mgmtsystem.nonconformity"].search(
[("qc_inspection_id", "=", self.inspection2.id)]
)
self.assertEqual(len(nc), 1)
self.assertEqual(self.inspection2.id, nc.qc_inspection_id.id)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
<record model="ir.ui.view" id="product_template_form_view">
<field name="name">product.template.common.qc</field>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: The name of this view should briefly describe what it's doing, this is just copy/pasted from the inherited view.
Please mention something about nonconformities

<field name="model">product.template</field>
<field name="inherit_id" ref="quality_control_oca.product_template_form_view" />
<field name="arch" type="xml">
<xpath expr="//field[@name='qc_triggers']" position="before">
<field name="create_nonconformity" />
</xpath>
</field>
</record>
</odoo>