[IMP] fields: stricter rules on selection fields overridings

One cannot override the attribute `selection`, and list selections can only be
extended with `selection_add`.

Adapt the bad extensions to be consistent with the new warnings

closes odoo/odoo#35663

Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
This commit is contained in:
Raphael Collet
2019-08-21 14:36:19 +00:00
committed by Martin Trigaux
parent 4cd093a001
commit 1d2bccd0db
4 changed files with 14 additions and 13 deletions
+2 -2
View File
@@ -174,10 +174,10 @@ class Lead2OpportunityMassConvert(models.TransientModel):
user_ids = fields.Many2many('res.users', string='Salesmen')
team_id = fields.Many2one('crm.team', 'Sales Team', index=True)
deduplicate = fields.Boolean('Apply deduplication', default=True, help='Merge with existing leads/opportunities of each partner')
action = fields.Selection([
action = fields.Selection(selection_add=[
('each_exist_or_create', 'Use existing partner or create'),
('nothing', 'Do not link to a customer')
], 'Related Customer', required=True)
], string='Related Customer', required=True)
force_assignation = fields.Boolean('Force assignation', help='If unchecked, this will leave the salesman of duplicated opportunities')
@api.onchange('action')
@@ -14,12 +14,9 @@ class PaymentWizard(models.TransientModel):
def _get_default_payment_method(self):
return self.env.company.sale_onboarding_payment_method or 'digital_signature'
payment_method = fields.Selection([
payment_method = fields.Selection(selection_add=[
('digital_signature', 'Online signature'),
('paypal', "Pay with PayPal"),
('stripe', "Pay with credit card (via Stripe)"),
('other', "Pay with another payment acquirer"),
('manual', "Custom payment instructions"),
('paypal',),
], default=_get_default_payment_method)
#
@@ -24,10 +24,7 @@ class Opportunity2Quotation(models.TransientModel):
result['lead_id'] = active_id
return result
action = fields.Selection([
('create', 'Create a new customer'),
('exist', 'Use an existing customer')
], 'Quotation Customer', required=True)
action = fields.Selection(string='Quotation Customer')
lead_id = fields.Many2one('crm.lead', "Associated Lead", required=True)
def action_apply(self):
+9 -2
View File
@@ -2048,6 +2048,11 @@ class Selection(Field):
if 'selection' in field.args:
selection = field.args['selection']
if isinstance(selection, list):
if (
values is not None
and values != [kv[0] for kv in selection]
):
_logger.warning("%s: selection=%r overrides existing selection; use selection_add instead", self, selection)
values = [kv[0] for kv in selection]
labels.update(selection)
else:
@@ -2055,8 +2060,10 @@ class Selection(Field):
if 'selection_add' in field.args:
selection_add = field.args['selection_add']
assert isinstance(selection_add, list)
assert values is not None
assert isinstance(selection_add, list), \
"%s: selection_add=%r must be a list" % (self, selection_add)
assert values is not None, \
"%s: selection_add=%r on non-list selection %r" % (self, selection_add, self.selection)
values = merge_sequences(values, [kv[0] for kv in selection_add])
labels.update(kv for kv in selection_add if len(kv) == 2)