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

Field function definition

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
2 Odpowiedzi
8277 Widoki
Awatar
Koffi KPONOUGLO

I'm a beginner in python.

Please i am trying to define in my new module for manage Human resource posting, a field fonction named "date_to" which have to display the end date of the employee posting. I use two step to do this: fonction and field definition

Here is the fonction code

#Automatic determination of field date_to

def compute_date_to(self, date_from, date_to): # I define date_from and date_to field.datetime in the object hr.posting
    """Returns a end date for hr.posting ."""

    DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
    from_dt = datetime.datetime.strptime(date_from, DATETIME_FORMAT)
    to_dat = datetime.datetime.strptime(date_to, DATETIME_FORMAT)      
    to_dat = from_dat + timedelta(days=1826)   # Here I'm fixing the timedelta days(1826 days = 5years for me) between date_from and date_to
    return to_dat

Here is the field code

'date_to': fields.function(compute_date_to, string='Date Departure', type='datetime', readonly=True, store=True), The module is installed correctly but when i try to save one posting i have this error

Client Traceback (most recent call last): File "/home/benos/Public/latest/openerp-7.0-20130723-231040/openerp/addons/web/http.py", line 204, in dispatch response["result"] = method(self, *self.params) File "/home/benos/Public/latest/openerp-7.0-20130723-231040/openerp/addons/web/controllers/main.py", line 1130, in call_kw return self._call_kw(req, model, method, args, kwargs) File "/home/benos/Public/latest/openerp-7.0-20130723-231040/openerp/addons/web/controllers/main.py", line 1122, in _call_kw return getattr(req.session.model(model), method)(args, **kwargs) File "/home/benos/Public/latest/openerp-7.0-20130723-231040/openerp/addons/web/session.py", line 42, in proxy result = self.proxy.execute_kw(self.session._db, self.session._uid, self.session._password, self.model, method, args, kw) File "/home/benos/Public/latest/openerp-7.0-20130723-231040/openerp/addons/web/session.py", line 30, in proxy_method result = self.session.send(self.service_name, method, *args) File "/home/benos/Public/latest/openerp-7.0-20130723-231040/openerp/addons/web/session.py", line 103, in send raise xmlrpclib.Fault(openerp.tools.ustr(e), formatted_info)

Server Traceback (most recent call last): File "/home/benos/Public/latest/openerp-7.0-20130723-231040/openerp/addons/web/session.py", line 89, in send return openerp.netsvc.dispatch_rpc(service_name, method, args) File "/home/benos/Public/latest/openerp-7.0-20130723-231040/openerp/netsvc.py", line 292, in dispatch_rpc result = ExportService.getService(service_name).dispatch(method, params) File "/home/benos/Public/latest/openerp-7.0-20130723-231040/openerp/service/web_services.py", line 626, in dispatch res = fn(db, uid, params) File "/home/benos/Public/latest/openerp-7.0-20130723-231040/openerp/osv/osv.py", line 188, in execute_kw return self.execute(db, uid, obj, method, *args, *kw or {}) File "/home/benos/Public/latest/openerp-7.0-20130723-231040/openerp/osv/osv.py", line 131, in wrapper return f(self, dbname, args, *kwargs) File "/home/benos/Public/latest/openerp-7.0-20130723-231040/openerp/osv/osv.py", line 197, in execute res = self.execute_cr(cr, uid, obj, method, args, *kw) File "/home/benos/Public/latest/openerp-7.0-20130723-231040/openerp/osv/osv.py", line 185, in execute_cr return getattr(object, method)(cr, uid, args, *kw) File "/home/benos/Public/latest/openerp-7.0-20130723-231040/openerp/addons/mail/mail_thread.py", line 242, in create thread_id = super(mail_thread, self).create(cr, uid, values, context=context) File "/home/benos/Public/latest/openerp-7.0-20130723-231040/openerp/osv/orm.py", line 4478, in create self.pool.get(object)._store_set_values(cr, user, ids, fields2, context) File "/home/benos/Public/latest/openerp-7.0-20130723-231040/openerp/osv/orm.py", line 4627, in _store_set_values result = self._columns[f].get(cr, self, ids, f, SUPERUSER_ID, context=context) File "/home/benos/Public/latest/openerp-7.0-20130723-231040/openerp/osv/fields.py", line 1133, in get result = self._fnct(obj, cr, uid, ids, name, self._arg, context) TypeError: compute_date_to() takes exactly 3 arguments (7 given)

i know i choose the wrong way help me.

0
Awatar
Odrzuć
Awatar
nazarii
Najlepsza odpowiedź

First of all this method has wrong arguments for functional field computation, it need to looks like def compute_date_to(self, cr, uid, ids, field_name, args, context=None): More you can read here. Second error is you are returning wrong value and you will get error when you fix previous one(you must return dict with value for each id from ids). Also value you computed needs to be converted to string representation of datetime field. If you use exact code provided you will also get an error Name 'from_dat' is not defined. Good luck!

1
Awatar
Odrzuć
Koffi KPONOUGLO
Autor

Thanks. i will try harder.

Awatar
Serpent Consulting Services Pvt. Ltd.
Najlepsza odpowiedź

Hello Friend,

Actually there are two problems.

(1) There is problem in method definition for function field.

It should be like:

def compute_date_to(self, cr, uid, ids, field_name, args, context=None):

(2) Another problem is with return value:

It should be dictionary with key = Record ID and value = Value.

Ex. { 1 : '2013-11-11 13:00:00' }

You can apply your own logic inside method.

Thank you.

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ę
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