Se rendre au contenu
Menu
Cette question a été signalée
7 Réponses
7681 Vues

how to add Unique barcode number on product in order to avoid having 2 different product with the same barcode number

Avatar
Ignorer
Meilleure réponse

product->product.py

find class product.product add following code line no 588

_sql_constraints = [
        ('unique_product_barcode', 'unique(ean13)', 'Product Bar-Code  Must Be Unique .'),
     ]

upgrade this module Restart your server Settings->Installed Modules->find Products & Pricelists upgrade

OR

if you want to create separate module for this one follow this step

create one folder name should like

unique_product_barcode

inside this folder add __init__.py , __openerp__.py and yourmodule.py file

1) __init__.py

import unique_product

2) __openerp__.py

{
    'name': 'Product Unique Barcode',
    'version': '1.1',
    'author': 'Husam',
    'category': 'Sales Management',
    'depends': ['base', 'process', 'decimal_precision', 'mail'],
    'description': """
        Unique Barcode of Product 
    """,
    'data': [],
    'installable': True,
    'auto_install': False,     }

3) unique_product.py

from openerp.osv import fields,osv

class product_product(osv.osv):
    _inherit = 'product.product'
   _sql_constraints = [
        ('unique_product_barcode', 'unique(ean13)', 'Product Bar-Code  Must Be Unique .'),
     ]

product_product()

Restart Your OpenERP Go to Settings->Install Modules->find unique_product_barcode and install

Avatar
Ignorer
Auteur

ur a master alot of thanks

Meilleure réponse

I have added these modules, but am unable to view it when updating the module list?

Avatar
Ignorer
Meilleure réponse

Add Unique Constraints in python file.

Create custom module

For Example create addons/barcode_unique Module

1) __init__.py file

import product

2) __openerp__.py file

{
    "name" :        "Product Barcode Unique",
    "version" :     "0.1",
    "category":     '',
    "description" : "Product",
    "author" :      "ERP",
    "depends" :     ["product"],
    "init_xml" :    [],
    "update_xml" :  [],
    "data": [],                         
    "css": [],                                
    "installable" : True,
    "active" :      False,

}

1) Create Product.py File add the below code

class product_product(osv.osv):
    _inherit = "product.product"

    _sql_constraints = [
            ('barcode_uniq', 'unique(ean13)', 'Bar-code  No must be unique !'),
         ]

Create the above Module and Install in openerp

Avatar
Ignorer
Auteur

many thanks

Auteur Meilleure réponse

Thank you so much for your reply, but which python file, can you provide path?

Avatar
Ignorer

I updated my answer