Skip to Content
Menu
This question has been flagged
1 Reply
4991 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.

Avatar
Discard
Best Answer

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()
Avatar
Discard