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 on One2many model with related fields

Subscriure's

Get notified when there's activity on this post

This question has been flagged
one2manyrelatedodoo10
6 Respostes
6411 Vistes
Avatar
Samo Arko

I looked at different forum posts but I don't see a fix. I have 2 custom models that are in a relation One2many. One the many side I have a few related fields just for displaying the data in the view. Now if I change a value on the One side model that is related to the many side model I get the Expected singleton: my_custom_model_many(id1, id2, id3).

How can I fix this? I tough to make create and  write methods @api.multi and then iterate with "for rec in self:" but they have return statements so the methods would finish in the first iteration. 

If anyone has any suggestions with maybe a code example, that would be very appreciated!  


class my_custom_module_one(models.Model):
	_name = 'my.custom.one'
	month = fields.Char()
	date_from = fields.Date()
	date_to = fields.Date()

	many_ids = fields.One2many('my.custom.many', 'one_id')

class my_custom_module_many(models.Model):
	_name = 'my.custom.many'
	one_month = fields.Char(related='one_id.month')
	one_date_form = fields.Date(related='one_id.date_from')
	one_date_to = fields.Date(related='one_id.date_to')

	one_id = fields.Many2one('my.custom.one')
0
Avatar
Descartar
Niyas Raphy (Walnut Software Solutions)

Can you update the question with your code and with the error message

Samo Arko
Autor

Can't update the question... get only 403 forbidden page.

Niyas Raphy (Walnut Software Solutions)

I have updated the question with what you have put as answer, by with this code there will not be any issues, I think you may have written some other functions in it

Avatar
ayman mohammed adam
Best Answer

Dear Samo Arko

I think you must use @api.multi instead of @api.one  on specific function and make for loop in your function:

@api.multi

def your_function_name(self):

      for rec in self:

                     ......................



I Hope I helped you..

0
Avatar
Descartar
Samo Arko
Autor

ok... I've removed the api.one method decorators. I've used them only a few for returning values of calculations. Didn't know that they are deprecated or I wouldn't even use them. But I'm still getting the error. A line before the "Except singleton" is "odoo models.py", line 4820, in ensure_one"

Samo Arko
Autor

Thanks for getting me on the right path! can't up vote your answer else I would!

ayman mohammed adam

Thanks..

Avatar
Samo Arko
Autor Best Answer

Thank all you guys for the help. Aymans answer got me on the right path. I all ready changed the @api.one to @api.multi decorators. After I changed all and still got the error I looked on those that I changed before. And there was the problem. In one of the methods I forgot to change self to rec when I added the for rec in self. 

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
get Job_ids from hr_contracts one2many field Solved
one2many related
Avatar
Avatar
1
de maig 24
3324
One2many field odoo version 10
one2many odoo10
Avatar
Avatar
1
de set. 22
2858
"RuntimeError: maximum recursion depth exceeded in cmp" problem
one2many odoo10
Avatar
Avatar
Avatar
Avatar
4
de maig 18
12079
Values has false in one2many field when changing the customer in Sale Order ODOO 10
one2many sale.order.line odoo10
Avatar
0
de març 23
6013
Prevent create and delete on a One2many tree view Solved
treeview one2many odoo10
Avatar
1
de jul. 20
9408
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