跳至内容
菜单
此问题已终结
2 回复
3677 查看

I inherited the partner model as follows:

class PartnerExt(models.Model):
_inherit = 'res.partner'
cars = fields.One2many('contact.cars', 'partner_id', string='Cars')
class Car(models.Model):
     _name = 'contact.cars'
     _rec_name = "car_name"
     car_name = fields.Char(string="Car")
     price = fields.Char(string="Price" )

I have this inside base view partner form:

< field name="cars" />

But it shows only the car names and not the prices.

How can I show the prices for each car?

Thank you

形象
丢弃
编写者

Thank you

最佳答案

Hi,
if you need to show the car name and price together in a field, you have to define the name_get function for the newly added model contacts.car and return the combined string of car name and price.

See: https://www.youtube.com/watch?v=-1r3WSwtqxQ

Thanks

形象
丢弃

Sample:

@api.multi

def name_get(self):

res = []

for rec in self:

res.append((rec.id, '%s - %s' % (rec.car_name, rec.price)))

return res

编写者 最佳答案

@Niyas, I need it to be a name and price 2 separate fields

形象
丢弃

seems you added one2many field ? so a contact can have multiple cars ?

then update your xml file as follows:

< field name="cars">

<tree>

<field name="car_name"/>

<field name="price"/>

</tree>

</>

相关帖文 回复 查看 活动
1
7月 25
2491
2
7月 25
7934
2
7月 25
4368
2
7月 25
4083
2
6月 25
2681