İçereği Atla
Menü
Bu soru işaretlendi
2 Cevaplar
8540 Görünümler

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'),
                }
Avatar
Vazgeç
En İyi Yanı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.

Avatar
Vazgeç
Üretici En İyi Yanı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
Avatar
Vazgeç

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

İlgili Gönderiler Cevaplar Görünümler Aktivite
0
Nis 23
2999
4
Ara 23
17712
1
Eyl 16
7426
0
Mar 15
3670
0
Eyl 24
296