在视图级别创建 odoo 模型

Create odoo model on view level

我们能否在 odoo 中创建一个模型,使其无法反映在数据库级别?

例如:

class SalaOrder(model.models):
    _name='sale.order'

我不想在数据库中创建 "sale_order" table。

根据 models.py (odoo/odoo/models.py) 的评论,您可以将 _auto 设置为 False.

class SalaOrder(model.models):
    _name = 'sale.order'
    _auto = False

评论说

_auto = False # don't create any database backend

以下是有关 Odoo 模型的更多详细信息(来自同一代码):

Odoo models are created by inheriting:

  • :class:Model for regular database-persisted models

  • :class:TransientModel for temporary data, stored in the database but automatically vacuumed every so often

  • :class:AbstractModel for abstract super classes meant to be shared by multiple inheriting models

The system automatically instantiates every model once per database. Those instances represent the available models on each database, and depend on which modules are installed on that database. The actual class of each instance is built from the Python classes that create and inherit from the corresponding model.

Every model instance is a "recordset", i.e., an ordered collection of records of the model. Recordsets are returned by methods like :meth:~.browse, :meth:~.search, or field accesses. Records have no explicit representation: a record is represented as a recordset of one record.

To create a class that should not be instantiated, the _register class attribute may be set to False.