[已解决]在录入业务伙伴时,如何做才能让系统提示重复?
-
我在录入业务伙伴信息时,当业务伙伴名称重复时系统不会重复,请问如何修改在录入业务伙伴名称重复时,系统可以提示错误?和res_users中login名称不能重复一样!
谢谢!
按官方论坛的方法可以解决
http://www.openerp.com/forum/topic18021.html -
您好,我是直接在原模块中进行的修改,我也新写了个简单的模块,不过还是不起作用!
# -- encoding: utf-8 --
from osv.orm import except_orm
from osv import osv, fields
class module_tpl(osv.osv):
_name = 'module.tpl'
_description = 'module template'
_columns = {
'name': fields.char('Sn Reference', size=64, required=True, select=True),
'state': fields.selection([
('draft', 'Dtatf'),
('done', 'Done'),
('cancel', 'Cancelled')
], 'Sn State', readonly=True, help="SN state.", select=True)
}
_sql_constraints = [
('name_uniq', 'unique (name)', 'The name of the group must be unique !')
]
module_tpl() -
我在官方论坛上,别人说这样可以实现,请问谁能帮我看一看,指导下?
Add this class in your module ,not the existing module. one more thing never edit the existing module,just inherit the features in your own module and add the new features.
class res_partner(osv.osv):
_inherit = 'res.partner'
_sql_constraints = [
('name', 'UNIQUE (name)', 'The name of the partner must be unique !')
]
res_partner() -
[quote author=lihaihe link=topic=2196.msg6997#msg6997 date=1287191234]
您好,我是直接在原模块中进行的修改,我也新写了个简单的模块,不过还是不起作用!
# -- encoding: utf-8 --
from osv.orm import except_orm
from osv import osv, fields
class module_tpl(osv.osv):
_name = 'module.tpl'
_description = 'module template'
_columns = {
'name': fields.char('Sn Reference', size=64, required=True, select=True),
'state': fields.selection([
('draft', 'Dtatf'),
('done', 'Done'),
('cancel', 'Cancelled')
], 'Sn State', readonly=True, help="SN state.", select=True)
}
_sql_constraints = [
('name_uniq', 'unique (name)', 'The name of the group must be unique !')
]
module_tpl()
[/quote]
你这段代码是写了个新的object,为什么不直接继承res.partner呢?
[quote author=lihaihe link=topic=2196.msg6998#msg6998 date=1287193889]
我在官方论坛上,别人说这样可以实现,请问谁能帮我看一看,指导下?
Add this class in your module ,not the existing module. one more thing never edit the existing module,just inherit the features in your own module and add the new features.
class res_partner(osv.osv):
_inherit = 'res.partner'
_sql_constraints = [
('name', 'UNIQUE (name)', 'The name of the partner must be unique !')
]
res_partner()
[/quote]
别人的回复也说了,写新模块继承比直接改代码来得安全,他这段就是继承了partner并且将一个约束条件添加进去
[b]这里有个简单例子,是关于产品编号不能重复的,可以参考下[/b]
http://openerp-china.org/wiki/index.php?title=Model -
哦,原来是另外一个问题新写的模块那个约束条件不生效,
<br /> _sql_constraints = [<br /> ('name_uniq', 'unique (name)', 'The name of the group must be unique !')<br /> ]<br />
这段代码看起来没有什么问题,
是不是你的数据库里面已经有了‘name_uniq’这个约束条件?
1.试试直接在数据库里面测试下
2.或者改个名字
3.看看log