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

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

Subscriure's

Get notified when there's activity on this post

This question has been flagged
computed-fieldssingletonissueOdoo12.0
1 Respondre
5402 Vistes
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
Descartar
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
Descartar
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!

Registrar-se
Related Posts Respostes Vistes Activitat
How to prevent "compute" value from being executed on write method Solved
writeMethod computed-fields Odoo12.0
Avatar
Avatar
1
de març 20
10105
ValueError: forbidden opcode(s) in 'lambda': STORE_ATTR
computed-fields
Avatar
Avatar
1
de juny 25
16830
Custom Dashboard using js
Odoo12.0
Avatar
Avatar
1
d’abr. 25
4571
Make stored compute filed recompute after changing it logic but not depedencies.
computed-fields
Avatar
Avatar
Avatar
Avatar
3
d’abr. 25
7422
Compute Fields Solved
computed-fields
Avatar
Avatar
2
de jul. 24
9259
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