2
votes

How do I create a functional field in OpenERP?

It seems that I need to create the function in python, then call it with XML. I see the XML that needs to be edited, but what file does the python code go in?

3

3 Answers

6
votes

The code for py file..

class some_model(osv.osv):

    _name = 'some.model'

    def Method_of_Function(self, cr, uid, ids, fld_name, arg, context=None):
        #Logic
        return value 

    _columns = {
        "functional_filed":fields.function(Method_of_Function, 
                   method=True,type='int',string='Label', store=True),

    }
some_model()

and in xml file record tag look like...

<record model="ir.ui.view" id="object_name_form_view">
        <field name="name">objectname.form</field>
        <field name="model">some.model</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <form string="form_string">
                <field name="functional_filed" />
            </form>
        </field>
    </record>
2
votes

First you have to define functional field in .py file:

'amount' : fields.function(_calc_amount, type="float", method=True, store=True, string="Amount"),

def _calc_amount(self, cr, uid, ids, name, args, context=None):
Your code...

Then define your functional field in your .xml file.

0
votes

You can refer from here. How to create functional fields

http://doc.openerp.com/v6.0/developer/2_5_Objects_Fields_Methods/field_type.html

Here is another link for your reference

http://members.hellug.gr/xrg/openerp-doc/html/api_reference/osv/fields_function.html

You have to create function fields in py file and call it from xml file.