Ir al contenido
Odoo Menú
  • Iniciar sesión
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • PdV para tiendas
    • PdV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en vivo
    • eLearning
    Cadena de suministro
    • Inventario
    • Manufactura
    • PLM
    • Compras
    • Mantenimiento
    • Calidad
    Recursos humanos
    • Empleados
    • Reclutamiento
    • Vacaciones
    • Evaluaciones
    • Referencias
    • Flotilla
    Marketing
    • Redes sociales
    • Marketing por correo
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyectos
    • Registro de horas
    • Servicio externo
    • Soporte al cliente
    • Planeación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Artículos
    • WhatsApp
    Aplicaciones externas Studio de Odoo Plataforma de Odoo en la nube
  • Industrias
    Venta minorista
    • Librería
    • Tienda de ropa
    • Mueblería
    • Tienda de abarrotes
    • Ferretería
    • Juguetería
    Alimentos y hospitalidad
    • Bar y pub
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidora de bebidas
    • Hotel
    Bienes inmuebles
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión de bienes inmuebles
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Firma contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Manufactura
    • Textil
    • Metal
    • Muebles
    • Comida
    • Cervecería
    • Regalos corporativos
    Salud y ejercicio
    • Club deportivo
    • Óptica
    • Gimnasio
    • Especialistas en bienestar
    • Farmacia
    • Peluquería
    Trades
    • Personal de mantenimiento
    • Hardware y soporte de TI
    • Sistemas de energía solar
    • Zapateros y fabricantes de calzado
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin fines de lucro
    • Agencia para la protección del medio ambiente
    • Alquiler de anuncios publicitarios
    • Fotografía
    • Alquiler de bicicletas
    • Distribuidor de software
    Descubre todas las industrias
  • Odoo Community
    Aprende
    • Tutoriales
    • Documentación
    • Certificaciones
    • Capacitación
    • Blog
    • Podcast
    Fortalece la educación
    • Programa educativo
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtén el software
    • Descargar
    • Compara ediciones
    • Versiones
    Colabora
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Conviértete en partner
    • Servicios para partners
    • Registra tu firma contable
    Obtén servicios
    • Encuentra un partner
    • Encuentra un contador
    • Contacta a un consultor
    • Servicios de implementación
    • Referencias de clientes
    • Soporte
    • Actualizaciones
    GitHub YouTube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicita 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
  • Proyectos
  • 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

Bulk import via CSV import generates issues with EAN validation

Suscribirse

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

Se marcó esta pregunta
importcsvean13odooV8ValidationError
1 Responder
6018 Vistas
Avatar
E.M.

Hi,

I have programmed the following module to automatically assign an EAN13 code to every new product (see code below).

The module works fine, both when you manually add products and when you import ONE product from CSV.

However, when trying to import a set of products (even a small number like 10) you get the following message:

Unknown error during import: <class 'openerp.exceptions.ValidationError'>: ('ValidateError', u'Field(s) `ean13` failed against a constraint: EAN13 code not valid. Use "Internal reference" field instead') in row number 5
Resolve other errors first

Row number varies from execution to execution. So it seems that the same code is being tried to be used twice (maybe CSV loads rows in paralel leading to a race condition or to the sequence to assign the same value).

What is wrong with the customized EAN13 method below? How should it be programmed to support CSV import too? Is there any way to make that code/transaction atomic?

EAN13 validation code:

# -*- coding: utf-8 -*-
from openerp import models, fields, api
 
# DESCRIPTION:
# Class EanAuto generates automatically EAN codes for new created products
# This ensures that every new product has its own unique EAN code
# Sequence is defined in XML file, and it is originally intended to use internal EAN13 codes
# although it can be used for any other codes.
# NOTES:
# It redefines create method adding additional required steps to retrieve a new EAN code
# to the product.
# If product is already provided with an EAN code it will be respected.
# If EAN code is used it will look for the next free value, so no duplicates are generated
# during creation through this routine.
# EAN duplicates are not checked elsewhere, at least not by this module.

class EanAuto ( models.Model ):
_inherit = 'product.template'

@api.model
def create(self, vals):

# Tests if EAN13 has been provided, if so do nothing, otherwise look for free EAN13 code
if not vals.get('ean13'):
while True:
# Gets next value for custom EAN13 working out checksum digit
seq_id = self.env['ir.sequence'].search([('code','=','ean.code')])
ean_seq = seq_id._next()
ean_check_digit = 10 - (( sum(map(int, ean_seq[0::2])) + 3*sum(map(int, ean_seq[1::2])) ) % 10 )
ean_code = str(ean_seq) + str(ean_check_digit)

# Checks that there is no such EAN in use
prod_count = self.env['product.product'].search_count([('ean13','=',ean_code)])
if prod_count == 0:
# EAN is not in use, so proceed
vals.update({'ean13': ean_code})
break

# Creates the product using standard create method
new_product_template = super(EanAuto, self).create(vals)

# TEST TEST try to retrieve product_id of the new generated product
#new_product_template.update({'ean13': new_product_template.product_id})

return new_product_template

Sequence is defined as follows:

# cat sequence.xml
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<record id="ean_code_sequence" model="ir.sequence.type">
<field name="name">EAN Code Sequence</field>
<field name="code">ean.code</field>
</record>
<record id="automatic_ean" model="ir.sequence">
<field name="name">Automatic EAN13</field>
<field name="code">ean.code</field>
<field name="prefix">291</field>
<field name="padding">9</field>
</record>
</data>
</openerp>

1
Avatar
Descartar
Avatar
E.M.
Autor Mejor respuesta

I finally found that there was a bug in the EAN sequence code. Check digit can be 10 which is actually a 0, and if after check digit generation fixes the issue.

0
Avatar
Descartar
¿Le interesa esta conversación? ¡Participe en ella!

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

Registrarse
Publicaciones relacionadas Respuestas Vistas Actividad
Odoo version 8: How to fix create products and/or pricelists via import?
import csv odooV8
Avatar
Avatar
1
jun 17
3682
How can i mass import products with attributes values from a CSV file on v8? Resuelto
import csv odooV8
Avatar
Avatar
Avatar
2
oct 23
13460
How can I import a csv file to an odoo 8 automatically? Resuelto
import automatic csv odooV8
Avatar
Avatar
1
jun 19
10316
To Import data in hr_attendnace?
hr import csv attendance odooV8
Avatar
Avatar
Avatar
Avatar
3
abr 18
5008
Allow CSV import only for Administrator user, how?
import csv permission administrator odooV8
Avatar
Avatar
Avatar
2
mar 16
6618
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento en Odoo.sh
  • Soporte
  • Actualizaciones del software
  • Desarrollos personalizados
  • Educación
  • Encuentra un contador
  • Encuentra un partner
  • Conviértete en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contáctanos
  • Empleos
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • 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 estar 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