06 显示每条记录的显示名称(学Odoo,就得Do)

11 篇文章 2 订阅
7 篇文章 0 订阅

截止到目前,我们Hospital模块的Patient数据显示在Form上有点奇怪,就是在标题栏位显示出来的是Odoo保存的这条记录的自动编号(hospital.patient,1),这个就不太友好和直观了。

我们通常的做法是显示病人的姓名,或者说显示名称,因为中国公司里面外国人越来越多,有的人证件上的名字又20个字符那么长,但是他们通常用简称,像Odoo这样的系统就很好的提供了这种支持, 首先要升级一下patient.py代码,增加一个patient_disp_name并赋给Odoo的一个系统字段_rec_name,该字段负责显示Form的标题栏

# -*- coding: utf-8 -*-

from odoo import models, fields

class HospitalPatient(models.Model):
    _name = 'hospital.patient'
    _description = 'Patient Record'
    _rec_name = 'patient_disp_name'

    patient_name = fields.Char(string='Name', required=True);  # 必填字段
    patient_age = fields.Integer(string='Age');
    notes = fields.Text(string='Notes');
    image = fields.Binary(string='Image');
    patient_disp_name = fields.Char(string='Patient Display Name'); # patient在标题栏的显示信息

然后把新字段添加到Form配置,我们直接把patient_disp_name放在patient_name下面了

<!-- Patient Form -->
    <record id="patient_form" model="ir.ui.view">
        <field name="name">hospital.patient.form</field>
        <field name="model">hospital.patient</field>
        <field name="arch" type="xml">
            <form string="Patients">
                <sheet>
                    <group>
                        <group>
                            <field name="patient_name"/>
                            <field name="patient_disp_name"/>
                        </group>
                        <group>
                            <field name="patient_age"/>
                        </group>
                        <group>
                            <field name="notes"/>
                            <field name="image"/>
                        </group>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

怎么更新和升级hospital模块,我们在前面的章节已经讲了,这里就不再浪费笔墨了,看一下效果:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值