In Odoo 17, creating a new instance of the Environment
class with a separate database transaction (cr
) involves manually managing the database cursor and environment. This is useful for isolated operations (e.g., background tasks, logging, or multi-database interactions). Below is a step-by-step guide:
- Environment: Combines a database cursor (
cr
), user ID (uid
), and context. - Registry: Holds the database models and connection pool.
- Manual Transaction Control: You must explicitly
commit()
/rollback()
andclose()
the cursor.