Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Artificial Intelligence
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Property Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

ValueError: Expected singleton (odoo 14)

Naroči se

Get notified when there's activity on this post

This question has been flagged
expectedvalueerrorsingletonv14
1 Odgovori
16750 Prikazi
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
Opusti
Deerom Technologies Pvt.Ltd

Can u please add the full error log

Fahimul Islam
Avtor

@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
Avtor

@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
Avtor

@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
Opusti
Enjoying the discussion? Don't just read, join in!

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

Prijavi
Related Posts Odgovori Prikazi Aktivnost
Error with singleton value
valueerror singleton
Avatar
Avatar
Avatar
Avatar
4
mar. 24
4290
Singleton error Solved
singleton v14
Avatar
Avatar
Avatar
2
sep. 22
4173
ValueError: ValueError singleton Solved
valueerror singleton
Avatar
Avatar
Avatar
4
feb. 19
5787
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
jun. 22
7225
Odoo 11.0 ValueError: Expected singleton on create operation Solved
create valueerror singleton
Avatar
Avatar
Avatar
4
dec. 19
7245
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة 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 Svenska ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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