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

Unable to delete several records selected from Action button. What's the problem?

Subscribe

Get notified when there's activity on this post

This question has been flagged
computed-fieldssingletonissueOdoo12.0
1 Reply
5394 Views
Avatar
Paulo Matos

Dear all,
I am using Odoo 12, and found a problem when trying to delete several selected records from the "action" button on top. When I delete records one by one (from the action button), it works fine, but If I select several records, I get the error:

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

I will try to explain what are my requirements.

1. On model_1, I need to show some records from a model_2. This is done when a user makes a selection from a Many2One field that is related to model_2.
Those records are shown on form view and if user saves the form, they are saved on model_1. If user do not save the form, the information is discarded.

In order to achieve that, I had to use "_compute_fields" on model_1 for some fields. So, the workflow is:
- User selects a record (vehicle_id field) from the many2one related field;
- The "_compute_field" function for the desired records, will get all the information required from model_2 for each field;
- The information is passed to this fields in order to be saved on the database "only if user saves the form".

So, besides other fields, my model_1 definition for the computed fields is:

    #Fields definition
    vehicle_id = fields.Many2one('mymodule.model_2', string="Vehicle", required=True)
    customer = fields.Char("Customer", readonly=True, compute='_compute_fields', store=True)
    brand = fields.Char("Brand", size=64, readonly=True, compute='_compute_fields', store=True)
    model = fields.Char("Model", size=64, readonly=True, compute='_compute_fields', store=True)
    #Compute function
    @api.multi
    @api.depends('vehicle_id')
       def _compute_fields(self):
          first_model_rec_set = self.env['mymodule.model_2'].search([('name','=',self.vehicle_id.name)])
        for rec in first_model_rec_set:
            self.customer = rec.customer_id.name
            self.brand = rec.brand_id.name
            self.model = rec.model_id.name

The error is related with this "compute function" and full error is:

Traceback (most recent call last):
  File "C:\odoo12\odoo\api.py", line 1039, in get
    value = self._data[key][field][record.id]
KeyError: 113

During handling of the above exception, another exception occurred:

"Traceback (most recent call last):
  File "C:\odoo12\odoo\fields.py", line 963, in __get__
    value = record.env.cache.get(record, self)
  File "C:\odoo12\odoo\api.py", line 1041, in get
    raise CacheMiss(record, field)
odoo.exceptions.CacheMiss: ('mymodule.model_1(113,).customer', None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\odoo12\odoo\http.py", line 654, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "C:\odoo12\odoo\http.py", line 312, in _handle_exception
    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
  File "C:\odoo12\odoo\tools\pycompat.py", line 87, in reraise
    raise value
  File "C:\odoo12\odoo\http.py", line 696, in dispatch
    result = self._call_function(**self.params)
  File "C:\odoo12\odoo\http.py", line 344, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "C:\odoo12\odoo\service\model.py", line 97, in wrapper
    return f(dbname, *args, **kwargs)
  File "C:\odoo12\odoo\http.py", line 337, in checked_call
    result = self.endpoint(*a, **kw)
  File "C:\odoo12\odoo\http.py", line 939, in __call__
    return self.method(*args, **kw)
  File "C:\odoo12\odoo\http.py", line 517, in response_wrap
    response = f(*args, **kw)
  File "c:\odoo12\addons\web\controllers\main.py", line 962, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "c:\odoo12\addons\web\controllers\main.py", line 954, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "C:\odoo12\odoo\api.py", line 749, in call_kw
    return _call_kw_multi(method, model, args, kwargs)
  File "C:\odoo12\odoo\api.py", line 736, in _call_kw_multi
    result = method(recs, *args, **kwargs)
  File "c:\workspace_36\odoo_12\custom_addons\mymodule\models\odometer.py", line 145, in unlink
    return super(mymodule_odometro, self).unlink()
  File "C:\odoo12\odoo\models.py", line 3141, in unlink
    self.recompute()
  File "C:\odoo12\odoo\models.py", line 5218, in recompute
    vals = {n: rec[n] for n in ns}
  File "C:\odoo12\odoo\models.py", line 5218, in <dictcomp>
    vals = {n: rec[n] for n in ns}
  File "C:\odoo12\odoo\models.py", line 5065, in __getitem__
    return self._fields[key].__get__(self, type(self))
  File "C:\odoo12\odoo\fields.py", line 967, in __get__
    self.determine_value(record)
  File "C:\odoo12\odoo\fields.py", line 1054, in determine_value
    self.compute_value(recs)  File "C:\odoo12\odoo\fields.py", line 1034, in compute_value    self._compute_value(records)  File "C:\odoo12\odoo\fields.py", line 1025, in _compute_value    getattr(records, self.compute)()
  File "c:\workspace_36\odoo_12\custom_addons\mymodule\models\odometer.py", line 77, in _compute_fields
    first_model_rec_set = self.env['mymodule.model_2'].search([('name','=',self.vehicle_id.name)])
  File "C:\odoo12\odoo\fields.py", line 961, in __get__
    record.ensure_one()
  File "C:\odoo12\odoo\models.py", line 4669, in ensure_one
    raise ValueError("Expected singleton: %s" % self)
ValueError: Expected singleton: mymodule.model_1(113, 112)"

How can I solve this error? Any idea about what could be the problem?

Thank you in advance.

Best regards

0
Avatar
Discard
Avatar
Niyas Raphy (Walnut Software Solutions)
Best Answer

Hi,

Update the compute function like this,

    @api.multi
    @api.depends('vehicle_id')
       def _compute_fields(self):
          for record in self:
              first_model_rec_set = self.env['mymodule.model_2'].search([('name','=',record.vehicle_id.name)])
            for rec in first_model_rec_set:
                  record.customer = rec.customer_id.name
                  record.brand = rec.brand_id.name
                  record.model = rec.model_id.name


Thanks

2
Avatar
Discard
Paulo Matos
Author

Thank you @Niyas, it's working as expected.

+1 for you.

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 prevent "compute" value from being executed on write method Solved
writeMethod computed-fields Odoo12.0
Avatar
Avatar
1
Mar 20
10097
ValueError: forbidden opcode(s) in 'lambda': STORE_ATTR
computed-fields
Avatar
Avatar
1
Jun 25
16824
Custom Dashboard using js
Odoo12.0
Avatar
Avatar
1
Apr 25
4568
Make stored compute filed recompute after changing it logic but not depedencies.
computed-fields
Avatar
Avatar
Avatar
Avatar
3
Apr 25
7414
Compute Fields Solved
computed-fields
Avatar
Avatar
2
Jul 24
9251
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