Skip to Content
Menu
This question has been flagged
8 Replies
28389 Views

Hello,

I have 2 fields, Name and Lastname, but in the view I want them to appear together inside just one field, so instead of having:

<field name="Name" string="Name" />

<field name="Last Name" string="Last Name" />

I want 1 field which would have Name+Last Name

Any tip on how to do this will be appreciated,

Thanks!

Avatar
Discard

@Yakito, if answer is good, you vote and/or accept this answer!

Author

Yes yes, sure I will, I have to test it first. That will happen tonight!

Best Answer

You could try something like:

<label for="Name and Lastname"/>
<div>
     <field name="Name" class="oe_inline"/><field name="Last Name" class="oe_inline" />
 </div>

The "label" should be the "string" that you wish to show.

Avatar
Discard
Author

Oh, perfect, I thought I had to do it on python, this is much simpler. thanks!

You can define a field and user a python code to concatenate what you want, but i thought that you only needed a "visual thing". If you need to store it for some reason i have a very basic example i had to make :P (i am a newbie myself :P)

tienes el ejemplo de contactenar un campo?
quiero concatenar tres campos: nombre+apellido1+apellido2
y sustituir con eso el nombre del partner

Best Answer

Oi Federico,

Tray the code below. You may iterate the variables if there are a list in place of object's fields.

<t t-set="finaltext" t-value="obj.yourvariable1+' #'+obj.yourvariable2+', #'+obj.yourvariable3 "/>
<span t-esc="finaltext"/>
Avatar
Discard
Best Answer

 @api.model

def create(self, vals):

if vals['fname']:

fname = vals['fname'].title()

else:

fname = ''

if vals['lname']:

lname = vals['lname'].title()

else:

lname = ''

name = "{}, {}".format(lname, fname,)

print 'name', name

vals['name'] = name

vals['fname'] = fname

vals['lname'] = lname

if 'address_id' in vals:

res_id = super(HrEmployee, self).create(vals)

return res_id


fname is your firstname and lname is your lastname, Try this on your python file

Avatar
Discard
Best Answer

Is possible to do the same thing with strings from a a single field (in my case product.id from pos.order)? 

I would like to concatenate every code starting with '#' between the codes starting with [internal reference].

Normal view:

[0001] product1
# product instructions 1
# product instructions 2

[0002] product2
# product instructions 1
# product instructions 2

Should appear as :

[0001] product1    # product instructions 1 , # product instructions 2

[0002] product2    # product instructions 1 , # product instructions 2

Is it possible with the same principle directly on xml? I don't need to store information (for now) is just another rappresentation.

Avatar
Discard
Related Posts Replies Views Activity
1
Sep 24
2601
1
Mar 22
2244
3
May 25
980
1
Apr 25
842
3
Sep 24
13131