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í
    Jídlo a pohostinství
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Penzion
    • Distributor nápojů
    • Hotel
    Nemovitost
    • Realitní kancelář
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Poradenství
    • Účetní firma
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textile
    • Kov
    • Nábytek
    • Jídlo
    • Brewery
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • IT hardware a podpora
    • Systémy solární energie
    • Výrobce obuvi
    • Úklidové služby
    • Služby HVAC
    Ostatní
    • Nezisková organizace
    • 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

Dynamic values in Select fields

Odebírat

Get notified when there's activity on this post

This question has been flagged
fieldsselectiondynamicselect
2 Odpovědi
5695 Zobrazení
Avatar
Thibaud

Hello,


My class purchase.order contain the following object :

new_line = {
'order_id': False,
'product_id': line.product.id,
'name': line.product.name,
'product_qty': line.quantity,
'date_planned': i.date_to,
'product_uom': 1,
'price_unit': line.price,
'history_field': [
('first',
str(line.quantity) + ' / ' + str((good_date + datetime.timedelta(hours=2)).strftime("%x")))
]
}

Then in purchase.order.line class I want to display into a selection field the object history field :

history_field = fields.Selection([], string='Historique')


I can retrieve it, I mean when I do a print it shows good values but I've got this error :

  File "/odoo/odoo-server/openerp/fields.py", line 1545, in convert_to_cache
    raise ValueError("Wrong value for %s: %r" % (self, value))
ValueError: Wrong value for purchase.order.line.history_field: [('first', '7.0 / 15/10/2020')]

I can see good values as inside my print in this error, but it still doesn't work.

Thanks
0
Avatar
Zrušit
Avatar
shubham shiroya
Nejlepší odpověď

you need to update the history_field field in the purchase.order.line model to match the format of the history_field value you are trying to set.

If you want to store multiple values in the history_field, you should use a One2many or Many2many field instead of a Selection field. Here's how you can do it:

  1. Define a new model for history_field:

class PurchaseOrderLineHistory(models.Model):

_name = 'purchase.order.line.history'

_description = 'Purchase Order Line History'


order_line_id = fields.Many2one('purchase.order.line', string='Order Line')

first = fields.Char(string='First')

# Add other fields as needed


  1. Update the history_field field in the purchase.order.line model to use the newly created model:


class PurchaseOrderLine(models.Model):

_inherit = 'purchase.order.line'


history_field = fields.One2many('purchase.order.line.history', 'order_line_id', string='Historique')


  1. Modify the creation of the new_line dictionary to use the new model:


history_vals = {

'first': str(line.quantity) + ' / ' + str((good_date + datetime.timedelta(hours=2)).strftime("%x"))

}


new_line = {

'order_id': False,

'product_id': line.product.id,

'name': line.product.name,

'product_qty': line.quantity,

'date_planned': i.date_to,

'product_uom': 1,

'price_unit': line.price,

'history_field': [(0, 0, history_vals)],

}


With this approach, the history_field in the purchase.order.line model will be a One2many field that can store multiple values, each represented by a record in the purchase.order.line.history model.

0
Avatar
Zrušit
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Nejlepší odpověď

Hi,

Although the history_field attribute of the purchase.order.line class is designed as a Selection field, which can only accept a single value from a preset list of options, it appears that you are attempting to store a list of tuples there. You are experiencing the "wrong value" error as a result.

Before you add the data to the history_field, you will need to prepare it properly to solve this problem. You should provide a list of tuples containing appropriate options for the field since the history_field is a selection field. The value to be stored and the display label should be present in each tuple.
from datetime import datetime, timedelta

# Assuming you have 'good_date' and 'line' defined somewhere

history_data = str(line.quantity) + ' / ' + str((good_date + timedelta(hours=2)).strftime("%x"))
history_field = str([(history_data, history_data)])

# Assign the history_field as a string to the selection field
history_field = fields.Selection([], string='History')

# Now set the value of the history_field
history_field = history_data

Please note that this method stores the history data in the selected field as a string. Use a JSON field or another appropriate data format if you may subsequently need to view or modify specific historical entries.

Hope it helps

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
how can I make a one2many field a selection field in view Vyřešeno
fields selection
Avatar
Avatar
Avatar
3
říj 25
18226
How to pass values to a method that defines selection for multiple fields?
fields selection
Avatar
0
dub 15
4848
How To Change Field Value According To Selection Field Openerp?
fields selection
Avatar
Avatar
1
bře 15
10301
Why in Selection Field Only Key is Store in Database Not the Value ? Vyřešeno
fields database selection
Avatar
Avatar
1
pro 24
2440
[SOLVED] How to create dynamic selection from model data? Vyřešeno
selection dynamic odoo10
Avatar
Avatar
2
zář 23
13574
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