Skip to Content
Odoo Menu
  • Zaloguj się
  • Wypróbuj za darmo
  • Aplikacje
    Finanse
    • Księgowość
    • Fakturowanie
    • Wydatki
    • Arkusz kalkulacyjny (BI)
    • Dokumenty
    • Podpisy
    Sprzedaż
    • CRM
    • Sprzedaż
    • PoS Sklep
    • PoS Restauracja
    • Subskrypcje
    • Wypożyczalnia
    Strony Internetowe
    • Kreator Stron Internetowych
    • eCommerce
    • Blog
    • Forum
    • Czat na Żywo
    • eLearning
    Łańcuch dostaw
    • Magazyn
    • Produkcja
    • PLM
    • Zakupy
    • Konserwacja
    • Jakość
    Zasoby Ludzkie
    • Pracownicy
    • Rekrutacja
    • Urlopy
    • Ocena pracy
    • Polecenia Pracownicze
    • Flota
    Marketing
    • Marketing Społecznościowy
    • E-mail Marketing
    • SMS Marketing
    • Wydarzenia
    • Automatyzacja Marketingu
    • Ankiety
    Usługi
    • Projekt
    • Ewidencja czasu pracy
    • Usługi Terenowe
    • Helpdesk
    • Planowanie
    • Spotkania
    Produktywność
    • Dyskusje
    • Zatwierdzenia
    • IoT
    • VoIP
    • Baza wiedzy
    • WhatsApp
    Aplikacje trzecich stron Studio Odoo Odoo Cloud Platform
  • Branże
    Sprzedaż detaliczna
    • Księgarnia
    • Sklep odzieżowy
    • Sklep meblowy
    • Sklep spożywczy
    • Sklep z narzędziami
    • Sklep z zabawkami
    Żywienie i hotelarstwo
    • Bar i Pub
    • Restauracja
    • Fast Food
    • Pensjonat
    • Dystrybutor napojów
    • Hotel
    Agencja nieruchomości
    • Agencja nieruchomości
    • Biuro architektoniczne
    • Budowa
    • Zarządzanie nieruchomościami
    • Ogrodnictwo
    • Stowarzyszenie właścicieli nieruchomości
    Doradztwo
    • Biuro księgowe
    • Partner Odoo
    • Agencja marketingowa
    • Kancelaria prawna
    • Agencja rekrutacyjna
    • Audyt i certyfikacja
    Produkcja
    • Tekstylia
    • Metal
    • Meble
    • Jedzenie
    • Browar
    • Prezenty firmowe
    Zdrowie & Fitness
    • Klub sportowy
    • Salon optyczny
    • Centrum fitness
    • Praktycy Wellness
    • Apteka
    • Salon fryzjerski
    Transakcje
    • Złota rączka
    • Wsparcie Sprzętu IT
    • Systemy energii słonecznej
    • Szewc
    • Firma sprzątająca
    • Usługi HVAC
    Inne
    • Organizacja non-profit
    • Agencja Środowiskowa
    • Wynajem billboardów
    • Fotografia
    • Leasing rowerów
    • Sprzedawca oprogramowania
    Przeglądaj wszystkie branże
  • Community
    Ucz się
    • Samouczki
    • Dokumentacja
    • Certyfikacje
    • Szkolenie
    • Blog
    • Podcast
    Pomóż w nauce innym
    • Program Edukacyjny
    • Scale Up! Gra biznesowa
    • Odwiedź Odoo
    Skorzystaj z oprogramowania
    • Pobierz
    • Porównaj edycje
    • Wydania
    Współpracuj
    • Github
    • Forum
    • Wydarzenia
    • Tłumaczenia
    • Zostań partnerem
    • Usługi dla partnerów
    • Zarejestruj swoją firmę rachunkową
    Skorzystaj z usług
    • Znajdź partnera
    • Znajdź księgowego
    • Spotkaj się z doradcą
    • Usługi wdrożenia
    • Opinie klientów
    • Wsparcie
    • Aktualizacje
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Zaplanuj demo
  • Cennik
  • Pomoc

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

  • CRM
  • e-Commerce
  • Księgowość
  • Zapasy
  • PoS
  • Projekt
  • MRP
All apps
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Pomoc

Dynamic values in Select fields

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
fieldsselectiondynamicselect
2 Odpowiedzi
5688 Widoki
Awatar
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
Awatar
Odrzuć
Awatar
shubham shiroya
Najlepsza odpowiedź

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
Awatar
Odrzuć
Awatar
Cybrosys Techno Solutions Pvt.Ltd
Najlepsza odpowiedź

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
Awatar
Odrzuć
Podoba Ci się ta dyskusja? Dołącz do niej!

Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!

Zarejestruj się
Powiązane posty Odpowiedzi Widoki Czynność
how can I make a one2many field a selection field in view Rozwiązane
fields selection
Awatar
Awatar
Awatar
3
paź 25
18222
How to pass values to a method that defines selection for multiple fields?
fields selection
Awatar
0
kwi 15
4845
How To Change Field Value According To Selection Field Openerp?
fields selection
Awatar
Awatar
1
mar 15
10299
Why in Selection Field Only Key is Store in Database Not the Value ? Rozwiązane
fields database selection
Awatar
Awatar
1
gru 24
2432
[SOLVED] How to create dynamic selection from model data? Rozwiązane
selection dynamic odoo10
Awatar
Awatar
2
wrz 23
13570
Społeczność
  • Samouczki
  • Dokumentacja
  • Forum
Open Source
  • Pobierz
  • Github
  • Runbot
  • Tłumaczenia
Usługi
  • Hosting Odoo.sh
  • Wsparcie
  • Aktualizacja
  • Indywidualne rozwiązania
  • Edukacja
  • Znajdź księgowego
  • Znajdź partnera
  • Zostań partnerem
O nas
  • Nasza firma
  • Zasoby marki
  • Skontaktuj się z nami
  • Oferty pracy
  • Wydarzenia
  • Podcast
  • Blog
  • Klienci
  • Informacje prawne • Prywatność
  • Bezpieczeństwo Odoo
الْعَرَبيّة 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 to pakiet aplikacji biznesowych typu open source, które zaspokoją wszystkie potrzeby Twojej firmy: CRM, eCommerce, księgowość, inwentaryzacja, punkt sprzedaży, zarządzanie projektami itp.

Unikalną wartością Odoo jest to, że jest jednocześnie bardzo łatwe w użyciu i w pełni zintegrowane.

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