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

Adding 1 year on a date

S'inscrire

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

Cette question a été signalée
datecomputestudiocalculationstimedelta
2 Réponses
3687 Vues
Avatar
Didier Ryckaert

Hello

Can anyone help me on a single date calculation

I have 2 date fields:

'x_studio_last_maintenance_date' and 'x_studio_next_maintenance_date'

I need that in the record when i set the last_maintenance_date,  the next_maintenance_date is calculated 1 year after de last_maintenance_date

Here is what i set in the compute field in the via studio:

from datetime import timedelta
for record in self:
  record['x_studio_next_maintenance_date'] = x_studio_last_maintenance_date + timedelta(years=1) 

Then i try  it and receive this error:

Any help about this error. I do not know python

Traceback (most recent call last):
  File "/home/odoo/src/odoo/16.0/odoo/http.py", line 1578, in _serve_db
    return service_model.retrying(self._serve_ir_http, self.env)
  File "/home/odoo/src/odoo/16.0/odoo/service/model.py", line 134, in retrying
    result = func()
  File "/home/odoo/src/odoo/16.0/odoo/http.py", line 1607, in _serve_ir_http
    response = self.dispatcher.dispatch(rule.endpoint, args)
  File "/home/odoo/src/odoo/16.0/odoo/http.py", line 1804, in dispatch
    result = self.request.registry['ir.http']._dispatch(endpoint)
  File "/home/odoo/src/odoo/16.0/addons/website/models/ir_http.py", line 227, in _dispatch
    response = super()._dispatch(endpoint)
  File "/home/odoo/src/odoo/16.0/odoo/addons/base/models/ir_http.py", line 140, in _dispatch
    result = endpoint(**request.params)
  File "/home/odoo/src/odoo/16.0/odoo/http.py", line 698, in route_wrapper
    result = endpoint(self, *args, **params_ok)
  File "/home/odoo/src/odoo/16.0/addons/web/controllers/dataset.py", line 42, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "/home/odoo/src/odoo/16.0/addons/web/controllers/dataset.py", line 33, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/home/odoo/src/odoo/16.0/odoo/api.py", line 461, in call_kw
    result = _call_kw_multi(method, model, args, kwargs)
  File "/home/odoo/src/odoo/16.0/odoo/api.py", line 448, in _call_kw_multi
    result = method(recs, *args, **kwargs)
  File "/home/odoo/src/odoo/16.0/odoo/models.py", line 6514, in onchange
    todo = [
  File "/home/odoo/src/odoo/16.0/odoo/models.py", line 6517, in 
    if name not in done and snapshot0.has_changed(name)
  File "/home/odoo/src/odoo/16.0/odoo/models.py", line 6300, in has_changed
    return self[name] != record[name]
  File "/home/odoo/src/odoo/16.0/odoo/models.py", line 5842, in __getitem__
    return self._fields[key].__get__(self, type(self))
  File "/home/odoo/src/odoo/16.0/odoo/fields.py", line 1135, in __get__
    self.recompute(record)
  File "/home/odoo/src/odoo/16.0/odoo/fields.py", line 1324, in recompute
    self.compute_value(recs)
  File "/home/odoo/src/odoo/16.0/odoo/fields.py", line 1346, in compute_value
    records._compute_field_value(self)
  File "/home/odoo/src/odoo/16.0/addons/mail/models/mail_thread.py", line 403, in _compute_field_value
    return super()._compute_field_value(field)
  File "/home/odoo/src/odoo/16.0/odoo/models.py", line 4189, in _compute_field_value
    field.compute(self)
  File "/home/odoo/src/odoo/16.0/odoo/addons/base/models/ir_model.py", line 37, in 
    func = lambda self: safe_eval(text, SAFE_EVAL_BASE, {'self': self}, mode="exec")
  File "/home/odoo/src/odoo/16.0/odoo/tools/safe_eval.py", line 337, in safe_eval
    c = test_expr(expr, _SAFE_OPCODES, mode=mode, filename=filename)
  File "/home/odoo/src/odoo/16.0/odoo/tools/safe_eval.py", line 195, in test_expr
    assert_valid_codeobj(allowed_codes, code_obj, expr)
  File "/home/odoo/src/odoo/16.0/odoo/tools/safe_eval.py", line 168, in assert_valid_codeobj
    raise ValueError("forbidden opcode(s) in %r: %s" % (expr, ', '.join(opname[x] for x in (code_codes - allowed_codes))))
ValueError: forbidden opcode(s) in "from datetime import timedelta\nfor record in self:\n  record['x_studio_next_maintenance_date'] = x_studio_last_maintenance_date + timedelta(years=1) ": IMPORT_NAME, IMPORT_FROM

The above server error caused the following client error:
null

I thank you in advance

1
Avatar
Ignorer
Avatar
Waleed Ali Mohsen
Meilleure réponse

You can't use years with timedelta, so you can use relativedelta as below:

You will add  x_studio_last_maintenance_date  to  Dependencies of the field  x_studio_next_maintenance_date and use the below code:

for rec in self:
if rec.x_studio_last_maintenance_date:
rec['x_studio_next_maintenance_date'] = rec.x_studio_last_maintenance_date + dateutil.relativedelta.relativedelta(years=1)
1
Avatar
Ignorer
Hassane LAHLOU

Thank you for your help Sir. it works perfectly for me.

Avatar
Didier Ryckaert
Auteur Meilleure réponse

It works perfectly.

I really thank you. Have a nice day

1
Avatar
Ignorer
Waleed Ali Mohsen

Thanks for feedback.

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 to create recurring date in "Studio"
date studio
Avatar
Avatar
2
sept. 24
1578
Computed Field - Sum of two fields - V14
cost compute studio
Avatar
Avatar
1
sept. 23
2199
Outstanding Value in Sales Orders - V14
sales formula compute studio
Avatar
0
sept. 23
1719
Studio compute field with condition
compute studio computed-fields Studio
Avatar
Avatar
Avatar
2
août 22
6300
SUM USING TWO DATES and INT.
fields date compute integer
Avatar
Avatar
Avatar
2
mars 22
4178
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