odoo14里面的用户登录log记录
一、继承userlog,添加字段
# -*- coding: utf-8 -*- from odoo import models, fields, api from odoo.http import request class ResUsersLog(models.Model): _inherit = 'res.users.log' ip = fields.Char('IP', readonly=True) location = fields.Char('Location', readonly=True) user_agent = fields.Char('User Agent', readonly=True) class Users(models.Model): _inherit = 'res.users' @api.model def _update_last_login(self):
"""继承记录登录log""" self.env['res.users.log'].create({ 'ip': request.httprequest.remote_addr, 'user_agent': request.httprequest.user_agent.string })
第二步、在xml里面继承视图修改
<record id="view_users_log_form" model="ir.ui.view"> <field name="name">res.users.log.form</field> <field name="model">res.users</field> <field name="inherit_id" ref="base.view_users_form"/> <field name="arch" type="xml"> <xpath expr="//notebook" position="inside"> <page string="Users Log"> <field name="log_ids" readonly="True"> <tree create="false"> <field name="ip"/> <field name="location"/> <field name="user_agent"/> <field name="create_date"/> </tree> </field> </page> </xpath> </field> </record>
最后效果图
心有猛虎,细嗅蔷薇