Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

ValueError: Expected singleton (odoo 14)

Subscriure's

Get notified when there's activity on this post

This question has been flagged
expectedvalueerrorsingletonv14
1 Respondre
15347 Vistes
Avatar
Fahimul Islam

Hello odoo experts, 

I just want to generate exam results according to the selected subjects. And my code is also ready for this. But when I execute this unfortunately the system response the error "ValueError: expected singleton: exam.subject(101, 102)".

I don't know what I'm missing here. Except your assist.

Thanks in Advance.


Here is my code:

# Method to Generate Result

def generate_result(self):
"""Method to generate result"""
result_obj = self.env["exam.result"]
student_obj = self.env["student.student"]
result_list = []
for rec in self:
for exam_schedule in rec.exam_schedule_ids:
string = [
("standard_id", "=", exam_schedule.standard_id.id),
("year", "=", rec.academic_year.id),
("state", "=", "done"),
("school_id", "=", exam_schedule.standard_id.school_id.id),
]
students_rec = student_obj.search(string)
for student in students_rec:
string = [
("standard_id", "=", student.standard_id.id),
("student_id", "=", student.id),
("s_exam_ids", "=", rec.id),
]
exam_result_rec = result_obj.search(string)
if exam_result_rec:
[result_list.append(res.id) for res in exam_result_rec]
else:
rs_dict = {
"s_exam_ids": rec.id,
"student_id": student.id,
"standard_id": student.standard_id.id,
"roll_no_id": student.roll_no,
"grade_system": rec.grade_system.id,
}
exam_line = []
timetable = exam_schedule.sudo().timetable_id
for line in timetable.sudo().timetable_ids:
min_mrks = line.subject_id.minimum_marks
max_mrks = line.subject_id.maximum_marks
sub_vals = {
"subject_id": line.subject_id.id,
"minimum_marks": min_mrks,
"maximum_marks": max_mrks,
}
exam_line.append((0, 0, sub_vals))
rs_dict.update({"result_ids": exam_line})
result_rec = result_obj.create(rs_dict)
result_list.append(result_rec.id)
return {
"name": _("Result Info"),
"view_mode": "tree,form",
"res_model": "exam.result",
"type": "ir.actions.act_window",
"string": [("id", "in", result_list)],
}

#Model 

class ExamResult(models.Model):

    """Defining Exam Result."""
    _name = "exam.result"
    _inherit = ["mail.thread", "resource.mixin"]
    _rec_name = "roll_no_id"
    _description = "exam result Information"
    
  standard_id = fields.Many2one(
    "school.standard", "Standard", help="Select Standard")
  result_ids = fields.One2many(
    "exam.subject", "exam_id", "Exam Subjects", help="Select exam subjects",
  )
  #.... other attributes

  @api.model
def create(self, vals):
"""Inherited the create method to assign the roll no and std"""
if vals.get("student_id"):

student_rec = self.env["student.student"].browse(
vals.get("student_id")
)
vals.update(
{
"roll_no_id": student_rec.roll_no,
"standard_id": student_rec.standard_id.id,
}
)
return super(ExamResult, self).create(vals)
  

0
Avatar
Descartar
Deerom Technologies Pvt.Ltd

Can u please add the full error log

Fahimul Islam
Autor

@Deerom Technologies Pvt.Ltd, Thanks for your response. This is the full error log-

Odoo Server Error

Traceback (most recent call last):

File "F:\odoo-14.0\odoo\odoo\addons\base\models\ir_http.py", line 237, in _dispatch

result = request.dispatch()

File "F:\odoo-14.0\odoo\odoo\http.py", line 682, in dispatch

result = self._call_function(**self.params)

File "F:\odoo-14.0\odoo\odoo\http.py", line 358, in _call_function

return checked_call(self.db, *args, **kwargs)

File "F:\odoo-14.0\odoo\odoo\service\model.py", line 94, in wrapper

return f(dbname, *args, **kwargs)

File "F:\odoo-14.0\odoo\odoo\http.py", line 346, in checked_call

result = self.endpoint(*a, **kw)

File "F:\odoo-14.0\odoo\odoo\http.py", line 911, in __call__

return self.method(*args, **kw)

File "F:\odoo-14.0\odoo\odoo\http.py", line 530, in response_wrap

response = f(*args, **kw)

File "f:\odoo-14.0\odoo\addons\web\controllers\main.py", line 1363, in call_button

action = self._call_kw(model, method, args, kwargs)

File "f:\odoo-14.0\odoo\addons\web\controllers\main.py", line 1351, in _call_kw

return call_kw(request.env[model], method, args, kwargs)

File "F:\odoo-14.0\odoo\odoo\api.py", line 396, in call_kw

result = _call_kw_multi(method, model, args, kwargs)

File "F:\odoo-14.0\odoo\odoo\api.py", line 383, in _call_kw_multi

result = method(recs, *args, **kwargs)

File "f:\odoo-14.0\odoo\custom-addons\odooeduerp-14.0\exam\models\exam.py", line 414, in generate_result

result_rec = result_obj.create(rs_dict)

File "<decorator-gen-202>", line 2, in create

File "F:\odoo-14.0\odoo\odoo\api.py", line 323, in _model_create_single

return create(self, arg)

File "f:\odoo-14.0\odoo\custom-addons\odooeduerp-14.0\exam\models\exam.py", line 686, in create

return super(ExamResult, self).create(vals)

File "<decorator-gen-130>", line 2, in create

File "F:\odoo-14.0\odoo\odoo\api.py", line 344, in _model_create_multi

