Odoo Help

0

Custom Module - functional field to sum two other fields - not working

By
rosey
on 8/29/13, 6:27 AM 2,074 views

class model_model(osv.osv):

_name = "model.model"

def multi_a_b(self, cr, uid, ids, name, arg, context=None):
    res = {}
    for record in self.browse(cr, uid, ids,context):
        res[record.id] = record.quantity * record.value
    return res

_columns = {
            'product' : fields.many2one('product.product','Product',required=True),
            'quantity' : fields.integer('Quantity',size = 16,required = True,translate = True),
            'value' : fields.float('Value',size = 16,required = True,translate = True),
            'amount' : fields.function(multi_a_b, string='Amount', type='float'),             
           }

model_model()

i want to multiple quantity*value get the answer in amount field. But i didnt get any output.

1
Xsias
On 8/29/13, 11:12 AM

Can you try :

class model_model(osv.osv):
   _name = "model.model"

    def multi_a_b(self, cr, uid, ids, name, arg, context=None):
        res = {}
        for record in self.browse(cr, uid, ids,context):
            res[record.id] = int(record.quantity) * float(record.value)
        return res

    _columns = {
        'product' : fields.many2one('product.product','Product',required=True),
        'quantity' : fields.integer('Quantity',size = 16,required = True,translate = True),
        'value' : fields.float('Value',size = 16,required = True,translate = True),
        'amount' : fields.function(multi_a_b, type='float', store=True, string='Amount'),             
       }

model_model()

About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 8/29/13, 6:27 AM
Seen: 2074 times
Last updated: 3/16/15, 8:10 AM