Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Priemyselné odvetvia
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Reštaurácia
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Reality
    • Real Estate Agency
    • Architecture Firm
    • Konštrukcia
    • Estate Managament
    • Gardening
    • Property Owner Association
    Poradenstvo
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Jedlo
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Iní
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

Field function definition

Odoberať

Get notified when there's activity on this post

This question has been flagged
2 Replies
8279 Zobrazenia
Avatar
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
Avatar
Zrušiť
Avatar
nazarii
Best Answer

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
Avatar
Zrušiť
Koffi KPONOUGLO
Autor

Thanks. i will try harder.

Avatar
Serpent Consulting Services Pvt. Ltd.
Best Answer

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
Avatar
Zrušiť
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrácia
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة 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 sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

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