Skip to content

[16.0][MIG] contract_sale_invoicing: backport from 17.0 to 16.0#1402

Open
ChanGuaZzz wants to merge 1 commit intoOCA:16.0from
ChanGuaZzz:16.0-contract_sale_invoicing
Open

[16.0][MIG] contract_sale_invoicing: backport from 17.0 to 16.0#1402
ChanGuaZzz wants to merge 1 commit intoOCA:16.0from
ChanGuaZzz:16.0-contract_sale_invoicing

Conversation

@ChanGuaZzz
Copy link

@ChanGuaZzz ChanGuaZzz commented Mar 9, 2026

backport from 17.0 to 16.0

@luisDIXMIT
Copy link
Contributor

Hi @ChanGuaZzz , preserve commit history please. Also tests and pre-commit is failing.

Copy link

@marcos-mendez marcos-mendez left a comment

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 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_id is accessed before invoice save, which is a critical path in the invoicing logic.
  • Potential race condition: If journal_id is 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 CacheMiss

This 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:

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

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.

3 participants