Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

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

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

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

Subscribe

Get notified when there's activity on this post

This question has been flagged
odoo12.0
2 Replies
1930 Views
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
Discard
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
Discard
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
Discard
Enjoying the discussion? Don't just read, join in!

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

Sign up
Related Posts Replies Views Activity
How to write Record Rule with domain based on the company_dependent Fields Solved
odoo12.0
Avatar
Avatar
Avatar
3
Oct 23
10577
loan request
odoo12.0
Avatar
Avatar
1
Sep 23
3956
sum Colum of based on id
odoo12.0
Avatar
Avatar
1
May 23
2917
How to make pagination that has a table in qweb
odoo12.0
Avatar
Avatar
2
Apr 23
3646
Inherit Element form kanban View Solved
odoo12.0
Avatar
Avatar
1
Mar 23
2838
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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 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