Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

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

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

How to use relativedelta in Odoo Studio for the following computed fields?

Subscribe

Get notified when there's activity on this post

This question has been flagged
#fields#studio#dateutil#datetime
2 Replies
3402 Views
Avatar
Bhoj Rani Soopal

This is my error: 


RPC_ERROR

Odoo Server Error

Traceback (most recent call last):

  File "/home/odoo/src/odoo/saas-16.4/odoo/tools/safe_eval.py", line 365, in safe_eval

    return unsafe_eval(c, globals_dict, locals_dict)

  File "", line 6, in

TypeError: 'wrap_module' object is not callable


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "/home/odoo/src/odoo/saas-16.4/odoo/http.py", line 1715, in _serve_db

    return service_model.retrying(self._serve_ir_http, self.env)

  File "/home/odoo/src/odoo/saas-16.4/odoo/service/model.py", line 133, in retrying

    result = func()

  File "/home/odoo/src/odoo/saas-16.4/odoo/http.py", line 1742, in _serve_ir_http

    response = self.dispatcher.dispatch(rule.endpoint, args)

  File "/home/odoo/src/odoo/saas-16.4/odoo/http.py", line 1943, in dispatch

    result = self.request.registry['ir.http']._dispatch(endpoint)

  File "/home/odoo/src/odoo/saas-16.4/odoo/addons/base/models/ir_http.py", line 191, in _dispatch

    result = endpoint(**request.params)

  File "/home/odoo/src/odoo/saas-16.4/odoo/http.py", line 717, in route_wrapper

    result = endpoint(self, *args, **params_ok)

  File "/home/odoo/src/odoo/saas-16.4/addons/web/controllers/dataset.py", line 30, in call_kw

    return self._call_kw(model, method, args, kwargs)

  File "/home/odoo/src/odoo/saas-16.4/addons/web/controllers/dataset.py", line 26, in _call_kw

    return call_kw(request.env[model], method, args, kwargs)

  File "/home/odoo/src/odoo/saas-16.4/odoo/api.py", line 466, in call_kw

    result = _call_kw_multi(method, model, args, kwargs)

  File "/home/odoo/src/odoo/saas-16.4/odoo/api.py", line 453, in _call_kw_multi

    result = method(recs, *args, **kwargs)

  File "/home/odoo/src/odoo/saas-16.4/odoo/models.py", line 6781, in onchange

    todo = [

  File "/home/odoo/src/odoo/saas-16.4/odoo/models.py", line 6784, in

    if name not in done and snapshot0.has_changed(name)

  File "/home/odoo/src/odoo/saas-16.4/odoo/models.py", line 6584, in has_changed

    return self[name] != record[name]

  File "/home/odoo/src/odoo/saas-16.4/odoo/models.py", line 6211, in __getitem__

    return self._fields[key].__get__(self, type(self))

  File "/home/odoo/src/odoo/saas-16.4/odoo/fields.py", line 1157, in __get__

    self.recompute(record)

  File "/home/odoo/src/odoo/saas-16.4/odoo/fields.py", line 1367, in recompute

    apply_except_missing(self.compute_value, recs)

  File "/home/odoo/src/odoo/saas-16.4/odoo/fields.py", line 1340, in apply_except_missing

    func(records)

  File "/home/odoo/src/odoo/saas-16.4/odoo/fields.py", line 1389, in compute_value

    records._compute_field_value(self)

  File "/home/odoo/src/odoo/saas-16.4/addons/base_automation/models/base_automation.py", line 434, in _compute_field_value

    _compute_field_value.origin(self, field)

  File "/home/odoo/src/odoo/saas-16.4/addons/mail/models/mail_thread.py", line 395, in _compute_field_value

    return super()._compute_field_value(field)

  File "/home/odoo/src/odoo/saas-16.4/odoo/models.py", line 4553, in _compute_field_value

    fields.determine(field.compute, self)

  File "/home/odoo/src/odoo/saas-16.4/odoo/fields.py", line 104, in determine

    return needle(records, *args)

  File "/home/odoo/src/odoo/saas-16.4/odoo/addons/base/models/ir_model.py", line 38, in

    func = lambda self: safe_eval(text, SAFE_EVAL_BASE, {'self': self}, mode="exec")

  File "/home/odoo/src/odoo/saas-16.4/odoo/tools/safe_eval.py", line 379, in safe_eval

    raise ValueError('%s: "%s" while evaluating\n%r' % (ustr(type(e)), ustr(e), expr))

ValueError: : "'wrap_module' object is not callable" while evaluating

'for record in self:\n    if record.x_studio_contract_duration_months ==0:\n       record["x_studio_contract_target_end_date"] = record.x_studio_contract_target_start_date \n       \n    if (record.x_studio_contract_target_start_date and record.x_studio_contract_duration_months):\n        future_date = record.x_studio_contract_target_start_date + dateutil.relativedelta(months=+record.x_studio_contract_duration_months)\n        print(future_date)\n        record["x_studio_contract_target_end_date"] = future_date - datetime.timedelta(days=1)\n'


The above server error caused the following client error:

null


And this is the code I am using for: 
for record in self:

    if record.x_studio_contract_duration_months ==0:

       record["x_studio_contract_target_end_date"] = record.x_studio_contract_target_start_date 

       

    if (record.x_studio_contract_target_start_date and record.x_studio_contract_duration_months):

        future_date = record.x_studio_contract_target_start_date + dateutil.relativedelta(months=+record.x_studio_contract_duration_months)

        print(future_date)

        record["x_studio_contract_target_end_date"] = future_date - datetime.timedelta(days=1)


Thanks in advance! 

0
Avatar
Discard
Avatar
Francesco Pranzo
Best Answer

try to update the code with this:

future_date = record.x_studio_contract_target_start_date + dateutil.relativedelta.relativedelta(months=+record.x_studio_contract_duration_months)



0
Avatar
Discard
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

Hi,In the given question, an attempt is made to add months which could potentially lead to an error. This is due to the usage of 'dateutil.relativedelta' with an argument of months equals to plus record.x_studio_contract_duration_months. The corrected solution uses 'dateutil.relativedelta.relativedelta' with an argument of months equals to record.x_studio_contract_duration_months to accurately apply the relative difference for adding months in date calculations. The key difference is in the correct usage of the relativedelta method for proper date manipulation. This change ensures that the months are added correctly.

By following these steps, you should be able to diagnose and potentially resolve the issue with the missing Studio tabs in your Odoo database.


Hope it helps

0
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

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

Sign up
Related Posts Replies Views Activity
Studio vs Code (V16)
#studio
Avatar
Avatar
1
Aug 23
1970
Filters / Custom Filters (V16) Solved
#studio
Avatar
Avatar
1
Aug 23
2125
"Time data does not match format" error with custom code Solved
v17 #datetime
Avatar
Avatar
1
Mar 24
3188
How to delete studio approval rules? Solved
#studio v17
Avatar
Avatar
Avatar
2
Feb 24
1885
How to make read-only fields false in 17? Solved
#fields v17
Avatar
Avatar
Avatar
3
Feb 24
5080
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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