20

我有一些扩展 Odoo 附加组件的模块。例如,my_module其中 expand的模型crm

class Lead(models.Model):
    _inherit = 'crm.lead'
    # exmaple fields
    field_1 = fields.Char(...)
    field_2 = fields.Many2one(...)
    # ... field 99


class Stage(models.Model):
    _inherit = 'crm.stage'
    # exmaple fields
    field_1 = fields.Char(...)
    field_2 = fields.Many2one(...)
    # ... field 99

对于扩展hr,product等的模块也是如此。我需要对模型进行一些更改。例如,在中my_module_1,我需要更改几个字段(类型,关系),在中my_module_2,只是为了删除一些字段等。当然我还需要更改每个模块的视图。当然,我有我的自定义模型,这些模型与来自不同应用程序/模块的模型有依赖关系。但我有必须存储的生产数据。我没有在 Odoo 中找到有关迁移(或模块同步)的任何信息。

我的问题是:在生产中更新模块/应用程序的最佳方式是什么(如果我们在模型和视图领域有很多变化)?提前致谢。

4

5 回答 5

2

My question is: What is the best way to update modules/apps on production(if we have many changes in fields of models and views)?

While this question has been around for a while I cannot see any canonical answer therefore here are my two cents.

The problem of migration from one version to another in Odoo is rather common and definitely complicated. With that in mind the OpenUpgrade project has been created. OpenUpgrade is basically an upgrade path that will help you transform your data and models from version A to version B. For example if a field named fieldA has had its type changed on version 9 and you are on version 8, OpenUpgrade will take care of this by doing the necessary transformations.

OpenUpgrade also gives you the possibility to create your own migration scripts that will do whatever needs to be done in order for your module to be forward ported (or back ported) in various versions. For the standard modules these scripts have already been written to an extend, but for your own you might need to do some writing.

I suggest that you take a look at the documentation above, this is basically your first stop when we talk about migrations in Odoo.


于 2018-11-08T14:48:28.733 回答
0

首先,您必须转储生产数据库,然后在本地系统中恢复它。

在本地系统中恢复后,开发您的自定义模块以扩展现有模型功能。

在本地系统(恢复的数据库)中安装开发的模块并查看您所做的更改。如果现有数据一切正常,则将该模块安装到生产数据库中。

要转储生产数据库,请在 postgres 中执行以下命令。命令:pg_dump dbname > outfile 示例:pg_dump prod_db > prod_db.sql

在恢复数据库之前,您必须在本地系统中创建新的数据库。要创建新数据库,请执行以下命令,命令: createdb --owner owner_name --encoding utf-8 dbname 示例: createdb --owner odoo --encoding utf-8 prod_db

要恢复生产数据库,请在 postgres 中执行以下命令。命令:psql dbname < infile 路径示例:pg_dump prod_db > prod_db.sql

于 2016-01-08T08:25:22.060 回答
0

也许在 Odoo企业版中有一些用于迁移的工具,但我还没有找到任何关于这方面的信息。所以我使用的解决方案是手动完成所有操作。一步一步,用心。如果您知道更好的方法,请告诉我。

例如。如果我们需要删除一些字段:

  1. 从模块/应用程序中的模型和视图中删除字段。
  2. 停止 openerp-server。运行删除我们的列的 sql。
  3. 将新版本的模型和视图部署到服务器。启动 openerp-server
  4. 激活开发者模式-> 进入设置 -> 找到你的模块/应用程序 -> 点击更新(升级)

如果您需要更改字段的类型/关系:

  1. 向您的模型添加一个字段(具有新类型/关系)。
  2. 准备将数据从旧列传输到新列/表的 sql 脚本。
  3. 从模型和视图中删除旧字段。
  4. 停止 openerp-server。运行 sql 脚本,删除旧列。
  5. 将新版本的模型和视图部署到服务器。启动 openerp-server
  6. 激活开发者模式-> 进入设置 -> 找到你的模块/应用程序 -> 点击更新(升级)

