Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    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 Managament
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Producție
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and 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
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

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

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

How to auto merge ?

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
2 Răspunsuri
1020 Vizualizări
Imagine profil
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
Imagine profil
Abandonează
Imagine profil
Sujata
Cel mai bun răspuns

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
Imagine profil
Abandonează
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
Autor

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

Imagine profil
Benoit
Autor Cel mai bun răspuns

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
Imagine profil
Abandonează
Enjoying the discussion? Don't just read, join in!

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

Înscrie-te
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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