Skip to content
  • Categories
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • 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

  • Default (Flatly)
  • No Skin
Collapse

Odoo 中文社区

  1. Home
  2. Categories
  3. Odoo 新手求助
  4. ondelete='restrict'

ondelete='restrict'

Scheduled Pinned Locked Moved Odoo 新手求助
8 Posts 4 Posters 2.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hui
    wrote on last edited by hui
    #1

    有一个模型是account.payment.term,这里面存储的基础数据,为了防止误删,另一个模型中引用这个模型的字段设置了ondelete属性,如下,但是没效果啊?是对于已经使用了的值没有效果。

    这个属性使用有什么条件限制吗?
    这个属性只对m2o字段有效,m2m字段如何实现相同的效果?

    property_supplier_payment_term_id = fields.Many2one('account.payment.term', company_dependent=True,string='Payment Terms',help="This payment term will be used instead of the default one for purchase orders and vendor bills",                                                oldname="property_supplier_payment_term", ondelete='restrict')
    
    
    萧 1 Reply Last reply
    0
    • G Offline
      G Offline
      ghotiv
      wrote on last edited by
      #2

      数据库表的触发器 或者重写删除方法吧

      H 1 Reply Last reply
      0
      • 萧 Offline
        萧 Offline
        萧云飞
        replied to hui on last edited by
        #3

        @1234567 在 ondelete='restrict' 中说:

        这个属性使用有什么条件限制吗

        这个属性只对many2one字段有效果,m2m字段不能使用,但m2m会建立 中间表,你在中间表的字段中,再使用这个属性,就可以变向解决

        H 1 Reply Last reply
        0
        • H Offline
          H Offline
          hui
          replied to ghotiv on last edited by
          #4

          @ghotiv 数据库表的触发器 或 重写unlink方法或许可以解决。这个属性为啥没起作用呢?

          1 Reply Last reply
          0
          • H Offline
            H Offline
            hui
            replied to 萧云飞 on last edited by
            #5

            @萧云飞
            我这个字段就是m2o的,但是没有起作用啊?

            1 Reply Last reply
            0
            • digitalsatoriD Offline
              digitalsatoriD Offline
              digitalsatori 管理员
              wrote on last edited by
              #6

              ondelete属性设置,实际上就是在数据库上创建外键约束。
              而你所针对的字段指定了company_dependent,所以该字段不再是一个普通的Many2one字段,而是一个compute 字段,其值也保存在另一个表中ir.property。参见这里
              所以你对它指定外键约束就没有作用了。

              【上海先安科技】(tony AT openerp.cn)

              H 1 Reply Last reply
              0
              • H Offline
                H Offline
                hui
                replied to digitalsatori on last edited by hui
                #7

                @digitalsatori

                这个字段指定了company_dependent,所以该字段不再是一个普通的Many2one字段,而是一个compute 字段,其值也保存在另一个表中ir.property。

                这个变成compute字段也是要存储的啊,是因为主要属性company_dependent,所以值是存储在ir.property中吗?那这种限制是怎么规定的,比如这个字段中,这两个属性相当于互斥的。怎么知道属性优先级的?

                property字段是compute字段吗?

                1 Reply Last reply
                0
                • digitalsatoriD Offline
                  digitalsatoriD Offline
                  digitalsatori 管理员
                  wrote on last edited by
                  #8

                  property字段就是一个函数字段,其读取和存储是通过函数来完成的。
                  ondelete属性是一个数据库层面的constraint, 你可以直接在数据库表上通过SQL来创建这个外键约束,现在这个对应的数据库字段都没有,怎么去创建这个约束。

                  【上海先安科技】(tony AT openerp.cn)

                  1 Reply Last reply
                  0

                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Tags
                  • Popular
                  • Users
                  • Groups