Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Creating a functional field in OpenERP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 416
    Comment on it

    Functional field is a field which gets its value on the basis of a function, for example an amount can be calculated using the various others values of the invoice like taxes, discounts, labor charges, extra charges etc, you will need a function that does it all and automatically the amount is shown in the invoice.

    First define a field in the _columns:

    'tamount':fields.function(_func_tax_amount, digits_compute=dp.get_precision('Account'), type='float', string='Vat Amount' , method=True, store=True),
    

    where, _func_tax_amount is the function that gets value for tamount field,

    type determines the type for the field tamount,

    string is the displayed name of the field,

    method determines whether the value will be calculated by the function,

    store as true means that the field will be stored in the database, by default it is false

    Now create a function with the same name in the field definition i.e. _func_tax_amount:

    def _func_tax_amount(self, cr, uid, ids, invoice_id, arg, context=None):
        res = {}        
        invoices = self.pool.get('account.invoice')
        taxes = self.pool.get('account.invoice.line.tax')
        tamount = 0.0
        for line in self.browse(cr, uid, ids, context=context):
            if not line.name == 'Cartage' and not line.name == 'Labour':                
                if line.tax_name == 'None':                    
                    tamount = 0.0               
                if not line.tax_name == 'None':              
                    cr.execute('select account_tax.amount from account_tax inner join account_invoice_line_tax  on account_invoice_line_tax.tax_id = account_tax.id where account_invoice_line_tax.invoice_line_id = %s',(line.id,))
                    amt = float(cr.fetchone()[0] )                
                    tamount = amt * line.price_subtotal            
            res[line.id] = tamount
        return res   
    

    Simply create a field and a function, and at last when defining in the view add as a normal field:

    <field name="tamount"/>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: