Odoo中文网|Odoo实施培训

 找回密码
 立即注册
搜索
热搜: Odoo OpenERP 实施
查看: 6051|回复: 0
打印 上一主题 下一主题

Odoo中产品判断内部编号唯一处理

[复制链接]

17

主题

19

帖子

75

积分

注册会员

Rank: 2

积分
75
跳转到指定楼层
楼主
发表于 2015-9-9 21:52:42 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 文抄公 于 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: 行云流水





回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|技术支持|开发手册|Odoo中文网-远鼎旗下odoo培训网站 ( 苏ICP备15039516号 )

GMT+8, 2024-4-26 03:54 , Processed in 0.011318 second(s), 9 queries , Xcache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表