Passa al contenuto
Odoo Menu
  • Accedi
  • Provalo gratis
  • App
    Finanze
    • Contabilità
    • Fatturazione
    • Note spese
    • Fogli di calcolo (BI)
    • Documenti
    • Firma
    Vendite
    • CRM
    • Vendite
    • Punto vendita Negozio
    • Punto vendita Ristorante
    • Abbonamenti
    • Noleggi
    Siti web
    • Configuratore sito web
    • E-commerce
    • Blog
    • Forum
    • Live chat
    • E-learning
    Supply chain
    • Magazzino
    • Produzione
    • PLM
    • Acquisti
    • Manutenzione
    • Qualità
    Risorse umane
    • Dipendenti
    • Assunzioni
    • Ferie
    • Valutazioni
    • Referral dipendenti
    • Parco veicoli
    Marketing
    • Social marketing
    • E-mail marketing
    • SMS marketing
    • Eventi
    • Marketing automation
    • Sondaggi
    Servizi
    • Progetti
    • Fogli ore
    • Assistenza sul campo
    • Helpdesk
    • Pianificazione
    • Appuntamenti
    Produttività
    • Comunicazioni
    • Approvazioni
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    App di terze parti Odoo Studio Piattaforma cloud Odoo
  • Settori
    Retail
    • Libreria
    • Negozio di abbigliamento
    • Negozio di arredamento
    • Alimentari
    • Ferramenta
    • Negozio di giocattoli
    Cibo e ospitalità
    • Bar e pub
    • Ristorante
    • Fast food
    • Pensione
    • Grossista di bevande
    • Hotel
    Agenzia immobiliare
    • Agenzia immobiliare
    • Studio di architettura
    • Edilizia
    • Gestione immobiliare
    • Impresa di giardinaggio
    • Associazione di proprietari immobiliari
    Consulenza
    • Società di contabilità
    • Partner Odoo
    • Agenzia di marketing
    • Studio legale
    • Selezione del personale
    • Audit e certificazione
    Produzione
    • Tessile
    • Metallo
    • Arredamenti
    • Alimentare
    • Birrificio
    • Ditta di regalistica aziendale
    Benessere e sport
    • Club sportivo
    • Negozio di ottica
    • Centro fitness
    • Centro benessere
    • Farmacia
    • Parrucchiere
    Commercio
    • Tuttofare
    • Hardware e assistenza IT
    • Ditta di installazione di pannelli solari
    • Calzolaio
    • Servizi di pulizia
    • Servizi di climatizzazione
    Altro
    • Organizzazione non profit
    • Ente per la tutela ambientale
    • Agenzia di cartellonistica pubblicitaria
    • Studio fotografico
    • Punto noleggio di biciclette
    • Rivenditore di software
    Carica tutti i settori
  • Community
    Apprendimento
    • Tutorial
    • Documentazione
    • Certificazioni 
    • Formazione
    • Blog
    • Podcast
    Potenzia la tua formazione
    • Programma educativo
    • Scale Up! Business Game
    • Visita Odoo
    Ottieni il software
    • Scarica
    • Versioni a confronto
    • Note di versione
    Collabora
    • Github
    • Forum
    • Eventi
    • Traduzioni
    • Diventa nostro partner
    • Servizi per partner
    • Registra la tua società di contabilità
    Ottieni servizi
    • Trova un partner
    • Trova un contabile
    • Incontra un esperto
    • Servizi di implementazione
    • Testimonianze dei clienti
    • Supporto
    • Aggiornamenti
    GitHub Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Richiedi una demo
  • Prezzi
  • Aiuto

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

  • CRM
  • e-Commerce
  • Contabilità
  • Magazzino
  • PoS
  • Progetti
  • MRP
All apps
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
Assistenza

Singleton error for Odoo 16 in action

Iscriviti

Ricevi una notifica quando c'è un'attività per questo post

La domanda è stata contrassegnata
many2manysingletonodoo16features
2 Risposte
2302 Visualizzazioni
Avatar
Alark Kulkarni

Hello,

I'm getting a singleton error in if-else condition and would like to add for loop to run code smoothly. The error is arising at 

'partner_id': rec.partner_ids.id,

in which partner_ids is many2many. The action code is as below

