Skip to Content
Odoo Menu
  • Zaloguj się
  • Wypróbuj za darmo
  • Aplikacje
    Finanse
    • Księgowość
    • Fakturowanie
    • Wydatki
    • Arkusz kalkulacyjny (BI)
    • Dokumenty
    • Podpisy
    Sprzedaż
    • CRM
    • Sprzedaż
    • PoS Sklep
    • PoS Restauracja
    • Subskrypcje
    • Wypożyczalnia
    Strony Internetowe
    • Kreator Stron Internetowych
    • eCommerce
    • Blog
    • Forum
    • Czat na Żywo
    • eLearning
    Łańcuch dostaw
    • Magazyn
    • Produkcja
    • PLM
    • Zakupy
    • Konserwacja
    • Jakość
    Zasoby Ludzkie
    • Pracownicy
    • Rekrutacja
    • Urlopy
    • Ocena pracy
    • Polecenia Pracownicze
    • Flota
    Marketing
    • Marketing Społecznościowy
    • E-mail Marketing
    • SMS Marketing
    • Wydarzenia
    • Automatyzacja Marketingu
    • Ankiety
    Usługi
    • Projekt
    • Ewidencja czasu pracy
    • Usługi Terenowe
    • Helpdesk
    • Planowanie
    • Spotkania
    Produktywność
    • Dyskusje
    • Zatwierdzenia
    • IoT
    • VoIP
    • Baza wiedzy
    • WhatsApp
    Aplikacje trzecich stron Studio Odoo Odoo Cloud Platform
  • Branże
    Sprzedaż detaliczna
    • Księgarnia
    • Sklep odzieżowy
    • Sklep meblowy
    • Sklep spożywczy
    • Sklep z narzędziami
    • Sklep z zabawkami
    Żywienie i hotelarstwo
    • Bar i Pub
    • Restauracja
    • Fast Food
    • Pensjonat
    • Dystrybutor napojów
    • Hotel
    Agencja nieruchomości
    • Agencja nieruchomości
    • Biuro architektoniczne
    • Budowa
    • Zarządzanie nieruchomościami
    • Ogrodnictwo
    • Stowarzyszenie właścicieli nieruchomości
    Doradztwo
    • Biuro księgowe
    • Partner Odoo
    • Agencja marketingowa
    • Kancelaria prawna
    • Agencja rekrutacyjna
    • Audyt i certyfikacja
    Produkcja
    • Tekstylia
    • Metal
    • Meble
    • Jedzenie
    • Browar
    • Prezenty firmowe
    Zdrowie & Fitness
    • Klub sportowy
    • Salon optyczny
    • Centrum fitness
    • Praktycy Wellness
    • Apteka
    • Salon fryzjerski
    Transakcje
    • Złota rączka
    • Wsparcie Sprzętu IT
    • Systemy energii słonecznej
    • Szewc
    • Firma sprzątająca
    • Usługi HVAC
    Inne
    • Organizacja non-profit
    • Agencja Środowiskowa
    • Wynajem billboardów
    • Fotografia
    • Leasing rowerów
    • Sprzedawca oprogramowania
    Przeglądaj wszystkie branże
  • Community
    Ucz się
    • Samouczki
    • Dokumentacja
    • Certyfikacje
    • Szkolenie
    • Blog
    • Podcast
    Pomóż w nauce innym
    • Program Edukacyjny
    • Scale Up! Gra biznesowa
    • Odwiedź Odoo
    Skorzystaj z oprogramowania
    • Pobierz
    • Porównaj edycje
    • Wydania
    Współpracuj
    • Github
    • Forum
    • Wydarzenia
    • Tłumaczenia
    • Zostań partnerem
    • Usługi dla partnerów
    • Zarejestruj swoją firmę rachunkową
    Skorzystaj z usług
    • Znajdź partnera
    • Znajdź księgowego
    • Spotkaj się z doradcą
    • Usługi wdrożenia
    • Opinie klientów
    • Wsparcie
    • Aktualizacje
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Zaplanuj demo
  • Cennik
  • Pomoc

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

  • CRM
  • e-Commerce
  • Księgowość
  • Zapasy
  • PoS
  • Projekt
  • MRP
All apps
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Pomoc

How to auto merge ?

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
2 Odpowiedzi
1063 Widoki
Awatar
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
Awatar
Odrzuć
Awatar
Sujata
Najlepsza odpowiedź

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
Awatar
Odrzuć
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

Awatar
Benoit
Autor Najlepsza odpowiedź

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
Awatar
Odrzuć
Podoba Ci się ta dyskusja? Dołącz do niej!

Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!

Zarejestruj się
Społeczność
  • Samouczki
  • Dokumentacja
  • Forum
Open Source
  • Pobierz
  • Github
  • Runbot
  • Tłumaczenia
Usługi
  • Hosting Odoo.sh
  • Wsparcie
  • Aktualizacja
  • Indywidualne rozwiązania
  • Edukacja
  • Znajdź księgowego
  • Znajdź partnera
  • Zostań partnerem
O nas
  • Nasza firma
  • Zasoby marki
  • Skontaktuj się z nami
  • Oferty pracy
  • Wydarzenia
  • Podcast
  • Blog
  • Klienci
  • Informacje prawne • Prywatność
  • Bezpieczeństwo Odoo
الْعَرَبيّة 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 to pakiet aplikacji biznesowych typu open source, które zaspokoją wszystkie potrzeby Twojej firmy: CRM, eCommerce, księgowość, inwentaryzacja, punkt sprzedaży, zarządzanie projektami itp.

Unikalną wartością Odoo jest to, że jest jednocześnie bardzo łatwe w użyciu i w pełni zintegrowane.

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