跳至内容
菜单
此问题已终结
1 回复
300 查看

I am merging two of my custom modules together, and I want to be sure I’m using the right upgrade_util functions.

Context:

  • "Module A" is being merged into "Module B".
  • Module A extends the sale.order model with one custom field (example_field) and an inherited view (sale_order_form_extend).
  • Module A also includes a wizard + its view. (Transient model with multiple fields)

My Question:

Do I need to explicitly use multiple utils (move_field_to_module, remove_view, move_model, etc.) to handle all the difference move/remove processes (fields, views, wizard) before merging?

Or is it enough to just call "merge_module" and "remove_module"? (Will Odoo move my fields and their stored data as well as remove the views that were defined in Module A as part of these utils?)


​Example of what I am think I need to do:

from odoo.upgrade import util

def migrate(cr, version):
​# move fields
​util.move_field_to_module(cr, "sale.order", "example_field", "module_a", "module_b")

# remove old views
​util.remove_view(cr, xml_id="module_a.sale_order_form_extend")

​# move wizard fields
​util.move_field_to_module(cr, "example.wizard", "fields...")

​​# Remove wizard view
​util.remove_view(cr, xml_id="module_a.wizard_form_view")


​# move wizard (model)
​util.move_model(cr, "example.wizard", "module_a", "module_b")


# merge modules
util.merge_module(cr, "module_a", "module_b")

# remove old module
util.remove_module(cr, "module_a")​​​​

OR is it as simple as doing the following:

from odoo.upgrade import util

def migrate(cr, version):

# merge modules
util.merge_module(cr, "module_a", "module_b")

# remove old module
util.remove_module(cr, "module_a")​​​​

I have already checked the Odoo documentation and I cannot determine which way I need to go. Any clarification is appreciated, thanks in advance! 

形象
丢弃
最佳答案

Hi,

When merging custom modules in Odoo, the behavior of merge_module and remove_module is very specific, and it does not automatically handle everything you might expect.

Since Module A is being fully merged into Module B:


You can usually just call:

from odoo.upgrade import util

def migrate(cr, version):

    util.merge_module(cr, "module_a", "module_b")

    util.remove_module(cr, "module_a")

The field example_field on sale. order and the wizard model will now belong to Module B, and the stored data is safe.

The views and actions will also now belong to Module B.


Hope it helps.

形象
丢弃
相关帖文 回复 查看 活动
1
9月 25
2151
1
7月 24
2436
1
6月 24
4271
1
1月 23
3041
1
11月 24
2017