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

I need sum the field "Hours" of all lines on a treeview and store the result in other field ("total_hours") on main table. The main Table have a one2many field linked to second table (treeview).

How can i do this?

Main Table:

class main_table(osv.osv):
    _name = 'sat.main'
    _columns = {
        'name' : fields.char('name', size=256, required=True),
        'total_hours' : fields.float('Producto'),
        'hours_id': fields.one2many('sat.hours', 'hour_id', 'Horas'),
        }

Second Table:

class hours(osv.osv):
    _name = 'sat.hours'
    _columns = {
                'hour_id': fields.many2one('sat.main', 'mainwork'),
                'concept': fields.char('Concept', size=128, required=True),
                'hours': fields.float('hours'),
                }
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

First of all on hour_id it's 'sat.main' not 'sat.incidencias'
You can write a default_get function and sum lines there, then you have to return the lines and there you can write on your object.

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

I Found a good solution:

def _total_presupuestos(self, cr, uid, ids, field_name, field_value, arg, context=None):
    result={} 
    total=0
    invoice_obj = self.pool.get('sat.incidencias')
    for records_invoice in invoice_obj.browse(cr, uid, ids):
        for records_invoice_lines in records_invoice.presupuesto_id:
            total += records_invoice_lines.pv_sin_impuestos
            result[records_invoice.id] = total
    return result
Ảnh đại diện
Huỷ bỏ

Dear Frans
Can I do this in online odoo version. I need it so bad.

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 4 23
2973
4
thg 12 23
17680
1
thg 9 16
7400
0
thg 3 15
3648
0
thg 9 24
296