Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions openerp/addons/openupgrade_records/lib/compare.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2011 Therp BV (<http://therp.nl>).
# Copyright (C) 2011 Therp BV (<http://therp.nl>).
# (C) 2015 Opener B.V. (<https://opener.am>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -108,12 +108,26 @@ def report_generic(new, old, attrs, reprs):
text += ', default = %s' % new['req_default']
fieldprint(old, new, None, text, reprs)
elif attr == 'isfunction':
if old['isfunction'] != new['isfunction']:
if old[attr] != new[attr]:
if new['isfunction']:
text = "now a function"
else:
text = "not a function anymore"
fieldprint(old, new, None, text, reprs)
elif attr == 'isproperty':
if old[attr] != new[attr]:
if new[attr]:
text = "now a property"
else:
text = "not a property anymore"
fieldprint(old, new, None, text, reprs)
elif attr == 'isrelated':
if old[attr] != new[attr]:
if new[attr]:
text = "now related"
else:
text = "not related anymore"
fieldprint(old, new, None, text, reprs)
elif attr == 'oldname':
if new.get('oldname') == old['field']:
text = 'was renamed to %s [nothing to to]' % new['field']
Expand Down Expand Up @@ -202,7 +216,8 @@ def match(match_fields, report_fields, warn=False):
]
for column in old_records:
# we do not care about removed function fields
if column['isfunction'] or column['field'] in IGNORE_FIELDS:
if (column['isfunction'] or column['isrelated'] or

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good candidate for being refactored to a method that can be called from the multiple places where you are making this change.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I call on the rule of three here, and not do this now?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, no problem. I told it as I see the same replace in several places, but indeed there are only 2 appearances.

column['field'] in IGNORE_FIELDS):
continue
if column['mode'] == 'create':
column['mode'] = ''
Expand All @@ -213,7 +228,8 @@ def match(match_fields, report_fields, warn=False):

for column in new_records:
# we do not care about newly added function fields
if column['isfunction'] or column['field'] in IGNORE_FIELDS:
if (column['isfunction'] or column['isrelated'] or
column['field'] in IGNORE_FIELDS):
continue
if column['mode'] == 'create':
column['mode'] = ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ def field_dump(self, cr, uid, context=None):
'field',
'type',
'isfunction',
'isproperty',
'isrelated',
'relation',
'required',
'selection_keys',
Expand Down
46 changes: 35 additions & 11 deletions openerp/openupgrade/openupgrade_loading.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2014 Therp BV (<http://therp.nl>)
# Copyright (C) 2014 Therp BV (<http://therp.nl>)
# (C) 2015 Opener B.V. (<https://opener.am>)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
Expand All @@ -22,7 +22,8 @@
import types
import logging
from openerp import release
from openerp.osv.orm import TransientModel
from openerp.osv import orm
from openerp import models
from openerp.osv import fields
from openupgradelib.openupgrade_tools import table_exists
from openerp.tools import config, safe_eval
Expand Down Expand Up @@ -116,19 +117,42 @@ def log_model(model, local_registry):
if not model._name:
return

typemap = {'monetary': 'float'}

# persistent models only
if isinstance(model, TransientModel):
if isinstance(model, (orm.TransientModel, models.TransientModel)):
return

def isfunction(model, k):
if ((isinstance(model._columns[k], fields.function) and
not isinstance(model._columns[k],
(fields.property, fields.related))) or
(model._fields[k].compute and not model._fields[k].related)):
return 'function'
return ''

def isproperty(model, k):
if (isinstance(model._columns[k], fields.property) or
model._fields[k].company_dependent):
return 'property'
return ''

def isrelated(model, k):
if (isinstance(model._columns[k], fields.related) or
model._fields[k].related):
return 'related'
return ''

model_registry = local_registry.setdefault(
model._name, {})
if model._inherits:
model_registry['_inherits'] = {'_inherits': unicode(model._inherits)}
for k, v in model._columns.items():
properties = {
'type': v._type,
'isfunction': (
isinstance(v, fields.function) and 'function' or ''),
'type': typemap.get(v._type, v._type),
'isfunction': isfunction(model, k),
'isproperty': isproperty(model, k),
'isrelated': isrelated(model, k),
'relation':
v._type in ('many2many', 'many2one', 'one2many') and v._obj or '',
'required': v.required and 'required' or '',
Expand All @@ -144,14 +168,14 @@ def log_model(model, local_registry):
sorted([x[0] for x in v.selection]))
else:
properties['selection_keys'] = 'function'
if v.required and k in model._defaults:
if isinstance(model._defaults[k], types.FunctionType):
default = model._defaults.get(k, False) or model._fields[k].default
if v.required and default:
if isinstance(default, types.FunctionType):
# todo: in OpenERP 5 (and in 6 as well),
# literals are wrapped in a lambda function
properties['req_default'] = 'function'
else:
properties['req_default'] = unicode(
model._defaults[k])
properties['req_default'] = unicode(default)
for key, value in properties.items():
if value:
model_registry.setdefault(k, {})[key] = value
Expand Down