Odoo 中文社区

    • 注册
    • 登录
    • 搜索
    • 版块
    • 标签
    • 热门
    • 用户
    • 群组

    Odoo中文社区可以通过以下两个域名访问:shine-it.net , odoo.net.cn

    由于系统升迁的原因,本论坛部分较早期的内容存在格式和链接损坏失效的问题,并非本论坛系统本身的缺陷,望谅解

    本社区没有维护任何QQ群讨论组,任何与本社区同名的QQ群讨论组的言论与本社区无关!

    开发人员可以登录gitter讨论组: http://gitter.im/odoo-china/Talk, 需要github账号

    如果您登录系统碰到问题,请在微信公众号留言:

    显示记录创建者姓名

    Odoo 开发与实施交流
    5
    8
    6806
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • Z
      zjxplq 最后由 编辑

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

      为了能够显示创建者姓名,需要在_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
      • digitalsatori
        digitalsatori 管理员 最后由 编辑

        操作方法不错,但是说明有误。
        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
          zjxplq 最后由 编辑

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

          1 条回复 最后回复 回复 引用 0
          • mrshelly
            mrshelly 最后由 编辑

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

            1 条回复 最后回复 回复 引用 0
            • digitalsatori
              digitalsatori 管理员 最后由 编辑

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

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

              1 条回复 最后回复 回复 引用 0
              • Joshua
                Joshua 管理员 最后由 编辑

                我也看不明白,校长的第二个办法,看了下源码,开始有点明白了
                就是根据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
                • wjfonhand
                  wjfonhand 最后由 编辑

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

                  GoodERP -- Odoo China fork

                  1 条回复 最后回复 回复 引用 0
                  • First post
                    Last post