Skip to Content
Odoo Menu
  • Log ind
  • Prøv gratis
  • Apps
    Økonomi
    • Bogføring
    • Fakturering
    • Udgifter
    • Regneark (BI)
    • Dokumenter
    • e-Signatur
    Salg
    • CRM
    • Salg
    • POS Butik
    • POS Restaurant
    • Abonnementer
    • Udlejning
    Hjemmeside
    • Hjemmesidebygger
    • e-Handel
    • Blog
    • Forum
    • LiveChat
    • e-Læring
    Forsyningskæde
    • Lagerbeholdning
    • Produktion
    • PLM
    • Indkøb
    • Vedligeholdelse
    • Kvalitet
    HR
    • Medarbejdere
    • Rekruttering
    • Fravær
    • Medarbejdersamtaler
    • Anbefalinger
    • Flåde
    Marketing
    • Markedsføring på sociale medier
    • E-mailmarketing
    • SMS-marketing
    • Arrangementer
    • Automatiseret marketing
    • Spørgeundersøgelser
    Tjenester
    • Projekt
    • Timesedler
    • Udkørende Service
    • Kundeservice
    • Planlægning
    • Aftaler
    Produktivitet
    • Dialog
    • Godkendelser
    • IoT
    • VoIP
    • Vidensdeling
    • WhatsApp
    Tredjepartsapps Odoo Studio Odoo Cloud-platform
  • Brancher
    Detailhandel
    • Boghandel
    • Tøjforretning
    • Møbelforretning
    • Dagligvarebutik
    • Byggemarked
    • Legetøjsforretning
    Mad og værtsskab
    • Bar og pub
    • Restaurant
    • Fastfood
    • Gæstehus
    • Drikkevareforhandler
    • Hotel
    Ejendom
    • Ejendomsmægler
    • Arkitektfirma
    • Byggeri
    • Ejendomsadministration
    • Havearbejde
    • Boligejerforening
    Rådgivning
    • Regnskabsfirma
    • Odoo-partner
    • Marketingbureau
    • Advokatfirma
    • Rekruttering
    • Audit & certificering
    Produktion
    • Tekstil
    • Metal
    • Møbler
    • Fødevareproduktion
    • Bryggeri
    • Firmagave
    Heldbred & Fitness
    • Sportsklub
    • Optiker
    • Fitnesscenter
    • Kosmetolog
    • Apotek
    • Frisør
    Håndværk
    • Handyman
    • IT-hardware og support
    • Solenergisystemer
    • Skomager
    • Rengøringsservicer
    • VVS- og ventilationsservice
    Andet
    • Nonprofitorganisation
    • Miljøagentur
    • Udlejning af billboards
    • Fotografi
    • Cykeludlejning
    • Softwareforhandler
    Gennemse alle brancher
  • Community
    Få mere at vide
    • Tutorials
    • Dokumentation
    • Certificeringer
    • Oplæring
    • Blog
    • Podcast
    Bliv klogere
    • Udannelselsesprogram
    • Scale Up!-virksomhedsspillet
    • Besøg Odoo
    Få softwaren
    • Download
    • Sammenlign versioner
    • Udgaver
    Samarbejde
    • Github
    • Forum
    • Arrangementer
    • Oversættelser
    • Bliv partner
    • Tjenester til partnere
    • Registrér dit regnskabsfirma
    Modtag tjenester
    • Find en partner
    • Find en bogholder
    • Kontakt en rådgiver
    • Implementeringstjenester
    • Kundereferencer
    • Support
    • Opgraderinger
    Github Youtube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Få en demo
  • Prissætning
  • Hjælp

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

  • CRM
  • e-Commerce
  • Bogføring
  • Lager
  • PoS
  • Projekt
  • MRP
All apps
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Hjælp

Re-usable Server actions in Automation Rules

Tilmeld

Få besked, når der er aktivitet på dette indlæg

Dette spørgsmål er blevet anmeldt
crmautomatedserver_actionsManufacturing OrderRules
456 Visninger
Avatar
Erik Orehek

Hi all,

Context

  1. Odoo 19 Enterprise.
  2. I want a reusable automation that, when a Manufacturing Order (MO) moves from “Confirmed” to “In Progress”, updates the related CRM Lead/Opportunity to a specific stage.
  3. I may need multiple automations that each move the CRM to different target stages.

