Passa al contenuto
Odoo Menu
  • Accedi
  • Provalo gratis
  • App
    Finanze
    • Contabilità
    • Fatturazione
    • Note spese
    • Fogli di calcolo (BI)
    • Documenti
    • Firma
    Vendite
    • CRM
    • Vendite
    • Punto vendita Negozio
    • Punto vendita Ristorante
    • Abbonamenti
    • Noleggi
    Siti web
    • Configuratore sito web
    • E-commerce
    • Blog
    • Forum
    • Live chat
    • E-learning
    Supply chain
    • Magazzino
    • Produzione
    • PLM
    • Acquisti
    • Manutenzione
    • Qualità
    Risorse umane
    • Dipendenti
    • Assunzioni
    • Ferie
    • Valutazioni
    • Referral dipendenti
    • Parco veicoli
    Marketing
    • Social marketing
    • E-mail marketing
    • SMS marketing
    • Eventi
    • Marketing automation
    • Sondaggi
    Servizi
    • Progetti
    • Fogli ore
    • Assistenza sul campo
    • Helpdesk
    • Pianificazione
    • Appuntamenti
    Produttività
    • Comunicazioni
    • Approvazioni
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    App di terze parti Odoo Studio Piattaforma cloud Odoo
  • Settori
    Retail
    • Libreria
    • Negozio di abbigliamento
    • Negozio di arredamento
    • Alimentari
    • Ferramenta
    • Negozio di giocattoli
    Cibo e ospitalità
    • Bar e pub
    • Ristorante
    • Fast food
    • Pensione
    • Grossista di bevande
    • Hotel
    Agenzia immobiliare
    • Agenzia immobiliare
    • Studio di architettura
    • Edilizia
    • Gestione immobiliare
    • Impresa di giardinaggio
    • Associazione di proprietari immobiliari
    Consulenza
    • Società di contabilità
    • Partner Odoo
    • Agenzia di marketing
    • Studio legale
    • Selezione del personale
    • Audit e certificazione
    Produzione
    • Tessile
    • Metallo
    • Arredamenti
    • Alimentare
    • Birrificio
    • Ditta di regalistica aziendale
    Benessere e sport
    • Club sportivo
    • Negozio di ottica
    • Centro fitness
    • Centro benessere
    • Farmacia
    • Parrucchiere
    Commercio
    • Tuttofare
    • Hardware e assistenza IT
    • Ditta di installazione di pannelli solari
    • Calzolaio
    • Servizi di pulizia
    • Servizi di climatizzazione
    Altro
    • Organizzazione non profit
    • Ente per la tutela ambientale
    • Agenzia di cartellonistica pubblicitaria
    • Studio fotografico
    • Punto noleggio di biciclette
    • Rivenditore di software
    Carica tutti i settori
  • Community
    Apprendimento
    • Tutorial
    • Documentazione
    • Certificazioni 
    • Formazione
    • Blog
    • Podcast
    Potenzia la tua formazione
    • Programma educativo
    • Scale Up! Business Game
    • Visita Odoo
    Ottieni il software
    • Scarica
    • Versioni a confronto
    • Note di versione
    Collabora
    • Github
    • Forum
    • Eventi
    • Traduzioni
    • Diventa nostro partner
    • Servizi per partner
    • Registra la tua società di contabilità
    Ottieni servizi
    • Trova un partner
    • Trova un contabile
    • Incontra un esperto
    • Servizi di implementazione
    • Testimonianze dei clienti
    • Supporto
    • Aggiornamenti
    GitHub Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Richiedi una demo
  • Prezzi
  • Aiuto

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

  • CRM
  • e-Commerce
  • Contabilità
  • Magazzino
  • PoS
  • Progetti
  • MRP
All apps
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
Assistenza

Define a Product with a Unique Key

Iscriviti

Ricevi una notifica quando c'è un'attività per questo post

La domanda è stata contrassegnata
purchasewarehousesproduct
3 Risposte
12210 Visualizzazioni
Avatar
rahul Hans

Hi, 

I am new to OpenErp. But I am conversant with ERP and with the functional areas of a business. I am working with a retail company that sells accessories and items of clothing amongst other products.

We need to create a product with a unique key. On my attempt to create a product I found I was able to create more than one salable product with 

1. Same Name

2. Same EAN13 barcode

My questions are very basic and is related to products. More specifically to definition of products. 

I need to create a product with a unique bar code. In other words, once defined with a 13 digit bar code, it should no tbe possible to create another product with the same bar code. Ideally this should also happen in case of product name.

1. Is there any way to achieve this in OpenERP?

2. What is the approach that OpenErp uses in defining unique products?

3. Is there any way to define a field in OpenErp that can be unique. We should be able to use the field to search a product and the field should also be usable by a bar code scanner?

I hope my questions are clear. In case of any doubts, please do let me know.

