This question has been flagged
2 Replies
3950 Views

Hello,

Please, help me!

Where is my error???

def _amount_weight(self, cr, uid, ids, name, args, context=None):
     invoice_ids = self.pool.get('account.invoice').search(cr, uid, [])

     total_weight = 0
    for iid in invoice_ids:
        line_ids = self.pool.get('account.invoice.line').search(cr, uid, [('id', '=', iid)], offset=0, limit=None, order=None, context=None, count=False)

        for lid in line_ids:
            i_line = self.pool.get('account.invoice.line').browse(cr, uid, iid, context=context)
            i_weight = i_line.weight
            total_weight = total_weight + i_weight
        return total_weight
    _columns = {
        'weight_tot_test': fields.function(_amount_weight, type='float', string='Poids Total'),
    }

Error Message

File "/opt/openerp/openerp/addons/invoice/invoice.py", line 22 return total_weight SyntaxError: 'return' outside function

Avatar
Discard
Author Best Answer

How can I do?

class account_invoice(osv.osv):
    _inherit = 'account.invoice'

    def _amount_weight(self, cr, uid, ids, name, args, context=None):
     invoice_ids = self.pool.get('account.invoice').search(cr, uid, [])

     total_weight = {}
    for iid in invoice_ids:
        line_ids = self.pool.get('account.invoice.line').search(cr, uid, [('id', '=', iid)], offset=0, limit=None, order=None, context=None, count=False)

        for lid in line_ids:
            i_line = self.pool.get('account.invoice.line').browse(cr, uid, iid, context=context)
            i_weight = i_line.weight
            total_weight[lid.id] = t i_weight
        return total_weight
    _columns = {
        'weight_tot_test': fields.function(_amount_weight, type='float', string='Poids Total'),
    }
account_invoice()

Is correct???

Thx

Avatar
Discard

I don't think so, because you are adding lid.id but you have to return iid.id.

Author

I don't understand ... how can I return only "total_weight"?

I cant understand ur indendation. The return Statement should have the same indentation as the line "for iid in invoice_ids:" has

Author
    for iid in invoice_ids:
        line_ids = self.pool.get('account.invoice.line').search(cr, uid, [('id', '=', iid)], offset=0, limit=None, order=None, context=None, count=False)

        for lid in line_ids:
            i_line = self.pool.get('account.invoice.line').browse(cr, uid, iid, context=context)
            i_weight = i_line.weight
            total_weight = total_weight + i_weight
    return total_weight
Best Answer

You have to return a dictionary with object ids and values:

return {1: 10.5, 2: 3.2 ..........}

this fills the function column with their respective id

Avatar
Discard