[16.0][FIX] account_invoice_supplierinfo_update: product_id write in tests #2211
+1
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@BinhexTeam
Problem
The test suite of the module account_invoice_supplierinfo_update fails on Odoo 16 during CI execution (Codecov / runbot).
The failure occurs in test_get_the_right_variant_supplierinfo, when writing a new product variant on an existing invoice line:
• The test passes a recordset to a many2one field (product_id) in a write() call.
• In Odoo 16, the accounting framework (account.move._field_will_change) strictly expects IDs (integers) in write() values.
• This results in a type mismatch and causes the test to fail with warnings and errors during coverage execution.
Root Cause
In Odoo 16, the method _field_will_change() compares:
record[field_name].id != vals[field_name]
When vals[field_name] is a recordset instead of an integer, the comparison becomes invalid and triggers a runtime warning / failure.
The test was implicitly relying on older permissive behavior, which is no longer valid in Odoo 16.
Solution
Update the test to comply with the Odoo ORM API by always passing IDs (integers) when writing to many2one fields.
Specifically:
• Replace the recordset assignment to product_id with its .id.
This is a minimal, safe, and fully backward-compatible fix that restores test stability without altering any functional behavior.
Implementation Details
• Update the failing test to write product_id as an integer:
self.line_a.write({"product_id": product_a_2.id, "price_unit": 400})
Tests
• Existing tests now pass successfully on Odoo 16.
• No new tests were required, as this change restores correctness in an existing regression test.
Scope & Compatibility
• Test-only fix.
• No functional or behavioral changes.
• Fully compatible with Odoo 16 and aligned with OCA coding standards.
• Prevents CI and Codecov failures.
Conclusion
This PR fixes a test incompatibility introduced by stricter ORM behavior in Odoo 16 by ensuring that many2one fields are written using integer IDs, as required by the framework.
The change is minimal, correct, and keeps the test suite reliable and CI-safe.