更改关系时要小心(one2many,many2many)。制作应用程序的转储和版本。使用生产中的 db 在本地计算机上检查您的修改几次。

关于具有关系的新领域的另一件事。例如,我有module_1取决于crmmodule_2取决于module_1等。我需要向crm模型添加一些字段并在module_1中显示它们。在module_2 中,我需要在 module_1 中显示我的自定义模型中的新字段

我们可以将所有新字段添加到模块中的模型和视图中。停止服务器并使用参数--update运行服务器,如下所示:

./openerp-server --update=all

在这种情况下,所有模块都将更新。如果我们只需要更新依赖于crm的模块,我们只需要更新crm

./openerp-server --update=crm
于 2016-01-13T20:48:08.087 回答
0

使用 -u 和 -d 标志从命令行重新启动服务器一次,例如。

sudo service odoo stop
/path/to/odoo/odoo.py -d <your_db_name> -u custom_module1,custom_module2

如果您正在处理生产服务器,我将在您的开发机器上使用生产数据库的新转储在本地进行测试,确保它可以正常工作,如果需要进行调整(例如,某些字段可能需要默认值,无论如何),测试它再次在另一个新的转储上,直到我需要做的就是如上所述重新启动服务器以进行更改。一旦发生这种情况,在生产服务器上备份数据库、数据存储甚至受影响的模块,上传新模块并如上所述重新启动生产服务器(这里没有将数据库从测试转储到生产)模块更新应该小心数据库更改。

如果您尝试显着更改表的结构(例如更改字段数据类型)并在表中保留数据,我能想到的唯一方法是首先使用新数据类型创建添加新字段,然后用来自的数据填充它们旧字段(直接使用 postgres 查询或在“临时版本模块”中),这实际上取决于更改,从选择到 many2one 的更改涉及将选择值插入新表,从数据库的角度来看,这是两个非常不同的事情表上的实际字段类型将是一个整数,即关系表中保存选择值的行的 ID...

填充新字段后,使模块的最终版本删除您不再需要的所有字段(保留生产数据库的其他版本)。

我可能会首先在 postgres 或使用 pgadminIII 之类的工具在开发服务器上手动测试数据库填充,但计划创建一个脚本以在生产服务器上执行此操作(或者更好地将其全部构建到新模块版本中)作为发生这种情况时,它必须关闭。

完成后我还会查看我的 postgres 表,即使新模块不使用它们,某些字段可能仍然存在。

抱歉,我不知道有什么更简单、更自动化的方法,只是变量太多了......

于 2016-05-04T15:42:57.503 回答
0

根据您的示例,我相信您已经知道如何向现有模型添加新字段。

我仍然不明白为什么有人想从现有模型中删除一个字段——这会/将比它的价值更麻烦(如果有正当理由,请告诉我)。这也适用于尝试重铸字段类型。话虽如此,您可以很容易地删除/替换/隐藏视图上的现有字段,这在本质上应该达到相同的结果。

https://www.odoo.com/forum/help-1/question/add-remove-fields-to-inherited-custom-module-72945

<record model="ir.ui.view" id="enter_an_id_here">
    <field name="name">some.text.here.form</field>
    <field name="model">crm.lead</field>
    <field name="inherit_id" ref="crm.external_id_here" />
    <field name="arch" type="xml">
        <field name="name" position="after">
            <field name="your_field_name"/>
        </field>
    </field>
</record>

您还谈到了通过复制/粘贴将数据从依赖项迁移到另一个模型。这不是必需的,因为您可以通过直接对象/字段引用或使用相关字段来简单地访问现有模型中的数据。

odoo 上的相关领域?

new_field = fields.Char(string='String', related='product_id.name')
or inside python
value = self.product_id.name

I will not address anything to do with installing the module/server side commands as the other answers here have already addressed these aspects.

于 2016-09-23T03:58:28.783 回答