return create(self, [arg])

File "f:\odoo-14.0\odoo\addons\mail\models\mail_thread.py", line 262, in create

threads = super(MailThread, self).create(vals_list)

File "<decorator-gen-117>", line 2, in create

File "F:\odoo-14.0\odoo\odoo\api.py", line 326, in _model_create_single

return self.browse().concat(*(create(self, vals) for vals in arg))

File "F:\odoo-14.0\odoo\odoo\api.py", line 326, in <genexpr>

return self.browse().concat(*(create(self, vals) for vals in arg))

File "f:\odoo-14.0\odoo\addons\resource\models\resource_mixin.py", line 46, in create

return super(ResourceMixin, self).create(values)

File "<decorator-gen-65>", line 2, in create

File "F:\odoo-14.0\odoo\odoo\api.py", line 344, in _model_create_multi

return create(self, [arg])

File "F:\odoo-14.0\odoo\odoo\addons\base\models\ir_fields.py", line 508, in create

recs = super().create(vals_list)

File "<decorator-gen-13>", line 2, in create

File "F:\odoo-14.0\odoo\odoo\api.py", line 345, in _model_create_multi

return create(self, arg)

File "F:\odoo-14.0\odoo\odoo\models.py", line 3827, in create

records = self._create(data_list)

File "F:\odoo-14.0\odoo\odoo\models.py", line 3987, in _create

for other, data in zip(others, data_list)

File "F:\odoo-14.0\odoo\odoo\fields.py", line 2970, in create

self.write_batch(record_values, True)

File "F:\odoo-14.0\odoo\odoo\fields.py", line 2996, in write_batch

return self.write_real(records_commands_list, create)

File "F:\odoo-14.0\odoo\odoo\fields.py", line 3168, in write_real

flush()

File "F:\odoo-14.0\odoo\odoo\fields.py", line 3132, in flush

comodel.create(to_create)

File "<decorator-gen-65>", line 2, in create

File "F:\odoo-14.0\odoo\odoo\api.py", line 345, in _model_create_multi

return create(self, arg)

File "F:\odoo-14.0\odoo\odoo\addons\base\models\ir_fields.py", line 508, in create

recs = super().create(vals_list)

File "<decorator-gen-13>", line 2, in create

File "F:\odoo-14.0\odoo\odoo\api.py", line 345, in _model_create_multi

return create(self, arg)

File "F:\odoo-14.0\odoo\odoo\models.py", line 3827, in create

records = self._create(data_list)

File "F:\odoo-14.0\odoo\odoo\models.py", line 4000, in _create

records._validate_fields(name for data in data_list for name in data['stored'])

File "F:\odoo-14.0\odoo\odoo\models.py", line 1249, in _validate_fields

check(self)

File "f:\odoo-14.0\odoo\custom-addons\odooeduerp-14.0\exam\models\exam.py", line 824, in _validate_marks

maximum_marks = self.maximum_marks if self.maximum_marks else self.subject_id.maximum_marks

File "F:\odoo-14.0\odoo\odoo\fields.py", line 926, in __get__

record.ensure_one()

File "F:\odoo-14.0\odoo\odoo\models.py", line 4950, in ensure_one

raise ValueError("Expected singleton: %s" % self)

Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):

File "F:\odoo-14.0\odoo\odoo\http.py", line 638, in _handle_exception

return super(JsonRequest, self)._handle_exception(exception)

File "F:\odoo-14.0\odoo\odoo\http.py", line 314, in _handle_exception

raise exception.with_traceback(None) from new_cause

ValueError: Expected singleton: exam.subject(117, 118)

Deerom Technologies Pvt.Ltd

can u please check the method that you defined under exam\models\exam.py", line 824, in _validate_mark

can u please check this mehtod "_validate_mark".Not sure but think the error is coming from this method.

Deerom Technologies Pvt.Ltd

In this method it Expected singleton but self contains multiple recordset.

Fahimul Islam
Autor

@Deerom Technologies Pvt.Ltd, Thanks again. But When I select a single subject it works perfectly. The error is occurred in case of multiple subject is selected.

Deerom Technologies Pvt.Ltd

Hi,

can u please add the method code here.

Fahimul Islam
Autor

@Deerom Technologies Pvt.Ltd, Thank you so much. You are saved my time. I wasted 2 days for this. Now the problem is solved just using a loop on the "_validate_marks" method.

Avatar
Deerom Technologies Pvt.Ltd
Best Answer

if self.test_field: #face ValueError Expected singleton because self contains multiple recordset.

Need to change with following:

for record in self:

    if record.test_field:

use decorators @api.multi with self.ensure_one() or use api.one and make changes accordingly

2
Avatar
Descartar
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrar-se
Related Posts Respostes Vistes Activitat
Error with singleton value
valueerror singleton
Avatar
Avatar
Avatar
Avatar
4
de març 24
2526
Singleton error Solved
singleton v14
Avatar
Avatar
Avatar
2
de set. 22
3112
ValueError: ValueError singleton Solved
valueerror singleton
Avatar
Avatar
Avatar
4
de febr. 19
4237
Odoo 14: editable tree "Add a line" shows ValueError: Invalid field 'same_vat_partner_id' on model 'tests.users'
inherit valueerror v14
Avatar
Avatar
Avatar
Avatar
3
de juny 22
6300
Odoo 11.0 ValueError: Expected singleton on create operation Solved
create valueerror singleton
Avatar
Avatar
Avatar
4
de des. 19
6105
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now