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

Expected singleton: hr.emp.travel.location(62, 63)

Subscriure's

Get notified when there's activity on this post

This question has been flagged
odoo12.0
2 Respostes
1939 Vistes
Avatar
jenan soliman

Hi,


class EmployeeTravelReqest(models.Model):
_name = 'hr.emp.travel.request'
_description = "Travel Request"
_inherit = ['mail.thread', 'mail.activity.mixin']

@api.multi
def hr_manager_user_ids_get(self):
self.ensure_one()
hr_group_ids = self.env.ref('hr.group_hr_manager').users.ids
self.hr_manager_user_ids = [(6, 0, hr_group_ids)]

user_id = fields.Many2one('res.users')
hr_manager_user_ids = fields.Many2many('res.users', compute="hr_manager_user_ids_get")

name = fields.Char(string="Name")
employee_id = fields.Many2one('hr.employee', string="Employee")
# related fields
department_id = fields.Many2one(related="employee_id.department_id", store=True)
company_id = fields.Many2one(related="employee_id.company_id", store=True)
parent_id = fields.Many2one(related="employee_id.parent_id", store=True)
job_id = fields.Many2one(related="employee_id.job_id", store=True)
grade_id = fields.Many2one(related="employee_id.grade_id", store=True)
currency_id = fields.Many2one(related="employee_id.company_id.currency_id", store=True)
# Travel Dates
from_date = fields.Date(string='From Date')
to_date = fields.Date(string='To Date')
expect_travel_days = fields.Integer(string="Days", compute="compute_days")
state = fields.Selection(
[('draft', 'Draft'), ('waiting', 'Waiting for confirmation'), ('confirmed', 'Confirmed'), ('approved', 'Approved'),
('closed', 'Closed'), ('rejected', 'Rejected'), ('canceled', 'Canceled')], default="draft", track_visibility="onchange")
# travel locations
travel_location_ids = fields.One2many('hr.emp.travel.location', 'travel_request_id_ref', required=True)
total_travel_days = fields.Integer(string="Days", compute="compute_days_travel_location")
# Expenses(proposed/actual)
expense_amount_ids = fields.One2many('hr.expense.amount', 'travel_request_id')
total_expense_amount = fields.Monetary(string="Grand Total", compute="compute_total_expense_amount", store=False)
ticket_book = fields.Boolean(string="Company Books ticket for You", track_visibility="onchange")
# Log
request_by = fields.Many2one('res.users', default=lambda self: self.env.uid)
approved_by = fields.Many2one('res.users')
rejected_by = fields.Many2one('res.users')
request_date = fields.Date(string="Requested Date", default=date.today())
approved_date = fields.Date()
rejected_date = fields.Date()
reject_reason = fields.Char("Reason For Reject")
# Reason
reason = fields.Text(string="Reason")
# Currency
currency_ids = fields.One2many('hr.travel.currency', 'travel_request_id')

# Expenses expenses_ids = fields.One2many('hr.expense', 'travel_request_id_ref'
@api.multi
def action_send_manager(self):
for rec in self:
if not rec.travel_location_ids:
raise Warning("Please enter the travel information before submit to manager")
else:
rec.state = 'waiting'

I get this error when I try to save more than one line in one2many field.


Thank you in advance for any help.



0
Avatar
Descartar
Mehjabin Farsana

Instead of sharing whole code, please check log and see which section throws the error, and please share it.
To understand single ton error in odoo and to learn its solution see: https://www.youtube.com/watch?v=Rv44nFVn_5U

Murugan Chinnasamy

you can check with one2many class(hr.emp.travel.location) like function, search, domain etc.

Avatar
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

Hi,

Singleton error occurs because somewhere in your code, a method that expects one record (self.ensure_one() is called) is being passed multiple records. In your case, it is happening with the One2many travel_location_ids when you try to save multiple lines.To fix this, avoid using ensure_one() in compute methods or methods that can be called on multiple records, and always loop over self when accessing fields like One2many or Many2many. For example, in the compute_days_travel_location method, you should iterate over each record in self and calculate the total travel days individually. Similarly, in the hr_manager_user_ids_get compute method, remove ensure_one() and loop over self to assign the HR manager users for each record. Also, make sure any button or action methods that work on multiple records, such as action_send_manager, use a loop to handle each record properly. Finally, review all methods that access One2many or Many2many fields to ensure they handle multiple records without assuming a single record. Following these steps will prevent singleton errors when saving multiple lines in the travel_location_ids field.


Hope it helps.

0
Avatar
Descartar
Avatar
stomtkamesromt
Best Answer

The error usually happens when a method is written with ensure_one() but is called on multiple records at once, which leads to the singleton issue. You can fix it by adjusting the method to handle recordsets, or by making sure the compute field only runs on a single record at a time. Reviewing how the travel_location_ids field is triggered can help narrow it down. It’s a bit like planning reliable operations such as sallimoservice.com, where handling multiple requests smoothly requires structuring the process correctly. In this case, refining the method logic should resolve the conflict.

0
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
How to write Record Rule with domain based on the company_dependent Fields Solved
odoo12.0
Avatar
Avatar
Avatar
3
d’oct. 23
10619
loan request
odoo12.0
Avatar
Avatar
1
de set. 23
3979
sum Colum of based on id
odoo12.0
Avatar
Avatar
1
de maig 23
2936
How to make pagination that has a table in qweb
odoo12.0
Avatar
Avatar
2
d’abr. 23
3679
Inherit Element form kanban View Solved
odoo12.0
Avatar
Avatar
1
de març 23
2856
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