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

Dynamic values in Select fields

Iscriviti

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

La domanda è stata contrassegnata
fieldsselectiondynamicselect
2 Risposte
5675 Visualizzazioni
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
Abbandona
Avatar
shubham shiroya
Risposta migliore

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
Abbandona
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Risposta migliore

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
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à
how can I make a one2many field a selection field in view Risolto
fields selection
Avatar
Avatar
Avatar
3
ott 25
18199
How to pass values to a method that defines selection for multiple fields?
fields selection
Avatar
0
apr 15
4820
How To Change Field Value According To Selection Field Openerp?
fields selection
Avatar
Avatar
1
mar 15
10290
Why in Selection Field Only Key is Store in Database Not the Value ? Risolto
fields database selection
Avatar
Avatar
1
dic 24
2420
[SOLVED] How to create dynamic selection from model data? Risolto
selection dynamic odoo10
Avatar
Avatar
2
set 23
13554
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