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

my filelds are

 def _get_total(self, cr, uid, ids, name, unknow_none, context=None):
        res = {}
        for record in self.browse(cr, uid, ids, context=context):
            total = 0.0
            for line in record.cost_ids:
                total += line.amount
            res[record.id] = total
        return res  
_columns = {
 'total': fields.function(_get_total, string='Total', type='float', method=True, store=True),
 'cost_amount': fields.related('total','cost_id', 'amount', string='Amount',type='float',store=True),  
}

it got an error like TypeError: 'float' object has no attribute '__getitem__'

pls anybody can help me regards jamshid k

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hy,

I think you have to precise a little bit. Is the related fiedl in the same object as total? If it's the case, I don't understand why you use an additionnal relation in your related fields.

'cost_amount': fields.related('total', string='Amount',type='float',store=True),

Should be enough!

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 3 15
3811
0
thg 9 25
2
2
thg 9 25
803
1
thg 9 25
1301
0
thg 7 25
798