Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

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

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

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

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
computed-fieldssingletonissueOdoo12.0
1 Răspunde
5404 Vizualizări
Imagine profil
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
Imagine profil
Abandonează
Imagine profil
Niyas Raphy (Walnut Software Solutions)
Cel mai bun răspuns

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
Imagine profil
Abandonează
Paulo Matos
Autor

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!

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
How to prevent "compute" value from being executed on write method Rezolvat
writeMethod computed-fields Odoo12.0
Imagine profil
Imagine profil
1
mar. 20
10107
ValueError: forbidden opcode(s) in 'lambda': STORE_ATTR
computed-fields
Imagine profil
Imagine profil
1
iun. 25
16830
Custom Dashboard using js
Odoo12.0
Imagine profil
Imagine profil
1
apr. 25
4571
Make stored compute filed recompute after changing it logic but not depedencies.
computed-fields
Imagine profil
Imagine profil
Imagine profil
Imagine profil
3
apr. 25
7425
Compute Fields Rezolvat
computed-fields
Imagine profil
Imagine profil
2
iul. 24
9259
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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