跳至內容
選單
此問題已被標幟
7 回覆
7696 瀏覽次數

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

頭像
捨棄
最佳答案

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

頭像
捨棄
作者

ur a master alot of thanks

最佳答案

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

頭像
捨棄
最佳答案

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

頭像
捨棄
作者

many thanks

作者 最佳答案

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

頭像
捨棄

I updated my answer