-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFR] OpenUpgrade framework patches #3
[RFR] OpenUpgrade framework patches #3
Conversation
e408226
to
151fbf4
Compare
151fbf4
to
447b0e7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def _drop_table(self): | ||
""" Never drop tables """ | ||
for model in self: | ||
if self.env.get(model.model) is not None: | ||
openupgrade.message( | ||
self.env.cr, "Unknown", False, False, | ||
"Not dropping the table or view of model %s", model.model) | ||
|
||
|
||
def _drop_column(self): | ||
""" Never drop columns """ | ||
for field in self: | ||
if field.name in models.MAGIC_COLUMNS: | ||
continue | ||
openupgrade.message( | ||
self.env.cr, "Unknown", False, False, | ||
"Not dropping the column of field %s of model %s", field.name, | ||
field.model, | ||
) | ||
continue | ||
|
||
|
||
IrModel._drop_column = _drop_column | ||
IrModel._drop_table = _drop_table | ||
|
||
|
||
@api.model | ||
def _process_end(self, modules): | ||
""" Don't warn about upgrade conventions from Odoo | ||
('fields should be explicitely removed by an upgrade script') | ||
""" | ||
with mute_logger('odoo.addons.base.models.ir_model'): | ||
return IrModelData._process_end._original_method(self, modules) | ||
|
||
|
||
_process_end._original_method = IrModelData._process_end | ||
IrModelData._process_end = _process_end | ||
|
||
|
||
def _module_data_uninstall(self): | ||
""" Don't delete many2many relation tables. Only unlink the | ||
ir.model.relation record itself. | ||
""" | ||
self.unlink() | ||
|
||
|
||
IrModelRelation._module_data_uninstall = _module_data_uninstall |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't you be using OdooPatch
?
_check_xml._original_method = View._check_xml | ||
View._check_xml = _check_xml | ||
handle_view_error._original_method = View.handle_view_error | ||
View.handle_view_error = handle_view_error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, shouldn't you use OdooPatch
?
savepoint = str(uuid4) | ||
try: | ||
self.env.cr.execute('SAVEPOINT "%s"' % savepoint) | ||
return BaseModel.unlink._original_method(self) | ||
except Exception as e: | ||
self.env.cr.execute('ROLLBACK TO SAVEPOINT "%s"' % savepoint) | ||
_logger.warning( | ||
"Could not delete obsolete record with ids %s of model %s: %s", | ||
self.ids, self._name, e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could just use with self.env.cr.savepoint(): ...
unlink._original_method = BaseModel.unlink | ||
BaseModel.unlink = unlink |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same point about OdooPatch
if ( | ||
"base" in self | ||
and self["base"].dbdemo | ||
and self["base"].installed_version < odoo.release.major_version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 Beware! You have to use a smart version comparison algorithm. Check out odoo.tools.parse_version
.
update_from_db._original_method = Graph.update_from_db | ||
Graph.update_from_db = update_from_db |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same about OdooPatch
I'm fast merging all the PR, because it make more complex the developpement to have multiple PR, even if @yajo could be valid. |
No description provided.