Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Food & Hospitality
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Guest House
    • Distributor nápojů
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Trades
    • Údržbář
    • IT hardware a podpora
    • Solar Energy Systems
    • Výrobce obuvi
    • Úklidové služby
    • HVAC Services
    Others
    • Nonprofit Organization
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Browse all Industries
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Services for Partners
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

Singleton error for Odoo 16 in action

Odebírat

Get notified when there's activity on this post

This question has been flagged
many2manysingletonodoo16features
2 Odpovědi
2294 Zobrazení
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
Zrušit
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Nejlepší odpověď

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
Zrušit
Avatar
Niyas Raphy (Walnut Software Solutions)
Nejlepší odpověď

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
Zrušit
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
Trouble with "Visible if" function in Odoo Studio Reports
singleton odoo16features
Avatar
0
zář 24
1983
Trouble with "Visible if" function in Odoo Studio Reports
singleton odoo16features
Avatar
0
dub 24
1886
Trouble with "Visible if" function in Odoo Studio Reports
singleton odoo16features
Avatar
0
dub 24
1593
[SOLVED] How to make visible selected values in many2one or many2many fields on Settings page in Odoo 16 Vyřešeno
many2one many2many odoo16features
Avatar
Avatar
Avatar
3
pro 23
7061
How to filter records based on a parent field's id Vyřešeno
many2many filter_domain odoo16features
Avatar
Avatar
2
bře 23
3687
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة 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 je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

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