[16.0][IMP] mgmtsystem_nonconformity_quality_control_oca: auto-create nonco…#760
[16.0][IMP] mgmtsystem_nonconformity_quality_control_oca: auto-create nonco…#760quirino95 wants to merge 1 commit into
Conversation
236b1bc to
9c604f9
Compare
9c604f9 to
420cc1b
Compare
marcos-mendez
left a comment
There was a problem hiding this comment.
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 conditionif self.state == "failed" and self.product_id.create_nonconformity:should be safe, but to avoid potential errors ifself.product_idisFalse, 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: Ifself.product_idisFalse(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
- File:
4. Test Improvements
The current tests cover basic functionality, but could be improved with:
- TransactionCase tests using
SavepointCaseto test edge cases:- Test with a product that has
create_nonconformity = Truebut 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.
- Test with a product that has
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_idinaction_approve. - Improve test coverage using
SavepointCaseandTransactionCasewith 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:
- server-tools#3554 [MIG] datetime_formatter: Migration to 18.0
- server-tools#3548 [18.0][MIG] base_kanban_stage: Migration to 18.0
- hr-attendance#262 [16.0][ADD] Hr_attendance_idsecure: iDSecure (ControliD) attendance integration
- stock-logistics-workflow#2276 [16.0][ADD] stock_move_line_devaluation
- stock-logistics-workflow#2275 [16.0][ADD] Stock move line analytic account
- stock-logistics-workflow#2268 [16.0][ADD] stock_move_line_picking_partner
- purchase-workflow#2694 [16.0][IMP]Purchase workflow added to review state & exception fix
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
left a comment
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
suggestion: Since this is a configuration, it could be also mentioned in a CONFIGURE fragment.
There was a problem hiding this comment.
praise: Thanks for covering this improvement with tests 🙏
| Test Nonconformity creation when inspection fails | ||
| if relative flag is off |
There was a problem hiding this comment.
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?
| """ | ||
| Test Nonconformity doesn't create when inspection fails | ||
| if relative flag is on | ||
| """ |
There was a problem hiding this comment.
suggestion: This test actually checks that the the nonconfromity record is created.
| """ | |
| 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() |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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
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.