Overslaan naar inhoud
Odoo Menu
  • Aanmelden
  • Probeer het gratis
  • Apps
    Financiën
    • Boekhouding
    • Facturatie
    • Onkosten
    • Spreadsheet (BI)
    • Documenten
    • Ondertekenen
    Verkoop
    • CRM
    • Verkoop
    • Kassasysteem winkel
    • Kassasysteem Restaurant
    • Abonnementen
    • Verhuur
    Websites
    • Websitebouwer
    • E-commerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Bevoorradingsketen
    • Voorraad
    • Productie
    • PLM
    • Inkoop
    • Onderhoud
    • Kwaliteit
    Personeelsbeheer
    • Werknemers
    • Werving & Selectie
    • Verlof
    • Evaluaties
    • Aanbevelingen
    • Wagenpark
    Marketing
    • Social media Marketing
    • E-mailmarketing
    • SMS Marketing
    • Evenementen
    • Marketingautomatisering
    • Enquêtes
    Diensten
    • Project
    • Urenstaten
    • Buitendienst
    • Helpdesk
    • Planning
    • Afspraken
    Productiviteit
    • Chat
    • Goedkeuringen
    • IoT
    • VoIP
    • Kennis
    • WhatsApp
    Apps van derden Odoo Studio Odoo Cloud Platform
  • Bedrijfstakken
    Detailhandel
    • Boekhandel
    • kledingwinkel
    • Meubelzaak
    • Supermarkt
    • Bouwmarkt
    • Speelgoedwinkel
    Food & Hospitality
    • Bar en Pub
    • Restaurant
    • Fastfood
    • Gastenverblijf
    • Drankenhandelaar
    • Hotel
    Vastgoed
    • Makelaarskantoor
    • Architectenbureau
    • Bouw
    • Vastgoedbeheer
    • Tuinieren
    • Vereniging van eigenaren
    Consulting
    • Accountantskantoor
    • Odoo Partner
    • Marketingbureau
    • Advocatenkantoor
    • Talentenwerving
    • Audit & Certificering
    Productie
    • Textiel
    • Metaal
    • Meubels
    • Eten
    • Brewery
    • Relatiegeschenken
    Gezondheid & Fitness
    • Sportclub
    • Opticien
    • Fitnesscentrum
    • Wellness-medewerkers
    • Apotheek
    • Kapper
    Trades
    • Klusjesman
    • IT-hardware & support
    • Zonne-energiesystemen
    • Schoenmaker
    • Schoonmaakdiensten
    • HVAC-diensten
    Andere
    • Non-profitorganisatie
    • Milieuagentschap
    • Verhuur van Billboards
    • Fotograaf
    • Fietsleasing
    • Softwareverkoper
    Browse all Industries
  • Community
    Leren
    • Tutorials
    • Documentatie
    • Certificeringen
    • Training
    • Blog
    • Podcast
    Versterk het onderwijs
    • Onderwijs- programma
    • Scale Up! Business Game
    • Bezoek Odoo
    Download de Software
    • Downloaden
    • Vergelijk edities
    • Releases
    Werk samen
    • Github
    • Forum
    • Evenementen
    • Vertalingen
    • Word een Partner
    • Services for Partners
    • Registreer je accountantskantoor
    Diensten
    • Vind een partner
    • Vind een boekhouder
    • Een adviseur ontmoeten
    • Implementatiediensten
    • Klantreferenties
    • Ondersteuning
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Vraag een demo aan
  • Prijzen
  • Help

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

  • CRM
  • e-Commerce
  • Boekhouding
  • Voorraad
  • PoS
  • Project
  • MRP
All apps
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Help

V19: Create Scheduled Actions

Inschrijven

Ontvang een bericht wanneer er activiteit is op deze post

Deze vraag is gerapporteerd
2 Antwoorden
226 Weergaven
Avatar
Benoit Vanasse

Hello and thank you for taking the time to review my post.

I would like to preface that I know a little about coding but not much, I am trying to configure my own Odoo for my small business.

I have to do maintenance on Equipment for my clients at set intervals (typically 3 month interval).

I would like to set Activity to remind myself to create the maintenance task. I do not wish to create the task automatically because those maintenance are often pushed to a later date by my customers.

With Studio, I added the following fields:

  • Date field : to display the next planned maintenance date
  • Integer field : to display the desired interval for maintenance (default 3)
I went to Scheduled Action and created a new action.
I set the Model to "Maintenance Equipment" which is where I keep my Equipment data.
The action is set to execute every 1 day.

I tried to get a code from GPT to run Action and create an automatic Activity everyday and then increase the value of the Date field by the number of months in the Integer field.

The code saves but when I try to run it manually, I do not see any added Activities being generated. Could anyone help me fix this code please?

Thank you!
Ben

Code:

# Get today's date using Odoo's fields helper
today = fields.Date.today()

# Find all equipment whose next PM date is today or earlier
to_process = records.filtered(
    lambda r: r.x_studio_next_pm_date and r.x_studio_next_pm_date <= today
)

