Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Priemyselné odvetvia
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Reštaurácia
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Reality
    • Real Estate Agency
    • Architecture Firm
    • Konštrukcia
    • Estate Managament
    • Gardening
    • Property Owner Association
    Poradenstvo
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Jedlo
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Iní
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

ValueError: Expected singleton (odoo 14)

Odoberať

Get notified when there's activity on this post

This question has been flagged
expectedvalueerrorsingletonv14
1 Odpoveď
15539 Zobrazenia
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
Zrušiť
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
Zrušiť
Enjoying the discussion? Don't just read, join in!

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

Registrácia
Related Posts Replies Zobrazenia Aktivita
Error with singleton value
valueerror singleton
Avatar
Avatar
Avatar
Avatar
4
mar 24
2757
Singleton error Solved
singleton v14
Avatar
Avatar
Avatar
2
sep 22
3249
ValueError: ValueError singleton Solved
valueerror singleton
Avatar
Avatar
Avatar
4
feb 19
4433
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
jún 22
6464
Odoo 11.0 ValueError: Expected singleton on create operation Solved
create valueerror singleton
Avatar
Avatar
Avatar
4
dec 19
6262
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة 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 je sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

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