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

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

By
rosey
on 8/29/13, 6:27 AM 1,592 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()

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

1 follower(s)

Stats

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