|
本帖最后由 文抄公 于 2015-9-9 21:53 编辑
Odoo(OpenERP)机制中,有两种方式来解决该问题,
一、使用_sql_constraints
按照 saleorder 的检查 ,复制 写了一个检查项
放在addone/product/product.py 的product_product 类中
_sql_constraints = [
('code_uniq', 'unique(default_code)', 'Code must be unique per Company!'),
]
测试了一下,没有成功,后来 总监提示 “可能是你没有重启服务以及更新模块所致..”
二、使用_constraints
参照 _check_ean_key 写了一个
def _check_default_code(self, cr, uid, ids, context=None):
result = 0
for product in self.read(cr, uid, ids, ['default_code'], context=context):
code=product['default_code']
other_product_ids = self.search(cr, uid, [('default_code', '=', code), ('id', '!=', product['id'])], context=context)
result=len(list(other_product_ids))
if result<1:
return True
else:
return False
_constraints = [(_check_ean_key, 'You provided an invalid "EAN13 Barcode" reference. You may use the "Internal Reference" field instead.', ['ean13']),
(_check_default_code, ' 内部单号重复 . 请重新输入.', ['default_code'])
]
_check_ean_key,是原有的,
(_check_default_code, ' 内部单号重复 . 请重新输入.', ['default_code']) 是加上的
经测试,输入重复的内部编号 ,提示内部单号重复 . 请重新输入.
---
by: 行云流水
|
|