Create a functional field in OpenErp

那年仲夏 提交于 2019-12-06 09:25:52

问题


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?


回答1:


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:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/11892897/create-a-functional-field-in-openerp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!