Browse Source

Merge pull request #1506 from hbrunn/10.0-database_cleanup-fix_false_default_properties

[FIX][database_cleanup] don't destroy values when there are empty default properties
pull/680/merge
Pedro M. Baeza 6 years ago
committed by GitHub
parent
commit
1245634381
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 28
      database_cleanup/models/purge_properties.py
  2. 2
      database_cleanup/views/create_indexes.xml
  3. 4
      database_cleanup/views/purge_columns.xml
  4. 4
      database_cleanup/views/purge_data.xml
  5. 4
      database_cleanup/views/purge_menus.xml
  6. 4
      database_cleanup/views/purge_models.xml
  7. 4
      database_cleanup/views/purge_modules.xml
  8. 2
      database_cleanup/views/purge_properties.xml
  9. 4
      database_cleanup/views/purge_tables.xml

28
database_cleanup/models/purge_properties.py

@ -4,6 +4,8 @@
from odoo import api, models, fields from odoo import api, models, fields
REASON_DUPLICATE = 1 REASON_DUPLICATE = 1
REASON_DEFAULT = 2 REASON_DEFAULT = 2
REASON_DEFAULT_FALSE = 3
REASON_UNKNOWN_MODEL = 4
class CleanupPurgeLineProperty(models.TransientModel): class CleanupPurgeLineProperty(models.TransientModel):
@ -17,6 +19,8 @@ class CleanupPurgeLineProperty(models.TransientModel):
reason = fields.Selection([ reason = fields.Selection([
(REASON_DUPLICATE, 'Duplicated property'), (REASON_DUPLICATE, 'Duplicated property'),
(REASON_DEFAULT, 'Same value as default'), (REASON_DEFAULT, 'Same value as default'),
(REASON_DEFAULT_FALSE, 'Empty default property'),
(REASON_UNKNOWN_MODEL, 'Unknown model'),
]) ])
@api.multi @api.multi
@ -42,6 +46,27 @@ class CleanupPurgeWizardProperty(models.TransientModel):
]) ])
handled_field_ids = [] handled_field_ids = []
for prop in default_properties: for prop in default_properties:
value = None
try:
value = prop.get_by_record()
except KeyError:
result.append({
'name': '%s@%s: %s' % (
prop.name, prop.res_id, value,
),
'property_id': prop.id,
'reason': REASON_UNKNOWN_MODEL,
})
continue
if not value:
result.append({
'name': '%s@%s: %s' % (
prop.name, prop.res_id, value,
),
'property_id': prop.id,
'reason': REASON_DEFAULT_FALSE,
})
continue
if prop.fields_id.id in handled_field_ids: if prop.fields_id.id in handled_field_ids:
continue continue
domain = [ domain = [
@ -76,7 +101,8 @@ class CleanupPurgeWizardProperty(models.TransientModel):
for redundant_property in self.env['ir.property'].search(domain): for redundant_property in self.env['ir.property'].search(domain):
result.append({ result.append({
'name': '%s@%s: %s' % ( 'name': '%s@%s: %s' % (
prop.name, prop.res_id, prop.get_by_record()
prop.name, redundant_property.res_id,
prop.get_by_record()
), ),
'property_id': redundant_property.id, 'property_id': redundant_property.id,
'reason': REASON_DEFAULT, 'reason': REASON_DEFAULT,

2
database_cleanup/views/create_indexes.xml

@ -39,7 +39,7 @@
<field name="type">ir.actions.server</field> <field name="type">ir.actions.server</field>
<field name="state">code</field> <field name="state">code</field>
<field name="model_id" ref="database_cleanup.model_cleanup_create_indexes_line" /> <field name="model_id" ref="database_cleanup.model_cleanup_create_indexes_line" />
<field name="code">env.get('cleanup.create_indexes.line').purge()</field>
<field name="code">records.purge()</field>
</record> </record>
<record id="cleanup_create_indexes_line_action_value" model="ir.values"> <record id="cleanup_create_indexes_line_action_value" model="ir.values">

4
database_cleanup/views/purge_columns.xml

@ -37,9 +37,7 @@
<field name="type">ir.actions.server</field> <field name="type">ir.actions.server</field>
<field name="state">code</field> <field name="state">code</field>
<field name="model_id" ref="database_cleanup.model_cleanup_purge_line_column" /> <field name="model_id" ref="database_cleanup.model_cleanup_purge_line_column" />
<field name="code">
env.get('cleanup.purge.line.column').purge()
</field>
<field name="code">records.purge()</field>
</record> </record>
<record id="action_purge_column_line_value" model="ir.values"> <record id="action_purge_column_line_value" model="ir.values">

4
database_cleanup/views/purge_data.xml

@ -37,9 +37,7 @@
<field name="type">ir.actions.server</field> <field name="type">ir.actions.server</field>
<field name="state">code</field> <field name="state">code</field>
<field name="model_id" ref="database_cleanup.model_cleanup_purge_line_data" /> <field name="model_id" ref="database_cleanup.model_cleanup_purge_line_data" />
<field name="code">
env.get('cleanup.purge.line.data').purge()
</field>
<field name="code">records.purge()</field>
</record> </record>
<record id="action_purge_data_line_value" model="ir.values"> <record id="action_purge_data_line_value" model="ir.values">

4
database_cleanup/views/purge_menus.xml

@ -33,9 +33,7 @@
<field name="type">ir.actions.server</field> <field name="type">ir.actions.server</field>
<field name="state">code</field> <field name="state">code</field>
<field name="model_id" ref="database_cleanup.model_cleanup_purge_line_menu" /> <field name="model_id" ref="database_cleanup.model_cleanup_purge_line_menu" />
<field name="code">
env.get('cleanup.purge.line.menu').purge()
</field>
<field name="code">records.purge()</field>
</record> </record>
<record id="action_purge_menu_line_value" model="ir.values"> <record id="action_purge_menu_line_value" model="ir.values">

4
database_cleanup/views/purge_models.xml

@ -33,9 +33,7 @@
<field name="type">ir.actions.server</field> <field name="type">ir.actions.server</field>
<field name="state">code</field> <field name="state">code</field>
<field name="model_id" ref="database_cleanup.model_cleanup_purge_line_model" /> <field name="model_id" ref="database_cleanup.model_cleanup_purge_line_model" />
<field name="code">
env.get('cleanup.purge.line.model').purge()
</field>
<field name="code">records.purge()</field>
</record> </record>
<record id="action_purge_model_line_value" model="ir.values"> <record id="action_purge_model_line_value" model="ir.values">

4
database_cleanup/views/purge_modules.xml

@ -33,9 +33,7 @@
<field name="type">ir.actions.server</field> <field name="type">ir.actions.server</field>
<field name="state">code</field> <field name="state">code</field>
<field name="model_id" ref="database_cleanup.model_cleanup_purge_line_module" /> <field name="model_id" ref="database_cleanup.model_cleanup_purge_line_module" />
<field name="code">
env.get('cleanup.purge.line.module').purge()
</field>
<field name="code">records.purge()</field>
</record> </record>
<record id="action_purge_module_line_value" model="ir.values"> <record id="action_purge_module_line_value" model="ir.values">

2
database_cleanup/views/purge_properties.xml

@ -33,7 +33,7 @@
<field name="type">ir.actions.server</field> <field name="type">ir.actions.server</field>
<field name="state">code</field> <field name="state">code</field>
<field name="model_id" ref="database_cleanup.model_cleanup_purge_line_property" /> <field name="model_id" ref="database_cleanup.model_cleanup_purge_line_property" />
<field name="code">env.get('cleanup.purge.line.property').purge()</field>
<field name="code">records.purge()</field>
</record> </record>
<record id="action_purge_property_line_value" model="ir.values"> <record id="action_purge_property_line_value" model="ir.values">

4
database_cleanup/views/purge_tables.xml

@ -33,9 +33,7 @@
<field name="type">ir.actions.server</field> <field name="type">ir.actions.server</field>
<field name="state">code</field> <field name="state">code</field>
<field name="model_id" ref="database_cleanup.model_cleanup_purge_line_table" /> <field name="model_id" ref="database_cleanup.model_cleanup_purge_line_table" />
<field name="code">
env.get('cleanup.purge.line.table').purge()
</field>
<field name="code">records.purge()</field>
</record> </record>
<record id="action_purge_table_line_value" model="ir.values"> <record id="action_purge_table_line_value" model="ir.values">

Loading…
Cancel
Save