for rec in to_process:
    # Create a reminder activity (admin must create PM task manually)
    env['mail.activity'].create({
        'res_model_id': env['ir.model']._get_id(rec._name),
        'res_id': rec.id,
        'activity_type_id': env.ref('mail.mail_activity_data_todo').id,
        'summary': "PM due for %s" % rec.name,
        'note': "Time to review this equipment and create a Field Service task if needed.",
        'date_deadline': today,
        'user_id': 11,  # put the correct user ID here
    })

    # Reschedule next PM date (use Odoo's Date.add, no import)
    freq = rec.x_studio_pm_frequency or 3
    next_date = fields.Date.add(rec.x_studio_next_pm_date, months=freq)

    # Use write() instead of direct assignment
    rec.write({
        'x_studio_next_pm_date': next_date,
    })


0
Avatar
Annuleer
Codesphere Tech

Hello,
Try this:
to_process = model.search([
('x_studio_next_pm_date', '<=', today),
('x_studio_next_pm_date', '!=', False)
])

Benoit Vanasse
Auteur
Thank you for the suggestion!

I read this updated code and still I did not get any activities generated. :(

Code:

# Get today's date using Odoo's fields helper
today = fields.Date.today()

# Find all equipment whose next PM date is today or earlier
to_process = model.search([
('x_studio_next_pm_date', '<=', today),
('x_studio_next_pm_date', '!=', False)
])

for rec in to_process:
    # Create a reminder activity (admin must create PM task manually)
    env['mail.activity'].create({
        'res_model_id': env['ir.model']._get_id(rec._name),
        'res_id': rec.id,
        'activity_type_id': env.ref('mail.mail_activity_data_todo').id,
        'summary': "PM due for %s" % rec.name,
        'note': "Time to review this equipment and create a Field Service task if needed.",
        'date_deadline': today,
        'user_id': 11,  # put the correct user ID here
    })

    # Reschedule next PM date (use Odoo's Date.add, no import)
    freq = rec.x_studio_pm_frequency or 3
    next_date = fields.Date.add(rec.x_studio_next_pm_date, months=freq)

    # Use write() instead of direct assignment
    rec.write({
        'x_studio_next_pm_date': next_date,
    })


Avatar
Kunjan Patel
Beste antwoord
Hello Benoit Vanasse,
I hope you are doing well

Quick Fix for Odoo v19 Scheduled Actions
1. Search returns no records - verify equipment actually has x_studio_next_pm_date <= today
2.Missing required fields in activity creation - need res_model_id and user_id

Working Code:
  from datetime import date
  from dateutil.relativedelta import relativedelta

  today = date.today()
  equipment = env['maintenance.equipment'].search([
      ('x_studio_next_pm_date', '<=', today)
  ])
  for rec in equipment:
      env['mail.activity'].create({
          'res_model_id': env['ir.model']._get('maintenance.equipment').id,
          'res_id': env.user.id,
      })

      interval = rec.x_studio_pm_interval or 3
      rec.write({
          'x_studio_next_pm_date': today + relativedelta(months=interval)
      })

Debug: Check server logs after "Run Manually" to see if records are found.


I hope this information helps you

Thanks & Regards,
Kunjan Patel

0
Avatar
Annuleer
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Beste antwoord
Hi,
To create a scheduled action in Odoo v19:

    First, activate Developer Mode.

    Then go to Settings → Technical → Automation → Scheduled Actions.

    Click New. Fill in:

        Name — give a clear title.

        Model — choose which model the action should run on (for example: sale.order, stock.move, or a custom model).

        Action — choose “code” if you want to run a Python method of the model, and in the Code field write something like:
        model.your_method_name()

        Interval — define how often it runs (e.g. every 1 day, 1 hour, etc).

        Next Execution Date, Number of Calls (e.g. -1 for infinite).

    Save the scheduled action — if “Active” is checked, Odoo will run it automatically according to schedule.

If you need to test it immediately, you can hit Run Manually from the Scheduled Actions list (in developer mode) to trigger it right away.


Hope it helps

-2
Avatar
Annuleer
Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!

Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!

Aanmelden
Community
  • Tutorials
  • Documentatie
  • Forum
Open Source
  • Downloaden
  • Github
  • Runbot
  • Vertalingen
Diensten
  • Odoo.sh Hosting
  • Ondersteuning
  • Upgrade
  • Gepersonaliseerde ontwikkelingen
  • Onderwijs
  • Vind een boekhouder
  • Vind een partner
  • Word een Partner
Over ons
  • Ons bedrijf
  • Merkelementen
  • Neem contact met ons op
  • Vacatures
  • Evenementen
  • Podcast
  • Blog
  • Klanten
  • Juridisch • Privacy
  • Beveiliging
الْعَرَبيّة 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 een suite van open source zakelijke apps die aan al je bedrijfsbehoeften voldoet: CRM, E-commerce, boekhouding, inventaris, kassasysteem, projectbeheer, enz.

Odoo's unieke waardepropositie is om tegelijkertijd zeer gebruiksvriendelijk en volledig geïntegreerd te zijn.

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