[FIX] *: cleanup (un|re)installation hacks

Replace hacks introduced in V11 by the proper solution.
This commit is contained in:
Adrian Torres
2018-06-11 09:47:34 +02:00
committed by GitHub
parent c0aacce182
commit 503b8ed692
14 changed files with 3 additions and 192 deletions
-1
View File
@@ -4,4 +4,3 @@ from . import res_config_settings
from . import ir_http
from . import res_partner
from . import res_users
from . import ir_model_fields
@@ -1,19 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details
from odoo import models
# This is a nasty hack, targeted for V11 only
class IrModelFields(models.Model):
_inherit = 'ir.model.fields'
def unlink(self):
# Prevent the deletion of some `shared` fields... -_-
self = self.filtered(
lambda rec: not (
rec.model == 'res.config.settings'
and rec.name == 'auth_signup_uninvited'
)
)
return super(IrModelFields, self).unlink()
-1
View File
@@ -8,5 +8,4 @@ from . import mail_thread
from . import res_config_settings
from . import mass_mailing_report
from . import link_tracker
from . import ir_model_fields
from . import res_users
@@ -1,30 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details
from odoo import api, models
# This is a nasty hack, targeted for V11 only
class IrModelFields(models.Model):
_inherit = 'ir.model.fields'
@api.multi
def unlink(self):
# Prevent the deletion of social_* fields defined in res.company if
# the other module is installed
social = (
'social_facebook',
'social_github',
'social_googleplus',
'social_linkedin',
'social_twitter',
'social_youtube',
)
self = self.filtered(
lambda rec: not (
rec.model == 'res.company' and
rec.name in social
)
)
return super(IrModelFields, self).unlink()
+1 -2
View File
@@ -12,5 +12,4 @@ from . import sale
from . import res_config_settings
from . import sale_layout
from . import sales_team
from . import ir_model_fields
from . import res_users
from . import res_users
-19
View File
@@ -1,19 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details
from odoo import models
# This is a nasty hack, targeted for V11 only
class IrModelFields(models.Model):
_inherit = 'ir.model.fields'
def unlink(self):
# Prevent the deletion of some `shared` fields... -_-
self = self.filtered(
lambda rec: not (
rec.model == 'res.config.settings'
and rec.name == 'auth_signup_uninvited'
)
)
return super(IrModelFields, self).unlink()
-2
View File
@@ -10,6 +10,4 @@ from . import ir_ui_view
from . import res_company
from . import res_partner
from . import res_config_settings
from . import ir_model_fields
from . import ir_model
from . import res_users
-15
View File
@@ -1,15 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details
from odoo import api, models
# This is a nasty hack, targeted for V11 only
class IrModel(models.Model):
_inherit = 'ir.model'
@api.multi
def unlink(self):
self.env.cr.execute(
"DELETE FROM ir_model_fields WHERE name='website_id'")
return super(IrModel, self).unlink()
-29
View File
@@ -1,29 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details
from odoo import models
# This is a nasty hack, targeted for V11 only
class IrModelFields(models.Model):
_inherit = 'ir.model.fields'
def unlink(self):
# Prevent the deletion of some `shared` fields... -_-
social = (
'social_facebook',
'social_github',
'social_googleplus',
'social_linkedin',
'social_twitter',
'social_youtube',
)
self = self.filtered(
lambda rec: not (
(rec.model == 'res.company' and rec.name in social)
or (rec.model == 'res.config.settings'
and rec.name == 'auth_signup_uninvited')
)
)
return super(IrModelFields, self).unlink()
+2 -2
View File
@@ -13,8 +13,8 @@ class ResConfigSettings(models.TransientModel):
def _default_website(self):
return self.env['website'].search([], limit=1)
# FIXME: Set website_id to ondelete='cascade' in master
website_id = fields.Many2one('website', string="website", default=_default_website, required=True)
website_id = fields.Many2one('website', string="website",
default=_default_website, required=True, ondelete='cascade')
website_name = fields.Char('Website Name', related='website_id.name')
language_ids = fields.Many2many(related='website_id.language_ids', relation='res.lang')
language_count = fields.Integer(string='Number of languages', compute='_compute_language_count', readonly=True)
-1
View File
@@ -4,5 +4,4 @@
from .import sale_order
from .import sale_quote
from .import product_template
from . import ir_model_fields
from .import res_config_settings
@@ -1,35 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, models
# !! Attention, this is a hack of a hack, do not try this at home !!
# This is done because website_quote defines the website_description
# field which is also defined by website_sale, but these two modules
# are independent of each other, the part of the ORM that generates
# xmlids does not support this case therefore it only creates a single
# pair of xmlids for whichever module is installed first, therefore
# when uninstalling any of the two modules the website_descripion field
# will be deleted from the db and the other module won't be able to
# use this field, resulting in a crash and data-loss.
# See opw-776464 for more details.
#
# This is hotfixed by overriding the unlink method so as to not delete
# the website_description field if website_quote is uninstalled, it's
# an ugly hack but it works and big changes can't be done to the ORM
# in stable versions, Odoo v12+ will properly fix this
class IrModelFields(models.Model):
_inherit = "ir.model.fields"
@api.multi
def unlink(self):
# Prevent the deletion of the field "website_description"
self = self.filtered(
lambda rec: not (
rec.model in ('product.product', 'product.template') and
rec.name == 'website_description'
)
)
return super(IrModelFields, self).unlink()
-1
View File
@@ -9,6 +9,5 @@ from . import res_country
from . import res_partner
from . import payment
from . import sale_order
from . import ir_model_fields
from . import website
from . import res_config_settings
@@ -1,35 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, models
# !! Attention, this is a hack of a hack, do not try this at home !!
# This is done because website_sale defines the website_description
# field which is also defined by website_quote, but these two modules
# are independent of each other, the part of the ORM that generates
# xmlids does not support this case therefore it only creates a single
# pair of xmlids for whichever module is installed first, therefore
# when uninstalling any of the two modules the website_descripion field
# will be deleted from the db and the other module won't be able to
# use this field, resulting in a crash and data-loss.
# See opw-776464 for more details.
#
# This is hotfixed by overriding the unlink method so as to not delete
# the website_description field if website_sale is uninstalled, it's
# an ugly hack but it works and big changes can't be done to the ORM
# in stable versions, Odoo v12+ will properly fix this
class IrModelFields(models.Model):
_inherit = "ir.model.fields"
@api.multi
def unlink(self):
# Prevent the deletion of the field "website_description"
self = self.filtered(
lambda rec: not (
rec.model in ('product.product', 'product.template') and
rec.name == 'website_description'
)
)
return super(IrModelFields, self).unlink()