-
-
Notifications
You must be signed in to change notification settings - Fork 357
[16.0][IMP] mgmtsystem_nonconformity_quality_control_oca: auto-create nonco… #760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 16.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
|---|---|---|
|
|
@@ -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. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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( | ||||||||||||||||||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||||||||||||||||||
| """ | ||||||||||||||||||
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||||||||||||||
| self.product.create_nonconformity = True | ||||||||||||||||||
| self.inspection2.write({"state": "failed"}) | ||||||||||||||||||
| self.inspection2.action_approve() | ||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| <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> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: if
selfis a recordset, accessingself.stateraises the errorplease loop on
selfand callcreate_nonconformityonly on appropriate inspections.A test checking approval of multiple inspections would also prevent a regression.