Skip to content

[18.0][FIX] contract: flush_recordset([create_date])#1480

Open
CristianoMafraJunior wants to merge 1 commit into
OCA:18.0from
Escodoo:18.0-fix-_set_start_contract_modification
Open

[18.0][FIX] contract: flush_recordset([create_date])#1480
CristianoMafraJunior wants to merge 1 commit into
OCA:18.0from
Escodoo:18.0-fix-_set_start_contract_modification

Conversation

@CristianoMafraJunior

Copy link
Copy Markdown
Member

Summary

Fix a MissingError raised when accessing record.create_date inside
_set_start_contract_modification during a fresh database installation with
demo data.

Root Cause

In Odoo 18, the create() flow was redesigned to support precompute=True
fields. The new sequence is:

  1. A virtual NewId is assigned to the record (not yet in the database).
  2. All precompute=True fields are computed in memory.
  3. The SQL INSERT is executed, writing the record to the database.
  4. Code after super().create() continues.

create_date is a database-generated value (set by PostgreSQL at INSERT time).
The ORM does not precompute it, and in Odoo 18 it may not be loaded into
the ORM cache automatically after the INSERT returns.

When _set_start_contract_modification runs immediately after
super().create(), and the contract has no lines yet (e.g., when contracts are
created before their lines in demo/fixture data), the code reaches:

else:
    date_start = record.create_date  # MissingError: record not found in cache

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants