Skip to content

Commit

Permalink
[FIX] project, sale_timesheet: common field between non-dependent mod…
Browse files Browse the repository at this point in the history
…ules workaround

The project and sale_timesheet modules both define a project_time_mode_id field on res.company but they are not dependent on each other. This causes problem because the first module that creates the field "wins" the xmlid and will delete the field on uninstall, regardless of the other module (which will then stop working until you do an update that will recreate the field).

To work around this in a stable version, we manually create xmlids for the field in each module; on uninstall the field will not be deleted if an xmlid still refers it (which will be the case if the other module is installed).

Inheriting fields from modules that are not dependent in a direct way (ancestor-child) is not supported, so normally you should use modularity to define the field in a parent module. Since 9.0 is a stable version, we need a small workaround.
  • Loading branch information
bouvyd committed Oct 16, 2015
1 parent be5fc7b commit 31ff6c6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
12 changes: 11 additions & 1 deletion addons/project/project_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@
<!-- alias domain: project.config.settings -->
<function id="default_alias_domain_project" model="ir.values" name="set_default" eval="('project.config.settings', 'generate_project_alias', 1)"/>


<!-- sale_timesheet and project define the same field without depending on each, which causes the field to be deleted when the module that created it
is deleted. To avoid this, we create xmlids manually for this field in both modules to prevent accidental deletion. To fix in saas-7 by moving the field definition-->
<record id="duplicate_field_xmlid" model="ir.model.data">
<field name="res_id" search="[('model','=','res.company'),('name','=','project_time_mode_id')]" model="ir.model.fields"/>
<field name="model">ir.model.fields</field>
<field name="module">project</field>
<field name="name">project_time_mode_id_duplicate_xmlid</field>
<field name="noupdate">True</field>
</record>

</data>
<data>

Expand Down Expand Up @@ -319,6 +330,5 @@
<field name="displayed_image_id" ref="msg_task_data_14_attach"/>
</record>


</data>
</openerp>
3 changes: 2 additions & 1 deletion addons/sale_timesheet/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
'author': 'OpenERP SA',
'website': 'https://www.odoo.com/page/warehouse',
'depends': ['sale', 'hr_timesheet'],
'data': ['views/sale_timesheet_view.xml'],
'data': ['views/sale_timesheet_view.xml',
'data/sale_timesheet_data.xml'],
'demo': ['data/sale_timesheet_demo.xml'],
'installable': True,
'auto_install': True,
Expand Down
16 changes: 16 additions & 0 deletions addons/sale_timesheet/data/sale_timesheet_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">

<!-- sale_timesheet and project define the same field without depending on each, which causes the field to be deleted when the module that created it
is deleted. To avoid this, we create xmlids manually for this field in both modules to prevent accidental deletion. To fix in saas-7 by moving the field definition-->
<record id="duplicate_field_xmlid" model="ir.model.data">
<field name="res_id" search="[('model','=','res.company'),('name','=','project_time_mode_id')]" model="ir.model.fields"/>
<field name="model">ir.model.fields</field>
<field name="module">sale_timesheet</field>
<field name="name">project_time_mode_id_duplicate_xmlid</field>
<field name="noupdate">True</field>
</record>
</data>

</odoo>

0 comments on commit 31ff6c6

Please sign in to comment.