Current automated action

  1. Model: Manufacturing Order (mrp.production)
  2. Trigger: State set to “In Progress”
  3. Domain filter: Components Availability = “Available”
  4. Action: Execute Python code:
for mo in records:
    # 1. Find the connected Sales Order (sale.order) by extracting the SO name from the MO's origin.
    # The MO dump shows 'origin: OP/00003 - S00038'. We try to extract 'S00038'.
    so_name = mo.origin.split(' - ')[-1].strip() if mo.origin else False

    if not so_name:
        mo.message_post(body="Warning: Could not extract a Sales Order name from the Manufacturing Order's origin.")
        continue

    SaleOrder = env['sale.order'].search([('name', '=', so_name)], limit=1)

    if not SaleOrder:
        mo.message_post(body=f"Warning: No Sales Order found with name '{so_name}'. Cannot update CRM stage.")
        continue

    # 2. Find the connected CRM Lead/Opportunity (crm.lead)
    # Assumes 'opportunity_id' is the field linking SO to CRM.
    lead = SaleOrder.opportunity_id

    if not lead:
        mo.message_post(body=f"Warning: Sales Order '{SaleOrder.name}' is not linked to a CRM Opportunity/Lead. Cannot update stage.")
        continue

    # 3. Find the 'Waiting spare parts delivery' stage in crm.stage
    target_stage = env['crm.stage'].search([('name', '=', 'Waiting spare parts delivery')], limit=1)

    if not target_stage:
        mo.message_post(body="Warning: Target CRM Stage 'Waiting spare parts delivery' not found. Stage update skipped.")
        continue

    # 4. Update the CRM Lead/Opportunity
    # Writing to the lead directly is simpler than browsing by ID.
    lead.write({'stage_id': target_stage.id})

    # Optional: Log success
    # mo.message_post(body=f"Success: Updated CRM Opportunity '{lead.name}' to stage '{target_stage.name}'.")

What I’d like

  1. Use the same Python once, but pass a different target CRM stage per automation rule. For example when click on "Produced All" (button_mark_done) in MO the CRM status should change to "Finished" stage.

Semi-workaround I have

  1. Create a separate Server Action and call it from each automation with a context param:
destination_stage = "In service"
stage = env['crm.stage'].search([('name', '=', destination_stage)], limit=1)
if not stage:
    raise UserError("CRM Stage '%s' not found." % destination_stage)

env['ir.actions.server'].browse(1124).with_context(
    active_model='mrp.production',
    active_ids=records.ids,
    crm_stage_xmlid=None,  # or name
    crm_stage_id=stage.id,
).run()

Question

Is there a cleaner or recommended pattern to parameterize the target CRM stage per automation? Examples welcome.

Thanks.

0
Avatar
Kassér
Enjoying the discussion? Don't just read, join in!

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

Tilmeld dig
Related Posts Besvarelser Visninger Aktivitet
CRM change name automatically
crm automated
Avatar
Avatar
Avatar
Avatar
3
feb. 24
2840
Automated action to create new scheduled activity Løst
crm automated
Avatar
Avatar
1
apr. 23
9651
CRM automations Løst
crm automated odoo17
Avatar
Avatar
1
dec. 24
1876
How to disable autofill in CRM Module when we select Customers?
crm automated v17
Avatar
Avatar
Avatar
2
mar. 24
2725
Link opportunity to contact using automated action
action crm automated
Avatar
0
okt. 21
2577
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Oversættelser
Tjenester
  • Odoo.sh-hosting
  • Support
  • Opgradere
  • Individuelt tilpasset udvikling
  • Uddannelse
  • Find en bogholder
  • Find en partner
  • Bliv partner
Om os
  • Vores virksomhed
  • Brandaktiver
  • Kontakt os
  • Stillinger
  • Arrangementer
  • Podcast
  • Blog
  • Kunder
  • Juridiske dokumenter • Privatlivspolitik
  • Sikkerhedspolitik
الْعَرَبيّة 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 er en samling open source-forretningsapps, der dækker alle dine virksomhedsbehov – lige fra CRM, e-handel og bogføring til lagerstyring, POS, projektledelse og meget mere.

Det unikke ved Odoo er, at systemet både er brugervenligt og fuldt integreret.

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