跳转至内容
  • 版块
  • 标签
  • 热门
  • 用户
  • 群组
皮肤
  • 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 开发与实施交流
8 帖子 5 发布者 7.1k 浏览
  • 从旧到新
  • 从新到旧
  • 最多赞同
登录后回复
此主题已被删除。只有拥有主题管理权限的用户可以查看。
  • Z 离线
    Z 离线
    zjxplq
    写于 最后由 编辑
    #1

    有时创建一个记录时需要把创建者的姓名显示出来,下面说明操作方法:

    为了能够显示创建者姓名,需要在_columns中显式的定义create_uid,代码如下:

    class demo(osv.osv):
        _name = 'demo.demo'
        _description = doc
        _columns = {
                'create_uid':  fields.many2one('res.users', 'Creator', readonly=True),
                'name': fields.char('名称',size=20, required=True),
                }

    demo()

    然后在视图中如下定义:
         
            <record model="ir.ui.view" id="demo_demo_tree_view">
                <field name="name">demo.demo.tree</field>
                <field name="model">demo.demo</field>
                <field name="type">tree</field>
                <field name="arch" type="xml">
                    <tree string="string">
                        <field name="name" select="1"/>
                        <field name="create_uid" readonly="1"/>
                    </tree>
                </field>
            </record>
           
            <record model="ir.ui.view" id="demo_demo_form_view">
                <field name="name">demo.demo.form</field>
                <field name="model">demo.demo</field>
                <field name="type">form</field>
                <field name="arch" type="xml">
                    <form string="string">
                        <field name="name"/>
                    </form>
                </field>
            </record>

    如果修改后osv与视图后,需重启服务器

    1 条回复 最后回复
    0
    • digitalsatoriD 离线
      digitalsatoriD 离线
      digitalsatori 管理员
      写于 最后由 编辑
      #2

      操作方法不错,但是说明有误。
      create_uid 不是osv类的创建者,
      OpenERP一般情况下(当osv类的_log_accesss属性为True时,默认为True)自动为osv类创建create_uid, write_uid, create_date, write_date四个字段,分别用来[b]记录创建一条记录或(Resource[/b])时的用户id(create_uid), 创建时间(create_date),[b]修改一条记录(resource)[/b]时的修改用户id(write_id),修改时间(write_date)
      比如,用户id为10的Tony创建了一个销售订单SO01那么这个SO01的creat_uid就是10(对于用户tony),如果之后小王(uid:5)修改了这张订单,那么小张的uid就会记录到这个订单的write_uid中,创建和修改的时间分别记录到create_date和write_date.

      要显示这个信息,zjxplq 给出了一个不错的方法。还有一个方法就是使用perm_read方法,比如:

      self.perm_read(cr, uid, [5,6])
      

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

      1 条回复 最后回复
      0
      • Z 离线
        Z 离线
        zjxplq
        写于 最后由 编辑
        #3

        谢谢指正。这个方法其实在document模块中有应用。然后是shelly指导下完成的。感谢shelly

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

          我一直试着弄懂 校长的回复 与 问题的相关性.... 😄

          1 条回复 最后回复
          0
          • digitalsatoriD 离线
            digitalsatoriD 离线
            digitalsatori 管理员
            写于 最后由 编辑
            #5

            我也搞不懂。所以发贴者请尽量保持原文,修改的部分要做一下说明,多谢。

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

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

              我也看不明白,校长的第二个办法,看了下源码,开始有点明白了
              就是根据id找到相应的创建,修改等信息

              &nbsp; &nbsp; <br />&nbsp; &nbsp; def perm_read(self, cr, user, ids, context=None, details=True):<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; Returns some metadata about the given records.<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; :param details: if True, \*_uid fields are replaced with the name of the user<br />&nbsp; &nbsp; &nbsp; &nbsp; :return: list of ownership dictionaries for each requested record<br />&nbsp; &nbsp; &nbsp; &nbsp; :rtype: list of dictionaries with the following keys:<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; * id: object id<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; * create_uid: user who created the record<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; * create_date: date when the record was created<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; * write_uid: last user who changed the record<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; * write_date: date of the last change to the record<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; * xmlid: XML ID to use to refer to this record (if there is one), in format ``module.name``<br />&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;<br />......................<br />
              

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

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

                界面上那个 view log的按钮就是调用的 perm_read

                GoodERP -- Odoo China fork

                1 条回复 最后回复
                0

                • 登录

                • 没有帐号? 注册

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