Skip to Content
Menu
This question has been flagged
2 Replies
8512 Zobrazenia

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
Zrušiť
Best Answer

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
Zrušiť
Autor Best Answer

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
Zrušiť

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

Related Posts Replies Zobrazenia Aktivita
0
apr 23
2973
4
dec 23
17680
1
sep 16
7401
0
mar 15
3649
0
sep 24
296