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

How to auto merge ?

Inschrijven

Ontvang een bericht wanneer er activiteit is op deze post

Deze vraag is gerapporteerd
2 Antwoorden
1064 Weergaven
Avatar
Benoit

Hi guy's,


Could you tell me how to auto merge orders with the same product please ?

I would like make it with an automated action on studio.


Thank you :)

0
Avatar
Annuleer
Avatar
Sujata
Beste antwoord

Hello  Benoit,

I understand that you want to merge sales orders based on similar products. Below is an approach using Odoo Studio's Automated Actions. If this solution fits your requirements, let me know; otherwise, we can adjust the logic as needed.

Steps to Implement:

1. Create an Automated Action

  • Navigate to Odoo Studio → Automated Actions
  • Click Create to add a new action

2. Configure the Action

  • Model: Sales Order (sale.order)
  • Trigger: On Creation & Update
  • Conditions:
    • State = Draft (state = 'draft')
    • (Optional) Filter by partner_id to ensure it's a customer order
  • Action to Execute: Python Code

3. Python Code for Order Merging

# Get current sales order
so = record

# Proceed only if the order is in draft state
if so.state == 'draft':
    customer = so.partner_id
   
    # Fetch other draft sales orders for the same customer
    existing_orders = env['sale.order'].search([
        ('partner_id', '=', customer.id),
        ('state', '=', 'draft'),
        ('id', '!=', so.id)  # Exclude the current order
    ])
   
    if existing_orders:
        # Select the first existing draft order for merging
        target_so = existing_orders[0]

        for line in so.order_line:
            product = line.product_id
            qty = line.product_uom_qty

            # Check if the product exists in the target SO
            existing_line = target_so.order_line.filtered(lambda l: l.product_id == product)
           
            if existing_line:
                # Update quantity in the existing order line
                existing_line.product_uom_qty += qty
            else:
                # Move the line to the existing order
                line.write({'order_id': target_so.id})

        # Delete the original SO if it's empty after merging
        if not so.order_line:
            so.unlink()

Use Cases Covered:

✅ If a new Draft Sales Order (SO) is created for a customer and contains a product already present in another Draft SO, the product is merged into the existing order.

✅ If the original SO is empty after merging, it is automatically deleted.

Let me know if this approach works for you! 😊


1
Avatar
Annuleer
Alec

Can something like this be done on contacts too?

Sujata

yes, sure you replace sale order to contacts in place of model and then update logic according to the case

Sujata

Alec, If this helps, please upvote the answer!

Benoit
Auteur

I've test it and I cant' save the automated rule due to this message :

forbidden opcode(s) in "# Available variables:\n# - env: environment on which the action is triggered\n# - model: model of the record on which the action is triggered; is a void recordset\n# - record: record on which the action is triggered; may be void\n# - records: recordset of all records on which the action is triggered in multi-mode; may be void\n# - time, datetime, dateutil, timezone: useful Python libraries\n# - float_compare: utility function to compare floats based on specific precision\n# - b64encode, b64decode: functions to encode/decode binary data\n# - log: log(message, level='info'): logging function to record debug information in ir.logging table\n# - _logger: _logger.info(message): logger to emit messages in server logs\n# - UserError: exception class for raising user-facing warning messages\n# - Command: x2many commands namespace\n# To return an action, assign: action = {...}\n\n# Get current sales order\nso = record\n\n# Proceed only if the order is in draft state\nif so.state == 'draft':\n customer = so.partner_id\n \n # Fetch other draft sales orders for the same customer\n existing_orders = env['sale.order'].search([\n ('partner_id', '=', customer.id),\n ('state', '=', 'draft'),\n ('id', '!=', so.id) # Exclude the current order\n ])\n \n if existing_orders:\n # Select the first existing draft order for merging\n target_so = existing_orders[0]\n\n for line in so.order_line:\n product = line.product_id\n qty = line.product_uom_qty\n\n # Check if the product exists in the target SO\n existing_line = target_so.order_line.filtered(lambda l: l.product_id == product)\n \n if existing_line:\n # Update quantity in the existing order line\n existing_line.product_uom_qty += qty\n else:\n # Move the line to the existing order\n line.write({'order_id': target_so.id})\n\n # Delete the original SO if it's empty after merging\n if not so.order_line:\n so.unlink()": STORE_ATTR

Avatar
Benoit
Auteur Beste antwoord

Thanks Sujata.


To Begin I've test to put in on the model mrp.production.


Here is the result, but it doesn't work :


# Get current manufacturing order

mo = record


# Proceed only if in confirmed state

if mo.state == 'confirmed':

   

    # Fetch other confirmed manufacturing orders excluding the current one

    existing_orders = env['mrp.production'].sudo().search([

        ('state', '=', 'confirmed'),

        ('id', '!=', target_mo.id})


        # Invalidate cache uniquement avant la suppression

        if not mo.sudo().move_finished_ids:

            mo.invalidate_cache()

            mo.sudo().unlink()


0
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