Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Jídlo a pohostinství
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Penzion
    • Distributor nápojů
    • Hotel
    Nemovitost
    • Realitní kancelář
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Poradenství
    • Účetní firma
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textil
    • Kov
    • Nábytek
    • Jídlo
    • Pivovar
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • Podpora IT & hardware
    • Systémy solární energie
    • Výrobce obuvi
    • Úklidové služby
    • Služby HVAC
    Ostatní
    • Nezisková organizace
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Procházet všechna odvětví
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Služby pro partnery
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

Automation Help to prevent Client Reference duplicates.

Odebírat

Get notified when there's activity on this post

This question has been flagged
helpsales.orderautomationv15
2 Odpovědi
4564 Zobrazení
Avatar
Alex Ashcroft

Hi all,

I am attempting to add in some automation in v15 for the sales order function, specifically to prevent duplication of the client reference number (field client_order_ref). 


I have already found the automation section and added the model, trigger and trigger fields (the client ref) but I am stuck on what python code to use to search for duplicates and then show a warning to stop the user from proceeding if it already exists.


Can anyone assist? Thanks in advance!


Apologies I cannot provide a screenshot as I don't have enough karma yet. 

0
Avatar
Zrušit
Avatar
Alex Ashcroft
Autor Nejlepší odpověď

Hi Geekboy (great name btw),


I tried using the above code but my DB doesn't recognise the inherit field in the 4th line. Any other suggestions? 

0
Avatar
Zrušit
Avatar
Bhavin Patel
Nejlepší odpověď

To prevent duplication of the client_order_ref field in the sales order model in Odoo 15, you can use a @api.constrains decorator to add a constraint that checks if the value already exists in the database. If a duplicate value is found, you can raise a ValidationError to prevent the user from proceeding with the sales order creation.

Here's an example code:

python

from odoo import api, fields, models, _

class SaleOrder(models.Model):
​_inherit = 'sale.order'

​client_order_ref = fields.Char('Client Reference')

​# Constraint to prevent duplication of client_order_ref
​@api.constrains('client_order_ref')
​def check_duplicate_client_order_ref(self):
​ ​for order in self:
​ ​ ​if order.client_order_ref:
​ ​ ​ ​duplicate_order = self.search([('client_order_ref', '=', order.client_order_ref), ('id', '!=', order.id)], limit=1)
​ ​ ​ ​if duplicate_order:
​ ​ ​ ​ ​raise ValidationError(_('The client reference number already exists in the system. Please enter a unique value.'))

In this code snippet, the SaleOrder model inherits the sale.order model and adds a new client_order_ref field. The @api.constrains decorator is used to define a constraint function that checks for duplicates of the client_order_ref field in the database.

The for loop iterates over each sale.order record and checks if the client_order_ref field is not empty. The search() function is used to search for other sale.order records that have the same client_order_ref value, excluding the current record (order.id). If a duplicate record is found, a ValidationError is raised with a warning message that informs the user that the client reference number already exists in the system.

Once you have added this code to your Odoo 15 instance, the constraint will be automatically applied whenever a new sales order is created or an existing one is updated. If the user tries to save a sales order with a duplicate client_order_ref value, they will be prevented from proceeding and will be shown the warning message you defined in the ValidationError

0
Avatar
Zrušit
Enjoying the discussion? Don't just read, join in!

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

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
How To ensure that a user only sees their default warehouse in inventory in Odoo 15
help v15
Avatar
Avatar
Avatar
2
čvc 23
3486
I'm having trouble displaying a message in the purchase template based on a boolean field (when true)
help v15
Avatar
Avatar
1
kvě 23
3035
Tooltips wont show up ODOO15 Vyřešeno
help tooltip v15
Avatar
Avatar
1
úno 25
3943
Create a sales order line via automation
sales.order automation salesorderlines
Avatar
Avatar
2
čvn 24
2058
Odoo 15 composed product
sales.order product.template v15
Avatar
0
úno 24
1411
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة 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 je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

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