Ir al contenido
Odoo Menú
  • Identificarse
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • TPV para tiendas
    • TPV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en directo
    • eLearning
    Cadena de suministro
    • Inventario
    • Fabricación
    • PLM
    • Compra
    • Mantenimiento
    • Calidad
    Recursos Humanos
    • Empleados
    • Reclutamiento
    • Ausencias
    • Evaluación
    • Referencias
    • Flota
    Marketing
    • Marketing social
    • Marketing por correo electrónico
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyecto
    • Partes de horas
    • Servicio de campo
    • Servicio de asistencia
    • Planificación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Información
    • WhatsApp
    Aplicaciones de terceros Studio de Odoo Plataforma de Odoo Cloud
  • Industrias
    Comercio al por menor
    • Librería
    • Tienda de ropa
    • Tienda de muebles
    • Tienda de ultramarinos
    • Ferretería
    • Juguetería
    Alimentación y hostelería
    • Bar y taberna
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidor de bebidas
    • Hotel
    Inmueble
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión inmobiliaria
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Empresa contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Fabricación
    • Textil
    • Metal
    • Muebles
    • Alimentos
    • Brewery
    • Regalos de empresas
    Salud y bienestar
    • Club deportivo
    • Óptica
    • Gimnasio
    • Terapeutas
    • Farmacia
    • Peluquería
    Oficios
    • Handyman
    • Hardware y asistencia informática
    • Sistemas de energía solar
    • Zapatero
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin ánimo de lucro
    • Agencia de protección del medio ambiente
    • Alquiler de paneles publicitarios
    • Estudio fotográfico
    • Alquiler de bicicletas
    • Distribuidor de software
    Browse all Industries
  • Comunidad
    Aprender
    • Tutoriales
    • Documentación
    • Certificaciones
    • Formación
    • Blog
    • Podcast
    Potenciar la educación
    • Programa de formación
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtener el software
    • Descargar
    • Comparar ediciones
    • Versiones
    Colaborar
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Convertirse en partner
    • Services for Partners
    • Registrar tu empresa contable
    Obtener servicios
    • Encontrar un partner
    • Encontrar un asesor fiscal
    • Contacta con un experto
    • Servicios de implementación
    • Referencias de clientes
    • Ayuda
    • Actualizaciones
    GitHub YouTube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicitar una demostración
  • Precios
  • Ayuda

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

  • CRM
  • e-Commerce
  • Contabilidad
  • Inventario
  • PoS
  • Proyecto
  • MRP
All apps
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Ayuda

Define a Product with a Unique Key

Suscribirse

Reciba una notificación cuando haya actividad en esta publicación

Se marcó esta pregunta
purchasewarehousesproduct
3 Respuestas
12207 Vistas
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
Descartar
Avatar
rahul Hans
Autor Mejor respuesta

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
Descartar
rahul Hans
Autor

Thanks very much for your informative answers

Avatar
Temur
Mejor respuesta

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
Descartar
Avatar
Atchuthan - Technical Consultant, Sodexis Inc
Mejor respuesta

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
Descartar
¿Le interesa esta conversación? ¡Participe en ella!

Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.

Inscribirse
Publicaciones relacionadas Respuestas Vistas Actividad
I want it to bring me only the stores in which this product is available. Not all stores
warehouses product
Avatar
Avatar
1
jul 25
1187
ODOO COMMUNITY: Multiple Company with same IP address
warehouses product
Avatar
0
jul 24
1884
Last purchase date Resuelto
purchase product
Avatar
Avatar
2
sept 21
4653
Purchase Order and Product name Problem Resuelto
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
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento Odoo.sh
  • Ayuda
  • Actualizar
  • Desarrollos personalizados
  • Educación
  • Encontrar un asesor fiscal
  • Encontrar un partner
  • Convertirse en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contacta con nosotros
  • Puestos de trabajo
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Información legal • Privacidad
  • Seguridad
الْعَرَبيّة 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 es un conjunto de aplicaciones de código abierto que cubren todas las necesidades de tu empresa: CRM, comercio electrónico, contabilidad, inventario, punto de venta, gestión de proyectos, etc.

La propuesta única de valor de Odoo es ser muy fácil de usar y totalmente integrado.

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