Siirry sisältöön
Odoo Menu
  • Kirjaudu sisään
  • Kokeile ilmaiseksi
  • Sovellukset
    Talous
    • Kirjanpito
    • Laskutus
    • Kulut
    • Datataulukot (BI)
    • Asiakirjat
    • Allekirjoita
    Myynti
    • CRM
    • Myynti
    • Kassajärjestelmä myymälään
    • Kassajärjestelmä ravintolaan
    • Tilaukset
    • Vuokraus
    Verkkosivut
    • Verkkosivun Rakennustyökalu
    • Verkkokauppa
    • Blogi
    • Foorumi
    • Livechat
    • Verkko-oppiminen
    Toimitusketju
    • Varastointi
    • Tuotanto
    • Tuotteen elinkaaren hallinta (PLM)
    • Ostot
    • Huolto
    • Laatu
    Henkilöstöhallinto
    • Työntekijät
    • Rekrytointi
    • Vapaat
    • Arvioinnit
    • Suositukset
    • Kuljetuskalusto
    Markkinointi
    • Somemarkkinointi
    • Sähköpostimarkkinointi
    • Tekstiviestimarkkinointi
    • Tapahtumat
    • Markkinoinnin automaatio
    • Kyselyt
    Palvelut
    • Projekti
    • Työaikakirjaukset
    • Kenttähuolto
    • Asiakaspalvelu
    • Suunnittelu
    • Ajanvaraukset
    Tuottavuus
    • Viestintä
    • Hyväksynnät
    • IoT
    • IP-puhe
    • Tietokirjasto
    • WhatsApp
    Kolmannen osapuolen sovellukset Odoo-Studio Odoo-Pilvialusta
  • Toimialat
    Vähittäiskauppa
    • Kirjakauppa
    • Vaatekauppa
    • Huonekaluliike
    • Ruokakauppa
    • Laitteistokauppa
    • Lelukauppa
    Ruoka & Majoitus
    • Baari ja Pubi
    • Ravintola
    • Pikaruoka
    • Majatalo
    • Juomien jakelija
    • Hotelli
    Kiinteistöt
    • Kiinteistönvälitystoimisto
    • Arkkitehtitoimisto
    • Rakentaminen
    • Kiinteistönhallinta
    • Puutarhanhoito
    • Kiinteistön omistajien yhdistys
    Konsultointi
    • Tilitoimisto
    • Odoo-kumppani
    • Markkinointitoimisto
    • Lakitoimisto
    • Osaajahankinta
    • Tilintarkastus & sertifiointi
    Tuotanto
    • Tekstiili
    • Metalli
    • Huonekalut
    • Ruoka
    • Panimo
    • Yrityslahjat
    Terveys & Liikunta
    • Urheiluseura
    • Silmälasiliike
    • Kuntokeskus
    • Hyvinvointialan ammattilaiset
    • Apteekki
    • Kampaamo
    Kaupat
    • Yleismies
    • IT-laitteisto & Tuki
    • Aurinkoenergiajärjestelmät
    • Suutari
    • Siivouspalvelut
    • LVI-palvelut
    Muut
    • Voittoa tavoittelematon järjestö
    • Ympäristötoimisto
    • Mainostaulujen vuokraus  
    • Valokuvaus
    • Leasing-pyörät
    • Ohjelmistojen jälleenmyyjä
    Selaa kaikkia toimialoja
  • Yhteisö
    Opi
    • Kurssit
    • Dokumentaatio
    • Todistukset
    • Koulutus
    • Blogi
    • Podcast
    Kannusta kouluttautumaan
    • Koulutusohjelmat
    • Scale Up! Liiketoimintapeli
    • Vieraile Odoolla
    Hanki ohjelmisto
    • Lataa
    • Vertaile versioita
    • Julkaisut
    Tee yhteistyötä
    • Github
    • Foorumi
    • Tapahtumat
    • Käännökset
    • Ryhdy kumppaniksi
    • Kumppanipalvelut
    • Rekisteröi tilitoimistosi
    Hanki palveluja
    • Löydä kumppani
    • Löydä kirjanpitäjä
    • Varaa asiantuntijatapaaminen
    • Implementaatiopalvelut
    • Asiakasreferenssit
    • Tuki
    • Versionkorotukset
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Varaa demo
  • Hinnoittelu
  • Asiakaspalvelu

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

  • CRM
  • e-Commerce
  • Kirjanpito
  • Varastointi
  • PoS
  • Projekti
  • MRP
All apps
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Kaikki kirjoitukset Ihmiset Merkit
Tunnisteet (Näytä kaikki)
odoo accounting v14 pos v15
Tietoa tästä foorumista
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Kaikki kirjoitukset Ihmiset Merkit
Tunnisteet (Näytä kaikki)
odoo accounting v14 pos v15
Tietoa tästä foorumista
Apua

Automation Help to prevent Client Reference duplicates.

Tilaa

Saat ilmoituksen, kun tähän viestiin ilmaantuu aktiviteettia

Tämä kysymys on merkitty
helpsales.orderautomationv15
2 Vastaukset
4553 Näkymät
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
Hylkää
Avatar
Alex Ashcroft
Tekijä Paras vastaus

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
Hylkää
Avatar
Bhavin Patel
Paras vastaus

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
Hylkää
Nautitko keskustelusta? Älä vain lue, vaan osallistu!

Luo tili jo tänään nauttiaksesi yksinoikeusominaisuuksista ja osallistuaksesi mahtavaan yhteisöömme!

Rekisteröidy
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
How To ensure that a user only sees their default warehouse in inventory in Odoo 15
help v15
Avatar
Avatar
Avatar
2
heinäk. 23
3482
I'm having trouble displaying a message in the purchase template based on a boolean field (when true)
help v15
Avatar
Avatar
1
toukok. 23
3034
Tooltips wont show up ODOO15 Ratkaistu
help tooltip v15
Avatar
Avatar
1
helmik. 25
3941
Create a sales order line via automation
sales.order automation salesorderlines
Avatar
Avatar
2
kesäk. 24
2051
Odoo 15 composed product
sales.order product.template v15
Avatar
0
helmik. 24
1410
Yhteisö
  • Kurssit
  • Dokumentaatio
  • Foorumi
Avoin lähdekoodi
  • Lataa
  • Github
  • Runbot
  • Käännökset
Palvelut
  • Odoo.sh hosting
  • Tuki
  • Versionkorotus
  • Räätälöidyt kehitykset
  • Koulutus
  • Löydä kirjanpitäjä
  • Löydä kumppani
  • Ryhdy kumppaniksi
Meistä
  • Yrityksemme
  • Tavaramerkki
  • Ota yhteyttä
  • Työpaikat
  • Tapahtumat
  • Podcast
  • Blogi
  • Asiakkaat
  • Oikeudellinen ilmoitus • Yksityisyys
  • Tietoturva
الْعَرَبيّة 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 on kokoelma avoimen lähdekoodin yrityssovelluksia, jotka kattavat kaikki yrityksesi tarpeet: asiakkuudenhallinta eli CRM, verkkokauppa, kirjanpito, varastointi, kassajärjestelmä, projektinhallinta, jne.

Odoon uniikki arvolupaus on olla samanaikaisesti erittäin helppokäyttöinen ja täysin integroitu.

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