[16.0][MIG] contract_sale_invoicing: backport from 17.0 to 16.0#1402
[16.0][MIG] contract_sale_invoicing: backport from 17.0 to 16.0#1402ChanGuaZzz wants to merge 1 commit intoOCA:16.0from
Conversation
|
Hi @ChanGuaZzz , preserve commit history please. Also tests and pre-commit is failing. |
marcos-mendez
left a comment
There was a problem hiding this comment.
Automated Review -- Tests Failed
1. Root Cause
The test failure occurs because the journal_id field is accessed on a newly created account.move record that hasn't been saved to the database yet, causing a CacheMiss error. This happens in the _recurring_create_invoice method when trying to access invoice.journal_id before the invoice is fully initialized.
2. Suggested Fix
In /tmp/repo/contract_sale_invoicing/models/contract.py, line 38, the method _recurring_create_invoice should ensure that the invoice is properly created and saved before accessing its journal_id. Specifically, after creating the invoice, it should call invoice._compute_journal_id() or ensure the invoice is flushed to the database before accessing invoice.journal_id.
Alternatively, if the access is only needed for logic that doesn't require the full record state, consider using a domain or conditional check that doesn't rely on journal_id directly.
3. Additional Code Issues
- Missing test coverage: The test suite does not cover the scenario where
journal_idis accessed before invoice save, which is a critical path in the invoicing logic. - Potential race condition: If
journal_idis accessed without ensuring the invoice is saved, it could lead to inconsistent behavior in multi-user or concurrent environments.
4. Test Improvements
Add a TransactionCase test in tests/test_contract_sale_invoicing.py to simulate the exact scenario where an invoice is created and then journal_id is accessed, ensuring that the invoice is properly saved before accessing the field. This aligns with OCA testing best practices for modules that extend core Odoo functionality.
Example test case:
def test_journal_id_access_after_creation(self):
# Create a contract with pending sales orders
contract = self.env['contract.contract'].create({
'name': 'Test Contract',
'partner_id': self.partner.id,
'recurring_create_invoice': True,
'invoicing_sales': True,
})
# Ensure the contract has pending sales orders
# ...
# Call the method that creates invoice and accesses journal_id
# Verify that journal_id is accessible without CacheMissThis test should be tagged with @tag('post_install', 'manual') if it requires data setup or @tag('standard') if it's a unit test.
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#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
backport from 17.0 to 16.0