NeoVe NeoVe - 16 days ago 6
Python Question

TypeError: can only concatenate tuple (not “list”) to tuple" - Odoo v9

I have this model:

class paymentTerm(models.Model):
_inherit = 'account.payment.term'

dte_sii_code = fields.Selection((
('1', '1: Contado'),
('2', '2: Credito'),
('3', '3: Otro')), 'DTE Sii Code', )


I want to add some fields to this selection, from another module, like this:

class paymentTerm(models.Model):
_inherit = 'account.payment.term'

dte_sii_code = fields.Selection(selection_add=[('1', 'COB1'),('2','COBRANZA'),('11','ACRED'),('12','CBOF'),('21','S/PAGO'),('32','ANTICIPO')])


But when I try to apply this to my module, Odoo server throws me this:

2016-11-25 02:04:06,338 13570 ERROR odoo_solti_ultima openerp.modules.registry: Failed to load registry
Traceback (most recent call last):
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/modules/registry.py", line 386, in new
openerp.modules.load_modules(registry._db, force_demo, status, update_module)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/modules/loading.py", line 340, in load_modules
registry.setup_models(cr)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/modules/registry.py", line 197, in setup_models
model._setup_base(cr, SUPERUSER_ID, partial)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/api.py", line 250, in wrapper
return old_api(self, *args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/api.py", line 354, in old_api
result = method(recs, *args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/models.py", line 3019, in _setup_base
self._add_field(name, field.new())
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/api.py", line 248, in wrapper
return new_api(self, *args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/models.py", line 471, in _add_field
field.setup_base(self, name)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/fields.py", line 406, in setup_base
self._setup_attrs(model, name)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/fields.py", line 1498, in _setup_attrs
self.selection = OrderedDict(self.selection + selection_add).items()
TypeError: can only concatenate tuple (not "list") to tuple


Any ideas about this?

I think it has to do with the original model, but I'm not so sure

I'm working on Odoo v9 community.

Answer

Selection datatype takes list of tuples. You have declared dte_sii_code with tuples. It should be list of tuples

Try with following code.

class paymentTerm(models.Model):
    _inherit = 'account.payment.term'

    dte_sii_code = fields.Selection([
        ('1', '1: Contado'),
        ('2', '2: Credito'),
        ('3', '3: Otro')], 'DTE Sii Code')

class paymentTerm(models.Model):
    _inherit = 'account.payment.term'

    dte_sii_code = fields.Selection(selection_add=[('4', 'COB1'),
        ('5','COBRANZA'),
        ('11','ACRED'),
        ('12','CBOF'),
        ('21','S/PAGO'),
        ('32','ANTICIPO')])

NOTE:

We should care about key. If you add tuple with same key then it will override with new definition.