Skip to Content
Menu
This question has been flagged
3491 Views
When I click on onchange if I have one record it comes perfectly,but 
when I add multiple records showing error like


y", line 4822, in ensure_one
ValueError: Expected singleton: destination.type(4, 3)


https://prnt.sc/gq9nvw
class BaseTrade(models.Model):

_name='base.trade'

name=fields.Char('Name')
test_many2many_ids=fields.Many2many('destination.type','source_dest_rel','source_id','dest_id')

value_test=fields.Char('ABC')

@api.onchange('test_many2many_ids')
def change_type(self):
for record in self:
record.value_test=self.test_many2many_ids.value.name



class DestinationType(models.Model):

_name='destination.type'

name=fields.Char('Type')
value=fields.Many2one('details.all','Details')


class DetailsAll(models.Model):

_name='details.all'

name=fields.Char('Test')
Avatar
Discard

Problem with the record.value_test=self.test_many2many_ids.value.name,

self.test_many2many has to be iterate over a loop,

for rec in self.test_many2many

print rec,

Do something like this

Author

Hi Niyas..I changed like this..but getting issue...

@api.onchange('test_many2many_ids')

def change_type(self):

for record in self:

# self.ensure_one()

for rec in record.test_many2many_ids:

rec.value_test=self.test_many2many_ids.value.name

many2many will give set of records so you will need to iterate them too in order to get the value

@api.onchange('test_many2many_ids')

def change_type(self):

for record in self:

for i in record.test_many2many_ids:

record.value_test=i.value

Author

Yeah..Absoultely..Thanks Onkar..

Author

Thanks Noyas..