An early response would be appreciated

 

 

 

 

 

0
Avatar
Abbandona
Avatar
rahul Hans
Autore Risposta migliore

Okay. First of all can thanks for your answer. 

I understand Sql constraints.

What are the exact differences between _constraints & @api_constraints? I can speculate on the differences 

A brief but reply would be most helpful. 

Also I tried searching for api constraints. Could not find anything useful. Can you point me in the right direction?

Thanks once again

1
Avatar
Abbandona
rahul Hans
Autore

Thanks very much for your informative answers

Avatar
Temur
Risposta migliore

There is several ways to achieve that, please check v8.0 documentation or v7.0 documentation selon your needs. possible options are "_constraints", "_sql_constraints" and "@api.constrains" (the last option is v8 speciphic and it replaces v7 _constraints, which is deprecated in v8 ). 

 

EXAMPLES:

  • _sql_constraints example of usage in "stock.py":

    _sql_constraints = [
            ('warehouse_name_uniq', 'unique(name, company_id)', 'The name of the warehouse must be unique per company!'),
            ('warehouse_code_uniq', 'unique(code, company_id)', 'The code of the warehouse must be unique per company!'),
        ]
  • @api.constrain example of usage in "event.py":

        @api.one
        @api.constrains('event_id', 'state', 'nb_register')
        def _check_seats_limit(self):
            if self.event_id.seats_max and \
                self.event_id.seats_available < (self.nb_register if self.state == 'draft' else 0):
                    raise Warning(_('No more available seats.'))
     
  • _constraints example of usage in "stock.py":

        def _check_uom(self, cr, uid, ids, context=None):
            for move in self.browse(cr, uid, ids, context=context):
                if move.product_id.uom_id.category_id.id != move.product_uom.category_id.id:
                    return False
            return True

        _constraints = [
            (_check_uom,
                'You try to move a product using a UoM that is not compatible with the UoM of the product moved. Please use an UoM in the same UoM category.',
                ['product_uom']),
        ]

 

The code in "_constraints" example above may be rewritten with "@api.constrains" as follows:

    @api.one
    @api.constrains('product_uom')
    def _check_uom(self):
        if self.product_id.uom_id.category_id.id != self.product_uom.category_id.id:
            raise Warning(_('You try to move a product using a UoM that is not compatible with the UoM of the product moved. Please use an UoM in the same UoM category.'))

 

_constraints and @api.constrains are the same concept and they allow to validate field in any sense (not only for uniqueness) using python function (as _check_uom - in examples above). _constraints is still supported but deprecated in v8, whereas @api.constrains makes part of new v8 api as its replacement

 

0
Avatar
Abbandona
Avatar
Atchuthan - Technical Consultant, Sodexis Inc
Risposta migliore

Constraints are applied only using ORM methods i.e. only in code and it does not affect the table whereas _sql_constraints set the rule at table level

In Odoo 7:
_sql_constraints and _constraints arguments were used

In Odoo 8:
_sql_constraints and @api.constraints arguments are used in v8.

 

0
Avatar
Abbandona
Ti stai godendo la conversazione? Non leggere soltanto, partecipa anche tu!

Crea un account oggi per scoprire funzionalità esclusive ed entrare a far parte della nostra fantastica community!

Registrati
Post correlati Risposte Visualizzazioni Attività
I want it to bring me only the stores in which this product is available. Not all stores
warehouses product
Avatar
Avatar
1
lug 25
1187
ODOO COMMUNITY: Multiple Company with same IP address
warehouses product
Avatar
0
lug 24
1889
Last purchase date Risolto
purchase product
Avatar
Avatar
2
set 21
4653
Purchase Order and Product name Problem Risolto
purchase product
Avatar
Avatar
2
mar 15
4804
Why does the purchase order allow products where Can be Purchased is false?
purchase v8 product
Avatar
Avatar
1
nov 24
4770
Community
  • Tutorial
  • Documentazione
  • Forum
Open source
  • Scarica
  • Github
  • Runbot
  • Traduzioni
Servizi
  • Hosting Odoo.sh
  • Supporto
  • Aggiornamenti
  • Sviluppi personalizzati
  • Formazione
  • Trova un contabile
  • Trova un partner
  • Diventa nostro partner
Chi siamo
  • La nostra azienda
  • Branding
  • Contattaci
  • Lavora con noi
  • Eventi
  • Podcast
  • Blog
  • Clienti
  • Note legali • Privacy
  • Sicurezza
الْعَرَبيّة 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 è un gestionale di applicazioni aziendali open source pensato per coprire tutte le esigenze della tua azienda: CRM, Vendite, E-commerce, Magazzino, Produzione, Fatturazione elettronica, Project Management e molto altro.

Il punto di forza di Odoo è quello di offrire un ecosistema unico di app facili da usare, intuitive e completamente integrate tra loro.

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