本文介绍了连接名字和姓氏,并在odoo中填写名称字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有包含三个字段的模块•姓名•名•姓当用户按保存时名字和姓氏将串联并显示在名称字段中.名称字段必须处于只读模式.
I have module which has three fields•name•first name•last nameWhen a user press saveThe first name and last name will concatenate and displayed in name field.Name Field must be in read only mode.
def onchange_name(self, cr, uid, ids, firstname, lastname, context=None):
value = {'fullname' : True}
if firstname and lastname:
value['fullname'] = firstname + " " +lastname
return {'value': value}
<field name="fullname" readonly="True" on_change="onchange_fullname(fullname,context)"/>
<field name="firstname" string="First name" on_change="onchange_name(firstname,lastname,context)"/>
<field name="lastname" string="Last name" on_change="onchange_name(firstname,lastname,context)"/>
推荐答案
在模型中,重新定义计算和存储的 name 字段:
In the model, redefine the name field as computed and stored:
name = fields.Char(compute='comp_name', store=True)
然后定义计算方法:
@api.depends('first_name','last_name')
def comp_name(self):
self.name = (self.first_name or '')+' '+(self.last_name or '')
这样,您可以删除 on_change
这篇关于连接名字和姓氏,并在odoo中填写名称字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!