def action_create_purchase_order(self):
"""create purchase order and internal transfer"""
for rec in self.requisition_order_ids:
if rec.requisition_type == 'internal_transfer':
self.env['stock.picking'].create({
'location_id': self.source_location_id.id,
'location_dest_id': self.destination_location_id.id,
'picking_type_id': self.internal_picking_id.id,
'requisition_order': self.name,
'move_ids_without_package': [(0, 0, {
'name': rec.product_id.name,
'product_id': rec.product_id.id,
'product_uom': rec.product_id.uom_id,
'product_uom_qty': rec.quantity,
'location_id': self.source_location_id.id,
'location_dest_id': self.destination_location_id.id,
})]
})
else:
self.env['purchase.order'].create({
'partner_id': rec.partner_ids.id,
'requisition_order': self.name,
'project_requisition_name': self.project_requisition_name_id.name,
'job_number': self.job_num,
"order_line": [(0, 0, {
'product_id': rec.product_id.id,
'product_qty': rec.quantity,
'name': rec.description,
})]})
self.write({'state': 'purchase_order_created'})

Thank you in advance.

0
Avatar
Abbandona
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Risposta migliore

Hi,

In the partner_ids fields that you are calling in the else condition will have a list of records, that's the reason for the singleton error.If you want to create a purchase order for all the partners in the list, you can change your code in the else condition in to:else:
            for partner_id in rec.partner_ids:
                self.env['purchase.order'].create({
                    'partner_id': partner_id.id,
                    'requisition_order': self.name,
                    'project_requisition_name': self.project_requisition_name_id.name,
                    'job_number': self.job_num,
                    "order_line": [(0, 0, {
                        'product_id': rec.product_id.id,
                        'product_qty': rec.quantity,
                        'name': rec.description,
                    })]})

If you don't need to loop through the partner_ids and only need to select one partner from the list, you can access it using indexes.
else:
                self.env['purchase.order'].create({
                    'partner_id': rec.partner_ids[0].id,
                    'requisition_order': self.name,
                    'project_requisition_name': self.project_requisition_name_id.name,
                    'job_number': self.job_num,
                    "order_line": [(0, 0, {
                        'product_id': rec.product_id.id,
                        'product_qty': rec.quantity,
                        'name': rec.description,
                    })]})


Hope it helps

0
Avatar
Abbandona
Avatar
Niyas Raphy (Walnut Software Solutions)
Risposta migliore

Hi,

Here the problem is that the partner_id field in the purchase order model is Many2one and rec.partner_ids field is a many2many field.

So when there is multiple values inside the rec.partner_ids and when you try to access the rec.partner_ids.id you will get single ton error, you can resolve it by passing ids instead of id, ie, rec.partner_ids.ids which will give list of ids, but still you cannot write into the partner_id field.

rec.partner_ids.id --- will give error when there is multiple partner
rec.partner_ids.ids ---- [2,5,6]

So depending on your need you have to create multiple purchase order for each partners or select one of the partner from the partner_ids and create the po.

For now change as follows: rec.partner_ids[0].id and see if this solves your issue technically and functionally

Thanks

0
Avatar
Abbandona
Ti stai godendo la conversazione? Non leggere soltanto, partecipa anche tu!

Crea un account oggi per scoprire funzionalità esclusive ed entrare a far parte della nostra fantastica community!

Registrati
Post correlati Risposte Visualizzazioni Attività
Trouble with "Visible if" function in Odoo Studio Reports
singleton odoo16features
Avatar
0
set 24
1991
Trouble with "Visible if" function in Odoo Studio Reports
singleton odoo16features
Avatar
0
apr 24
1889
Trouble with "Visible if" function in Odoo Studio Reports
singleton odoo16features
Avatar
0
apr 24
1598
[SOLVED] How to make visible selected values in many2one or many2many fields on Settings page in Odoo 16 Risolto
many2one many2many odoo16features
Avatar
Avatar
Avatar
3
dic 23
7083
How to filter records based on a parent field's id Risolto
many2many filter_domain odoo16features
Avatar
Avatar
2
mar 23
3697
Community
  • Tutorial
  • Documentazione
  • Forum
Open source
  • Scarica
  • Github
  • Runbot
  • Traduzioni
Servizi
  • Hosting Odoo.sh
  • Supporto
  • Aggiornamenti
  • Sviluppi personalizzati
  • Formazione
  • Trova un contabile
  • Trova un partner
  • Diventa nostro partner
Chi siamo
  • La nostra azienda
  • Branding
  • Contattaci
  • Lavora con noi
  • Eventi
  • Podcast
  • Blog
  • Clienti
  • Note legali • Privacy
  • Sicurezza
الْعَرَبيّة 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 è un gestionale di applicazioni aziendali open source pensato per coprire tutte le esigenze della tua azienda: CRM, Vendite, E-commerce, Magazzino, Produzione, Fatturazione elettronica, Project Management e molto altro.

Il punto di forza di Odoo è quello di offrire un ecosistema unico di app facili da usare, intuitive e completamente integrate tra loro.

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