跳转至内容
  • 版块
  • 标签
  • 热门
  • 用户
  • 群组
皮肤
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • 默认(Flatly)
  • 不使用皮肤
折叠

Odoo 中文社区

  1. 主页
  2. 版块
  3. Odoo 新手求助
  4. [已解决]在录入业务伙伴时,如何做才能让系统提示重复?

[已解决]在录入业务伙伴时,如何做才能让系统提示重复?

已定时 已固定 已锁定 已移动 Odoo 新手求助
12 帖子 3 发布者 7.9k 浏览
  • 从旧到新
  • 从新到旧
  • 最多赞同
登录后回复
此主题已被删除。只有拥有主题管理权限的用户可以查看。
  • L 离线
    L 离线
    lihaihe
    写于 最后由 编辑
    #1

    我在录入业务伙伴信息时,当业务伙伴名称重复时系统不会重复,请问如何修改在录入业务伙伴名称重复时,系统可以提示错误?和res_users中login名称不能重复一样!

    谢谢!

    按官方论坛的方法可以解决
    http://www.openerp.com/forum/topic18021.html

    1 条回复 最后回复
    0
    • L 离线
      L 离线
      lihaihe
      写于 最后由 编辑
      #2

      我在res_user里找到了相应的代码?但是修改后加入res_partner中,并重新更新了模块,可是并不起作用,请问还有其它地方需要修改的吗?

        _sql_constraints = [
              ('name_uniq', 'unique (name)', 'The name of the group must be unique !')
          ]

      1 条回复 最后回复
      0
      • JoshuaJ 离线
        JoshuaJ 离线
        Joshua 管理员
        写于 最后由 编辑
        #3

        _sql_constraints = [
                ('name_uniq', 'unique (name)', 'The name of the group must be unique !')
            ]
        不起作用。很有可能是因为你本来的name里面就有事重复的

        当添加_sql_constraints的时候,必须保证原始数据没有违反约束的,否则会添加不成功。

        【上海先安科技】(joshua AT openerp.cn),欢迎关注公众号:openerp_cn

        1 条回复 最后回复
        0
        • L 离线
          L 离线
          lihaihe
          写于 最后由 编辑
          #4

          谢谢joshua 的回复,按着你的提示我将所有的业务伙伴信息删除,再重新添加,但是还是不能控制重复提示,请问还有没有可能是其它的问题?

          1 条回复 最后回复
          0
          • JoshuaJ 离线
            JoshuaJ 离线
            Joshua 管理员
            写于 最后由 编辑
            #5
             <br /> _sql_constraints = [<br />&nbsp; &nbsp; &nbsp; &nbsp; (&#039;name_uniq&#039;, &#039;unique (name)&#039;, &#039;The name of the group must be unique !&#039;)<br />&nbsp; &nbsp; ]<br />
            


            这段代码看起来没什么问题
            你是写个新模块继承,还是直接在源代码上面改?
            更新完模块有没有重启服务器呢?

            【上海先安科技】(joshua AT openerp.cn),欢迎关注公众号:openerp_cn

            1 条回复 最后回复
            0
            • L 离线
              L 离线
              lihaihe
              写于 最后由 编辑
              #6

              您好,我是直接在原模块中进行的修改,我也新写了个简单的模块,不过还是不起作用!

              # -- 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()

              1 条回复 最后回复
              0
              • L 离线
                L 离线
                lihaihe
                写于 最后由 编辑
                #7

                我在官方论坛上,别人说这样可以实现,请问谁能帮我看一看,指导下?

                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()

                1 条回复 最后回复
                0
                • JoshuaJ 离线
                  JoshuaJ 离线
                  Joshua 管理员
                  写于 最后由 编辑
                  #8

                  [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

                  【上海先安科技】(joshua AT openerp.cn),欢迎关注公众号:openerp_cn

                  1 条回复 最后回复
                  0
                  • L 离线
                    L 离线
                    lihaihe
                    写于 最后由 编辑
                    #9

                    谢谢您的回复,采用继承的方法实现起来没有问题,但是我新写的模块,要想控制字段能否重复,难道需要再写一个模块,控制字段重复?

                    1 条回复 最后回复
                    0
                    • JoshuaJ 离线
                      JoshuaJ 离线
                      Joshua 管理员
                      写于 最后由 编辑
                      #10

                      哦,原来是另外一个问题新写的模块那个约束条件不生效, 😉

                      <br />&nbsp; &nbsp; _sql_constraints = [<br />&nbsp; &nbsp; &nbsp; &nbsp; (&#039;name_uniq&#039;, &#039;unique (name)&#039;, &#039;The name of the group must be unique !&#039;)<br />&nbsp; &nbsp; ]<br />
                      


                      这段代码看起来没有什么问题,
                      是不是你的数据库里面已经有了‘name_uniq’这个约束条件?
                      1.试试直接在数据库里面测试下
                      2.或者改个名字
                      3.看看log

                      【上海先安科技】(joshua AT openerp.cn),欢迎关注公众号:openerp_cn

                      1 条回复 最后回复
                      0
                      • mrshellyM 离线
                        mrshellyM 离线
                        mrshelly
                        写于 最后由 编辑
                        #11

                        官方的方法 不就是 Joshua 的方法么???????

                        1 条回复 最后回复
                        0

                        • 登录

                        • 没有帐号? 注册

                        • 登录或注册以进行搜索。
                        • 第一个帖子
                          最后一个帖子
                        0
                        • 版块
                        • 标签
                        • 热门
                        • 用户
                        • 群组