Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Where is my error? DEF function

By
Anne-Sylvie Burri
on 11/5/13, 6:37 AM 1,155 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

0

Grover Menacho

--Grover Menacho--
2523
| 5 7 8
La Paz, Bolivia
--Grover Menacho--

Systems Engineer + MBA

Grover Menacho
On 11/5/13, 8:57 AM

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

0
Anne-Sylvie Burri
On 11/5/13, 9:14 AM

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

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

GH Mediacloud, Grover Menacho
on 11/5/13, 10:25 AM

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

J.-M. Burri - Bureau ing.-conseils informatique, Anne-Sylvie Burri
on 11/5/13, 11:09 AM

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

Subhin P V
on 11/7/13, 8:12 AM
    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
J.-M. Burri - Bureau ing.-conseils informatique, Anne-Sylvie Burri
on 11/11/13, 6:43 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 11/5/13, 6:37 AM
Seen: 1155 times
Last updated: 3/16/15, 8:10 AM