Skip to content

[16.0][IMP] mgmtsystem_nonconformity_quality_control_oca: auto-create nonco…#760

Open
quirino95 wants to merge 1 commit into
OCA:16.0from
PyTech-SRL:16.0-create_nonconformity
Open

[16.0][IMP] mgmtsystem_nonconformity_quality_control_oca: auto-create nonco…#760
quirino95 wants to merge 1 commit into
OCA:16.0from
PyTech-SRL:16.0-create_nonconformity

Conversation

@quirino95

Copy link
Copy Markdown

Added new flag "Create Nonconformity" on products.

When an inspection related to a picking fails, related nonconformities are automatically created for all products having the flag active.

@quirino95 quirino95 force-pushed the 16.0-create_nonconformity branch 2 times, most recently from 236b1bc to 9c604f9 Compare December 3, 2025 11:29
@quirino95 quirino95 marked this pull request as ready for review December 3, 2025 11:32

@HekkiMelody HekkiMelody left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code review, LGTM

@quirino95 quirino95 force-pushed the 16.0-create_nonconformity branch from 9c604f9 to 420cc1b Compare February 2, 2026 14:41

@marcos-mendez marcos-mendez left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Automated Review -- Tests Failed

1. Root Cause

The test failure is caused by a database connection error during the Odoo startup, which is unrelated to the code changes in this PR. This is likely due to an infrastructure or environment issue in the CI/runner setup (e.g., PostgreSQL not running or misconfigured).


2. Suggested Fix

There is no code fix needed for the test failure itself, as it's a runtime environment issue. However, to ensure robustness of the module:

  • In qc_inspection.py, line 53: The condition if self.state == "failed" and self.product_id.create_nonconformity: should be safe, but to avoid potential errors if self.product_id is False, add a null check:
    if self.state == "failed" and self.product_id and self.product_id.create_nonconformity:

3. Additional Code Issues

  • Missing null check in action_approve: If self.product_id is False (e.g., inspection is not linked to a product), the code will raise an AttributeError. This should be guarded.
    • File: mgmtsystem_nonconformity_quality_control_oca/models/qc_inspection.py
    • Line: 53

4. Test Improvements

The current tests cover basic functionality, but could be improved with:

  • TransactionCase tests using SavepointCase to test edge cases:
    • Test with a product that has create_nonconformity = True but inspection is not linked to a product.
    • Test with inspection state not set to "failed" — ensure no NC is created.
    • Test that the created NC has correct values for qc_inspection_id, name, description, etc.

Example test case to add:

def test_create_nonconformity_with_no_product(self):
    self.inspection2.write({"state": "failed", "object_id": False})
    self.inspection2.action_approve()
    nc = self.env["mgmtsystem.nonconformity"].search([("qc_inspection_id", "=", self.inspection2.id)])
    self.assertFalse(nc)

Use tagged tests (e.g., @tag('post_install')) for tests that require data setup or module dependencies.


Summary

  • The test failure is environment-related, not code-related.
  • Add a null check for self.product_id in action_approve.
  • Improve test coverage using SavepointCase and TransactionCase with edge cases.

⏰ PR Aging Alert

This PR by @quirino95 has been open for 103 days (3 months).
💤 Last activity was 41 days ago.

Every ignored PR is a contributor who might not come back. Review time matters. (OCA Aging Report)


Reciprocal Review Request

Hi everyone! I found some test failures on this PR and left detailed feedback above. I am happy to discuss or help debug. In the meantime, if any of you get a chance, I would appreciate a look at my open PR(s):

My open PRs across OCA:

Reviewing each other's work helps the whole community move forward. Thank you!


Environment via OCA Neural Reviewer: Minikube + K8s Job + oca-ci/py3.10-odoo16.0 | Odoo 16.0
Automated review by OCA Neural Reviewer + qwen3-coder:30b

@SirPyTech SirPyTech left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for the PR!
I only reviewed the code and have a few suggestions, also not the issue that could raise an exception

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.

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.

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 🙏

Comment on lines +71 to +72
Test Nonconformity creation when inspection fails
if relative flag is off

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?

Comment on lines +83 to +86
"""
Test Nonconformity doesn't create when inspection fails
if relative flag is on
"""

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.

<!-- 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

@max3903 max3903 added this to the 16.0 milestone May 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants