Skip to content

Commit

Permalink
[FIX] *: set ondelete policy of required Selection fields
Browse files Browse the repository at this point in the history
With this commit, Selection fields with `required=True` which are
extended via `selection_add` are given proper ondelete policies to
ensure the cleanup of records containing these extended options during
uninstall of the extending module.

This commit also cleans up leftover uninstall hooks that were being used
to handle the same set of problems prior to the ondelete mechanism being
implemented for Selection fields.

closes #46325

Related: odoo/enterprise#9117
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
  • Loading branch information
Adrian Torres authored and rco-odoo committed Mar 30, 2020
1 parent f048139 commit 1daf8eb
Show file tree
Hide file tree
Showing 55 changed files with 160 additions and 108 deletions.
13 changes: 0 additions & 13 deletions addons/account_tax_python/__init__.py
Expand Up @@ -2,16 +2,3 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from . import models

from odoo import api, SUPERUSER_ID

import logging
_logger = logging.getLogger(__name__)

def uninstall_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})

code_taxes = env['account.tax'].search([('amount_type', '=', 'code')])
code_taxes.write({'amount_type': 'percent', 'active': False})

_logger.warning("The following taxes have been archived following 'account_tax_python' module uninstallation: %s" % code_taxes.ids)
1 change: 0 additions & 1 deletion addons/account_tax_python/__manifest__.py
Expand Up @@ -17,5 +17,4 @@
'data': [
'views/account_tax_views.xml',
],
'uninstall_hook': "uninstall_hook",
}
8 changes: 6 additions & 2 deletions addons/account_tax_python/models/account_tax.py
Expand Up @@ -8,7 +8,9 @@
class AccountTaxPython(models.Model):
_inherit = "account.tax"

amount_type = fields.Selection(selection_add=[('code', 'Python Code')])
amount_type = fields.Selection(selection_add=[
('code', 'Python Code')
], ondelete={'code': lambda recs: recs.write({'amount_type': 'percent', 'active': False})})

python_compute = fields.Text(string='Python Code', default="result = price_unit * 0.10",
help="Compute the amount of the tax by setting the variable 'result'.\n\n"
Expand Down Expand Up @@ -54,7 +56,9 @@ def compute_all(self, price_unit, currency=None, quantity=1.0, product=None, par
class AccountTaxTemplatePython(models.Model):
_inherit = 'account.tax.template'

amount_type = fields.Selection(selection_add=[('code', 'Python Code')])
amount_type = fields.Selection(selection_add=[
('code', 'Python Code')
], ondelete={'code': 'cascade'})

python_compute = fields.Text(string='Python Code', default="result = price_unit * 0.10",
help="Compute the amount of the tax by setting the variable 'result'.\n\n"
Expand Down
4 changes: 3 additions & 1 deletion addons/base_automation/models/ir_actions.py
Expand Up @@ -7,4 +7,6 @@
class ServerAction(models.Model):
_inherit = "ir.actions.server"

usage = fields.Selection(selection_add=[('base_automation', 'Automated Action')])
usage = fields.Selection(selection_add=[
('base_automation', 'Automated Action')
], ondelete={'base_automation': 'cascade'})
4 changes: 3 additions & 1 deletion addons/base_sparse_field/models/models.py
Expand Up @@ -7,7 +7,9 @@
class IrModelFields(models.Model):
_inherit = 'ir.model.fields'

ttype = fields.Selection(selection_add=[('serialized', 'serialized')])
ttype = fields.Selection(selection_add=[
('serialized', 'serialized'),
], ondelete={'serialized': 'cascade'})
serialization_field_id = fields.Many2one('ir.model.fields', string='Serialization Field',
ondelete='cascade', domain="[('ttype','=','serialized'), ('model_id', '=', model_id)]",
help="If set, this field will be stored in the sparse structure of the "
Expand Down
4 changes: 3 additions & 1 deletion addons/calendar_sms/models/calendar.py
Expand Up @@ -31,7 +31,9 @@ def _do_sms_reminder(self):
class CalendarAlarm(models.Model):
_inherit = 'calendar.alarm'

alarm_type = fields.Selection(selection_add=[('sms', 'SMS Text Message')])
alarm_type = fields.Selection(selection_add=[
('sms', 'SMS Text Message')
], ondelete={'sms': 'set default'})


class AlarmManager(models.AbstractModel):
Expand Down
4 changes: 3 additions & 1 deletion addons/crm/wizard/crm_lead_to_opportunity_mass.py
Expand Up @@ -24,7 +24,9 @@ def default_get(self, fields):
deduplicate = fields.Boolean('Apply deduplication', default=True, help='Merge with existing leads/opportunities of each partner')
action = fields.Selection(selection_add=[
('each_exist_or_create', 'Use existing partner or create'),
], string='Related Customer')
], string='Related Customer', ondelete={
'each_exist_or_create': lambda recs: recs.write({'action': 'exist'}),
})
force_assignment = fields.Boolean(default=False)

@api.depends('duplicated_lead_ids')
Expand Down
6 changes: 5 additions & 1 deletion addons/delivery/models/delivery_grid.py
Expand Up @@ -38,7 +38,11 @@ def _compute_name(self):
class ProviderGrid(models.Model):
_inherit = 'delivery.carrier'

delivery_type = fields.Selection(selection_add=[('base_on_rule', 'Based on Rules')])
delivery_type = fields.Selection(selection_add=[
('base_on_rule', 'Based on Rules'),
], ondelete={'base_on_rule': lambda recs: recs.write({
'delivery_type': 'fixed', 'fixed_price': 0,
})})
price_rule_ids = fields.One2many('delivery.price.rule', 'carrier_id', 'Pricing Rules', copy=True)

def base_on_rule_rate_shipment(self, order):
Expand Down
8 changes: 6 additions & 2 deletions addons/event_sms/models/event_mail.py
Expand Up @@ -7,7 +7,9 @@
class EventTypeMail(models.Model):
_inherit = 'event.type.mail'

notification_type = fields.Selection(selection_add=[('sms', 'SMS')])
notification_type = fields.Selection(selection_add=[
('sms', 'SMS')
], ondelete={'sms': 'set default'})
sms_template_id = fields.Many2one(
'sms.template', string='SMS Template',
domain=[('model', '=', 'event.registration')], ondelete='restrict',
Expand All @@ -21,7 +23,9 @@ def _get_event_mail_fields_whitelist(self):
class EventMailScheduler(models.Model):
_inherit = 'event.mail'

notification_type = fields.Selection(selection_add=[('sms', 'SMS')])
notification_type = fields.Selection(selection_add=[
('sms', 'SMS')
], ondelete={'sms': 'set default'})
sms_template_id = fields.Many2one(
'sms.template', string='SMS Template',
domain=[('model', '=', 'event.registration')], ondelete='restrict',
Expand Down
4 changes: 3 additions & 1 deletion addons/hr/models/mail_alias.py
Expand Up @@ -7,7 +7,9 @@
class Alias(models.Model):
_inherit = 'mail.alias'

alias_contact = fields.Selection(selection_add=[('employees', 'Authenticated Employees')])
alias_contact = fields.Selection(selection_add=[
('employees', 'Authenticated Employees'),
], ondelete={'employees': 'cascade'})

def _get_alias_bounced_body_fallback(self, message_dict):
if self.alias_contact == 'employees':
Expand Down
7 changes: 3 additions & 4 deletions addons/im_livechat_mail_bot/models/res_users.py
Expand Up @@ -6,7 +6,6 @@

class Users(models.Model):
_inherit = 'res.users'
odoobot_state = fields.Selection(
selection_add=[
('onboarding_canned', 'Onboarding canned'),
])
odoobot_state = fields.Selection(selection_add=[
('onboarding_canned', 'Onboarding canned'),
], ondelete={'onboarding_canned': 'set default'})
4 changes: 3 additions & 1 deletion addons/l10n_be_invoice_bba/models/account_journal.py
Expand Up @@ -6,4 +6,6 @@
class AccountJournal(models.Model):
_inherit = 'account.journal'

invoice_reference_model = fields.Selection(selection_add=[('be', 'Belgium')])
invoice_reference_model = fields.Selection(selection_add=[
('be', 'Belgium')
], ondelete={'be': lambda recs: recs.write({'invoice_reference_model': 'odoo'})})
4 changes: 3 additions & 1 deletion addons/l10n_ch/models/account_journal.py
Expand Up @@ -14,7 +14,9 @@ class AccountJournal(models.Model):

# creation of bank journals by giving the account number, allow craetion of the
l10n_ch_postal = fields.Char('Client Number', related='bank_account_id.l10n_ch_postal', readonly=False)
invoice_reference_model = fields.Selection(selection_add=[('ch', 'Switzerland')])
invoice_reference_model = fields.Selection(selection_add=[
('ch', 'Switzerland')
], ondelete={'ch': lambda recs: recs.write({'invoice_reference_model': 'odoo'})})

@api.model
def create(self, vals):
Expand Down
4 changes: 3 additions & 1 deletion addons/l10n_no/models/account_journal.py
Expand Up @@ -7,4 +7,6 @@
class AccountJournal(models.Model):
_inherit = 'account.journal'

invoice_reference_model = fields.Selection(selection_add=[('no', 'Norway')])
invoice_reference_model = fields.Selection(selection_add=[
('no', 'Norway')
], ondelete={'no': lambda recs: recs.write({'invoice_reference_model': 'odoo'})})
4 changes: 3 additions & 1 deletion addons/mail/models/ir_action_act_window.py
Expand Up @@ -5,4 +5,6 @@
class ActWindowView(models.Model):
_inherit = 'ir.actions.act_window.view'

view_mode = fields.Selection(selection_add=[('activity', 'Activity')])
view_mode = fields.Selection(selection_add=[
('activity', 'Activity')
], ondelete={'activity': 'cascade'})
2 changes: 1 addition & 1 deletion addons/mail/models/ir_actions.py
Expand Up @@ -17,7 +17,7 @@ class ServerActions(models.Model):
('email', 'Send Email'),
('followers', 'Add Followers'),
('next_activity', 'Create Next Activity'),
])
], ondelete={'email': 'cascade', 'followers': 'cascade', 'next_activity': 'cascade'})
# Followers
partner_ids = fields.Many2many('res.partner', string='Add Followers')
channel_ids = fields.Many2many('mail.channel', string='Add Channels')
Expand Down
4 changes: 3 additions & 1 deletion addons/mass_mailing_sms/models/mailing_mailing.py
Expand Up @@ -21,7 +21,9 @@ def default_get(self, fields):
return res

# mailing options
mailing_type = fields.Selection(selection_add=[('sms', 'SMS')])
mailing_type = fields.Selection(selection_add=[
('sms', 'SMS')
], ondelete={'sms': 'set default'})
# sms options
body_plaintext = fields.Text('SMS Body', compute='_compute_body_plaintext', store=True, readonly=False)
sms_template_id = fields.Many2one('sms.template', string='SMS Template', ondelete='set null')
Expand Down
4 changes: 3 additions & 1 deletion addons/mass_mailing_sms/models/mailing_trace.py
Expand Up @@ -14,7 +14,9 @@ class MailingTrace(models.Model):
_inherit = 'mailing.trace'
CODE_SIZE = 3

trace_type = fields.Selection(selection_add=[('sms', 'SMS')])
trace_type = fields.Selection(selection_add=[
('sms', 'SMS')
], ondelete={'sms': 'set default'})
sms_sms_id = fields.Many2one('sms.sms', string='SMS', index=True, ondelete='set null')
sms_sms_id_int = fields.Integer(
string='SMS ID (tech)',
Expand Down
4 changes: 3 additions & 1 deletion addons/mrp/models/stock_picking.py
Expand Up @@ -7,7 +7,9 @@
class StockPickingType(models.Model):
_inherit = 'stock.picking.type'

code = fields.Selection(selection_add=[('mrp_operation', 'Manufacturing')])
code = fields.Selection(selection_add=[
('mrp_operation', 'Manufacturing')
], ondelete={'mrp_operation': 'cascade'})
count_mo_todo = fields.Integer(string="Number of Manufacturing Orders to Process",
compute='_get_mo_count')
count_mo_waiting = fields.Integer(string="Number of Manufacturing Orders Waiting",
Expand Down
4 changes: 3 additions & 1 deletion addons/mrp/models/stock_rule.py
Expand Up @@ -11,7 +11,9 @@

class StockRule(models.Model):
_inherit = 'stock.rule'
action = fields.Selection(selection_add=[('manufacture', 'Manufacture')])
action = fields.Selection(selection_add=[
('manufacture', 'Manufacture')
], ondelete={'manufacture': 'cascade'})

def _get_message_dict(self):
message_dict = super(StockRule, self)._get_message_dict()
Expand Down
4 changes: 3 additions & 1 deletion addons/mrp_landed_costs/models/stock_landed_cost.py
Expand Up @@ -7,7 +7,9 @@
class StockLandedCost(models.Model):
_inherit = 'stock.landed.cost'

target_model = fields.Selection(selection_add=[('manufacturing', "Manufacturing Orders")])
target_model = fields.Selection(selection_add=[
('manufacturing', "Manufacturing Orders")
], ondelete={'manufacturing': 'set default'})
mrp_production_ids = fields.Many2many(
'mrp.production', string='Manufacturing order',
copy=False, states={'done': [('readonly', True)]}, groups='mrp.group_mrp_user')
Expand Down
4 changes: 3 additions & 1 deletion addons/mrp_subcontracting/models/mrp_bom.py
Expand Up @@ -7,7 +7,9 @@
class MrpBom(models.Model):
_inherit = 'mrp.bom'

type = fields.Selection(selection_add=[('subcontract', 'Subcontracting')])
type = fields.Selection(selection_add=[
('subcontract', 'Subcontracting')
], ondelete={'subcontract': lambda recs: recs.write({'type': 'normal', 'active': False})})
subcontractor_ids = fields.Many2many('res.partner', 'mrp_bom_subcontractor', string='Subcontractors', check_company=True)

def _bom_subcontract_find(self, product_tmpl=None, product=None, picking_type=None, company_id=False, bom_type='subcontract', subcontractor=False):
Expand Down
4 changes: 3 additions & 1 deletion addons/payment_adyen/models/payment.py
Expand Up @@ -47,7 +47,9 @@
class AcquirerAdyen(models.Model):
_inherit = 'payment.acquirer'

provider = fields.Selection(selection_add=[('adyen', 'Adyen')])
provider = fields.Selection(selection_add=[
('adyen', 'Adyen')
], ondelete={'adyen': 'set default'})
adyen_merchant_account = fields.Char('Merchant Account', required_if_provider='adyen', groups='base.group_user')
adyen_skin_code = fields.Char('Skin Code', required_if_provider='adyen', groups='base.group_user')
adyen_skin_hmac_key = fields.Char('Skin HMAC Key', required_if_provider='adyen', groups='base.group_user')
Expand Down
4 changes: 3 additions & 1 deletion addons/payment_alipay/models/payment.py
Expand Up @@ -17,7 +17,9 @@
class PaymentAcquirer(models.Model):
_inherit = 'payment.acquirer'

provider = fields.Selection(selection_add=[('alipay', 'Alipay')])
provider = fields.Selection(selection_add=[
('alipay', 'Alipay')
], ondelete={'alipay': 'set default'})
alipay_payment_method = fields.Selection([
('express_checkout', 'Express Checkout (only for Chinese Merchant)'),
('standard_checkout', 'Cross-border'),
Expand Down
4 changes: 3 additions & 1 deletion addons/payment_authorize/models/payment.py
Expand Up @@ -19,7 +19,9 @@
class PaymentAcquirerAuthorize(models.Model):
_inherit = 'payment.acquirer'

provider = fields.Selection(selection_add=[('authorize', 'Authorize.Net')])
provider = fields.Selection(selection_add=[
('authorize', 'Authorize.Net')
], ondelete={'authorize': 'set default'})
authorize_login = fields.Char(string='API Login Id', required_if_provider='authorize', groups='base.group_user')
authorize_transaction_key = fields.Char(string='API Transaction Key', required_if_provider='authorize', groups='base.group_user')
authorize_signature_key = fields.Char(string='API Signature Key', required_if_provider='authorize', groups='base.group_user')
Expand Down
4 changes: 3 additions & 1 deletion addons/payment_buckaroo/models/payment.py
Expand Up @@ -26,7 +26,9 @@ def normalize_keys_upper(data):
class AcquirerBuckaroo(models.Model):
_inherit = 'payment.acquirer'

provider = fields.Selection(selection_add=[('buckaroo', 'Buckaroo')])
provider = fields.Selection(selection_add=[
('buckaroo', 'Buckaroo')
], ondelete={'buckaroo': 'set default'})
brq_websitekey = fields.Char('WebsiteKey', required_if_provider='buckaroo', groups='base.group_user')
brq_secretkey = fields.Char('SecretKey', required_if_provider='buckaroo', groups='base.group_user')

Expand Down
4 changes: 3 additions & 1 deletion addons/payment_ingenico/models/payment.py
Expand Up @@ -25,7 +25,9 @@
class PaymentAcquirerOgone(models.Model):
_inherit = 'payment.acquirer'

provider = fields.Selection(selection_add=[('ogone', 'Ingenico')])
provider = fields.Selection(selection_add=[
('ogone', 'Ingenico')
], ondelete={'ogone': 'set default'})
ogone_pspid = fields.Char('PSPID', required_if_provider='ogone', groups='base.group_user')
ogone_userid = fields.Char('API User ID', required_if_provider='ogone', groups='base.group_user')
ogone_password = fields.Char('API User Password', required_if_provider='ogone', groups='base.group_user')
Expand Down
4 changes: 3 additions & 1 deletion addons/payment_paypal/models/payment.py
Expand Up @@ -19,7 +19,9 @@
class AcquirerPaypal(models.Model):
_inherit = 'payment.acquirer'

provider = fields.Selection(selection_add=[('paypal', 'Paypal')])
provider = fields.Selection(selection_add=[
('paypal', 'Paypal')
], ondelete={'paypal': 'set default'})
paypal_email_account = fields.Char('Email', required_if_provider='paypal', groups='base.group_user')
paypal_seller_account = fields.Char(
'Merchant Account ID', groups='base.group_user',
Expand Down
4 changes: 3 additions & 1 deletion addons/payment_payulatam/models/payment.py
Expand Up @@ -18,7 +18,9 @@
class PaymentAcquirerPayulatam(models.Model):
_inherit = 'payment.acquirer'

provider = fields.Selection(selection_add=[('payulatam', 'PayU Latam')])
provider = fields.Selection(selection_add=[
('payulatam', 'PayU Latam')
], ondelete={'payulatam': 'set default'})
payulatam_merchant_id = fields.Char(string="PayU Latam Merchant ID", required_if_provider='payulatam', groups='base.group_user')
payulatam_account_id = fields.Char(string="PayU Latam Account ID", required_if_provider='payulatam', groups='base.group_user')
payulatam_api_key = fields.Char(string="PayU Latam API Key", required_if_provider='payulatam', groups='base.group_user')
Expand Down
4 changes: 3 additions & 1 deletion addons/payment_payumoney/models/payment.py
Expand Up @@ -17,7 +17,9 @@
class PaymentAcquirerPayumoney(models.Model):
_inherit = 'payment.acquirer'

provider = fields.Selection(selection_add=[('payumoney', 'PayUmoney')])
provider = fields.Selection(selection_add=[
('payumoney', 'PayUmoney')
], ondelete={'payumoney': 'set default'})
payumoney_merchant_key = fields.Char(string='Merchant Key', required_if_provider='payumoney', groups='base.group_user')
payumoney_merchant_salt = fields.Char(string='Merchant Salt', required_if_provider='payumoney', groups='base.group_user')

Expand Down
4 changes: 3 additions & 1 deletion addons/payment_sips/models/payment.py
Expand Up @@ -43,7 +43,9 @@
class AcquirerSips(models.Model):
_inherit = 'payment.acquirer'

provider = fields.Selection(selection_add=[('sips', 'Sips')])
provider = fields.Selection(selection_add=[
('sips', 'Sips')
], ondelete={'sips': 'set default'})
sips_merchant_id = fields.Char('Merchant ID', help="Used for production only", required_if_provider='sips', groups='base.group_user')
sips_secret = fields.Char('Secret Key', size=64, required_if_provider='sips', groups='base.group_user')
sips_test_url = fields.Char("Test url", required_if_provider='sips', default='https://payment-webinit.simu.sips-atos.com/paymentInit')
Expand Down
4 changes: 3 additions & 1 deletion addons/payment_stripe/models/payment.py
Expand Up @@ -24,7 +24,9 @@
class PaymentAcquirerStripe(models.Model):
_inherit = 'payment.acquirer'

provider = fields.Selection(selection_add=[('stripe', 'Stripe')])
provider = fields.Selection(selection_add=[
('stripe', 'Stripe')
], ondelete={'stripe': 'set default'})
stripe_secret_key = fields.Char(required_if_provider='stripe', groups='base.group_user')
stripe_publishable_key = fields.Char(required_if_provider='stripe', groups='base.group_user')
stripe_image_url = fields.Char(
Expand Down
4 changes: 3 additions & 1 deletion addons/payment_test/models/payment_acquirer.py
Expand Up @@ -10,7 +10,9 @@
class PaymentAcquirerTest(models.Model):
_inherit = 'payment.acquirer'

provider = fields.Selection(selection_add=[('test', 'Test')])
provider = fields.Selection(selection_add=[
('test', 'Test')
], ondelete={'test': 'set default'})

@api.model
def create(self, values):
Expand Down
4 changes: 3 additions & 1 deletion addons/payment_transfer/models/payment.py
Expand Up @@ -13,7 +13,9 @@
class TransferPaymentAcquirer(models.Model):
_inherit = 'payment.acquirer'

provider = fields.Selection(selection_add=[('transfer', 'Manual Payment')], default='transfer')
provider = fields.Selection(selection_add=[
('transfer', 'Manual Payment')
], default='transfer', ondelete={'transfer': 'set default'})

@api.model
def _create_missing_journal_for_acquirers(self, company=None):
Expand Down

0 comments on commit 1daf8eb

Please sign in to comment.