Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Validations
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Food & Hospitality
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Maison d’hôtes
    • Distributeur de boissons
    • Hôtel
    Immobilier
    • Agence immobilière
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consultance
    • Cabinet d'expertise comptable
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Métal
    • Meubles
    • Alimentation
    • Brewery
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Trades
    • Bricoleur
    • Matériel informatique et support
    • Systèmes photovoltaïques
    • Cordonnier
    • Services de nettoyage
    • Services CVC
    Autres
    • Organisation à but non lucratif
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Browse all Industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenez partenaire
    • Services for Partners
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide

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

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

Automation Help to prevent Client Reference duplicates.

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
helpsales.orderautomationv15
2 Réponses
4546 Vues
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
Ignorer
Avatar
Alex Ashcroft
Auteur Meilleure réponse

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
Ignorer
Avatar
Bhavin Patel
Meilleure réponse

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
Ignorer
Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Publications associées Réponses Vues Activité
How To ensure that a user only sees their default warehouse in inventory in Odoo 15
help v15
Avatar
Avatar
Avatar
2
juil. 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
mai 23
3033
Tooltips wont show up ODOO15 Résolu
help tooltip v15
Avatar
Avatar
1
févr. 25
3938
Create a sales order line via automation
sales.order automation salesorderlines
Avatar
Avatar
2
juin 24
2048
Odoo 15 composed product
sales.order product.template v15
Avatar
0
févr. 24
1410
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenez partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة 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 est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

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