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

How to create a new openerp field through function?

By
arsalan
on 3/31/14, 5:20 AM 1,765 views

I wanted to know if I want to create a new field then how this can be done. How to set the xml and other details .I think I will have to set them and return the field. But is there any specific function to create new field ? . I have no idea .

Please help Thanks

You want to add dynamic field ?

Jagdish Panchal
on 3/31/14, 5:23 AM

first I want to add a new field then I will think a way to add dynamic ones . I f you know any of these plz help

arsalan
on 3/31/14, 5:29 AM

my field is not being displayed

arsalan
on 3/31/14, 10:53 AM
0
ayman mohammed adam
On 7/24/14, 5:10 AM

def fields_view_get(self, cr, uid, view_id, view_type='form', context=None,toolbar=False,submenu=False): result = super(deg_form, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar,submenu) moves_fields=result['fields'] moves_fields.update({ "name" : {'string': 'MyNewName','type': 'char', 'size': 10}) moves_fields.update({ "data_type" : {'string': 'MyTYPE','type': 'char', 'size': 10}) moves_fields.update({ "father_name" : {'string': 'MyNewName','type': 'char', 'size': 10})

0

Jagdish Panchal

--Jagdish Panchal--
2674
| 5 3 6
Gandhinagar, India
--Jagdish Panchal--

OpenERP Developer

Jagdish Panchal
On 3/31/14, 5:32 AM

Hi

This will help you https://accounts.openerp.com/forum/Help-1/question/47546

Refer below code

def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
    if context is None:
        context = {}
    wiz_id = self.pool.get('ir.actions.act_window').search(cr, uid, [("name","=","analytic.plan.create.model.action")], context=context)
    res = super(account_analytic_plan_instance,self).fields_view_get(cr, uid, view_id, view_type, context, toolbar=toolbar, submenu=submenu)
    journal_obj = self.pool.get('account.journal')
    analytic_plan_obj = self.pool.get('account.analytic.plan')
    if (res['type']=='form'):
        plan_id = False
        if context.get('journal_id', False):
            plan_id = journal_obj.browse(cr, uid, int(context['journal_id']), context=context).plan_id
        elif context.get('plan_id', False):
            plan_id = analytic_plan_obj.browse(cr, uid, int(context['plan_id']), context=context)

        if plan_id:
            i=1
            res['arch'] = """<form string="%s">
<field name="name"/>
<field name="code"/>
<field name="journal_id"/>
<button name="%d" string="Save This Distribution as a Model" type="action" colspan="2"/>
"""% (tools.to_xml(plan_id.name), wiz_id[0])
            for line in plan_id.plan_ids:
                res['arch']+="""
                <field name="account%d_ids" string="%s" nolabel="1" colspan="4">
                <tree string="%s" editable="bottom">
                    <field name="rate"/>
                    <field name="analytic_account_id" domain="[('parent_id','child_of',[%d])]" groups="analytic.group_analytic_accounting"/>
                </tree>
            </field>
            <newline/>"""%(i,tools.to_xml(line.name),tools.to_xml(line.name),line.root_analytic_id and line.root_analytic_id.id or 0)
                i+=1
            res['arch'] += "</form>"
            doc = etree.fromstring(res['arch'].encode('utf8'))
            xarch, xfields = self._view_look_dom_arch(cr, uid, doc, view_id, context=context)
            res['arch'] = xarch
            res['fields'] = xfields
        return res
    else:
        return res

I tried that .But I was unable to get that solution . I think fields_view_get will up grade the already created fields . I want to create fields not upgrade.

arsalan
on 3/31/14, 5:44 AM

using fields_view_get get you can add dynamic filed. can u paste your code here ?

Jagdish Panchal
on 3/31/14, 6:49 AM

have u created dynamic fields before?

arsalan
on 3/31/14, 7:02 AM

yes ? i have

Jagdish Panchal
on 3/31/14, 7:05 AM

def fields_view_get(self, cr, uid, view_id, view_type='form', context=None,toolbar=False,submenu=False): result = super(deg_form, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar,submenu) moves_fields=result['fields'] moves_fields.update({ "name" : {'string': 'MyNewName','type': 'char'}}) moves_fields.update({ "data_type" : {'string': 'MyTYPE','type': 'char'}})
moves_fields.update({ "father_name" : {'string': 'MyNewName','type': 'char'}}) # school_obj = self.pool.get('deg.form') result['fields'] = moves_fields # if vi

arsalan
on 3/31/14, 7:08 AM

above here is my function

arsalan
on 3/31/14, 7:11 AM

<button name="fields_view_get" string="CREATE FIELD" type="object" /> And this is button which will call fields_view_get to create fields

arsalan
on 3/31/14, 7:12 AM

can u make me realize whats wrong here

arsalan
on 3/31/14, 7:22 AM

@arsalan: fields view get call when view load, you want create in button click. So in your case i can't help you.

Jagdish Panchal
on 3/31/14, 7:25 AM

is there some way I could do this , by any function . If I can return field

arsalan
on 3/31/14, 7:27 AM

hello jack?

arsalan
on 3/31/14, 7:51 AM

Sorry i have no idea..

Jagdish Panchal
on 3/31/14, 7:55 AM

ok tell me how can I create fields with fields_view_get function

arsalan
on 3/31/14, 7:57 AM

I have update ans check try it.

Jagdish Panchal
on 3/31/14, 8:01 AM

can we give name, data_type etc of our choice or not?

arsalan
on 3/31/14, 8:05 AM

yes you can type:'Any tyep' , string:'name of field'

Jagdish Panchal
on 3/31/14, 8:08 AM

but here u have not used my class n objects , I am having problems understanding it. How could I import it in my module

arsalan
on 3/31/14, 8:10 AM

u have used account.journal , journal_id , account_analytic_plan etc . can u explain a bit

arsalan
on 3/31/14, 8:12 AM

because I will have to make changes according to my class.

arsalan
on 3/31/14, 8:12 AM

There is lost of example in openerp addons module.

Jagdish Panchal
on 3/31/14, 8:24 AM

ur code is complaining "xml view error". May be u have missed something. Please check

arsalan
on 3/31/14, 8:25 AM

This code is given in openerp addons>>account_analytic_plans>>account_analytic_plans.py line no : 170 to 210, pls refer this

Jagdish Panchal
on 3/31/14, 8:43 AM

just tell me how it works if u know. because I really need to understand this to code it

arsalan
on 3/31/14, 9:12 AM

can u code a simple function n edit the one that I sent u . It will be much easier for me to understand the flow of fields_view_get because ur function has an xml issue

arsalan
on 3/31/14, 9:30 AM

show your code will give solution.

Jagdish Panchal
on 3/31/14, 9:38 AM

I sent u my code before .Pls do make changes in it

arsalan
on 3/31/14, 9:39 AM

xml issue, because u have not given the xml issue

arsalan
on 3/31/14, 9:54 AM

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: 3/31/14, 5:20 AM
Seen: 1765 times
Last updated: 3/16/15, 8:10 AM