Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Validations
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Food & Hospitality
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Maison d’hôtes
    • Distributeur de boissons
    • Hôtel
    Immobilier
    • Agence immobilière
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consultance
    • Cabinet d'expertise comptable
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Métal
    • Meubles
    • Alimentation
    • Brewery
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Trades
    • Bricoleur
    • Matériel informatique et support
    • Systèmes photovoltaïques
    • Cordonnier
    • Services de nettoyage
    • Services CVC
    Autres
    • Organisation à but non lucratif
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Browse all Industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenez partenaire
    • Services for Partners
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide

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

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

Dynamic values in Select fields

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
fieldsselectiondynamicselect
2 Réponses
5689 Vues
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
Ignorer
Avatar
shubham shiroya
Meilleure réponse

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
Ignorer
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Meilleure réponse

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
Ignorer
Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Publications associées Réponses Vues Activité
how can I make a one2many field a selection field in view Résolu
fields selection
Avatar
Avatar
Avatar
3
oct. 25
18222
How to pass values to a method that defines selection for multiple fields?
fields selection
Avatar
0
avr. 15
4845
How To Change Field Value According To Selection Field Openerp?
fields selection
Avatar
Avatar
1
mars 15
10299
Why in Selection Field Only Key is Store in Database Not the Value ? Résolu
fields database selection
Avatar
Avatar
1
déc. 24
2436
[SOLVED] How to create dynamic selection from model data? Résolu
selection dynamic odoo10
Avatar
Avatar
2
sept. 23
13571
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenez partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة 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 est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

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