Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
3654 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Tác giả

Thank you

Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ

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

Tác giả Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ

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>

</>

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 7 25
2447
2
thg 7 25
7905
2
thg 7 25
4313
2
thg 7 25
4059
2
thg 6 25
2661