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

Run server action only on certain products

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
actionserverroutes
2 Odpowiedzi
3201 Widoki
Awatar
Aleksander Steffensen

Hello

I am trying to add a server action / contextual action to generate an internal reference for my manufactured products that do not have an internal reference already. The Python code that is executed looks like this:

for record in records:
  if record['route_ids' == 6]:
    if not record['default_code']:
      record['default_code'] = env['ir.sequence'].next_by_code('manufactured_product.default_code')
  else:
    raise UserError(_("Product is not manufactured."))

I've checked that the "Manufacture" route has ID 6. I want Odoo to only allow generation of internal reference for manufactured products. The problem is that if I try to run this server action on products that are not manufactured (only "Buy" route), the action still runs and generates an internal reference.

I'm obviously doing something wrong here. Anyone with a sharp eye who can see what's wrong with my code?

0
Awatar
Odrzuć
Awatar
Cybrosys Techno Solutions Pvt.Ltd
Najlepsza odpowiedź

Hi,

Maybe the issue in your code is with the way you are checking if the product is manufactured or not. The condition if record['route_ids' == 6]: is not correct. You are trying to compare the 'route_ids' field with 6, but it's not the correct way to check if the product has a route with ID 6.

You should use the in operator to check if the route with ID 6 is in the 'route_ids' list. Here's the corrected code:

for record in records:
  if 6 in record['route_ids']:
    if not record['default_code']:
      record['default_code'] = env['ir.sequence'].next_by_code('manufactured_product.default_code')
  else:
    raise UserError(_("Product is not manufactured."))


Hope it helps

1
Awatar
Odrzuć
Aleksander Steffensen
Autor

Thank you for the input! :-)
Unfortunately, it does not seem to work. Now, it will not generate the internal reference with any products. I'm not seeing any errors messages, but then I don't have any shell access so I wouldn't know. But it doesn't look like the conditions are met.

Awatar
Aleksander Steffensen
Autor Najlepsza odpowiedź

So using ChatGPT I was able to find a way that worked. I think there were some problems accessing the related field in stock.route from the server actions context. Here is the code that actually works:

for record in records:
    try:
        # Use sudo() to execute the operation with elevated privileges
        route_ids = record.sudo().route_ids.ids
       
        if 6 in route_ids:
            if not record.default_code:
                # Use Odoo API to update the record
                record.sudo().write({
                    'default_code': env['ir.sequence'].next_by_code('manufactured_product.default_code')
                })
    except Exception as e:
        # Handle the exception, print or log it as needed
        print(f"Error processing record: {e}")



I've got some concerns as to the security of this code. Any thoughts?


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ę
Powiązane posty Odpowiedzi Widoki Czynność
difference between server actions and client actions in Odoo? Rozwiązane
action server
Awatar
Awatar
Awatar
Awatar
3
cze 23
13290
How to create server action incoming in human resources?
action server email
Awatar
0
mar 15
4342
How to create server action incoming in human resources?
action server email
Awatar
Awatar
2
mar 15
7858
Send emails with automated action when a purchase request is created, odoo 13 community Rozwiązane
action mail server automation
Awatar
Awatar
1
mar 24
2786
Purpose of the Scheduled Action - "Base: Auto-vacuum internal data" ?
action server auto scheduled
Awatar
Awatar
Awatar
Awatar
4
paź 23
13799
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