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

override Data in tree view

By
omkar
on 3/31/14, 1:18 PM 1,892 views

HI Friends.

I had a query. I had a tree view I want to override the values for the fields in the tree view so that , I can put my values instead of the existing values for the Display, The same should display for the form view also.

I want to do this operation by using the python coding not with the xml coding.

Eg : by using fields_view_get function we can modify the values for the form view, how can we do the same for the tree view.

Yes you can do using fields_view_get.

Jagdish Panchal
on 4/1/14, 5:26 AM

HI Jack. Can you send me a example for this.

omkar
on 4/4/14, 2:50 PM

I struck with this from last three days... Please provide a example It helps me a lot..

omkar
on 4/4/14, 2:50 PM

paste your method code will see and help you

Jagdish Panchal
on 4/5/14, 2:00 AM
0
omkar
On 4/5/14, 4:28 AM

Hi Jack..

Here is the code in .py file

class hr_objectives(osv.osv): _name="hr.objectives" _columns={'active_id': fields.integer(), 'values': fields.text(), }

class hr_performancegoals(osv.osv): _name = "hr.performancegoals" _description = "Performance Goals"

def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
     if context is None:
        context = {}
     result = super(hr_performancegoals, self).fields_view_get(cr, uid, view_id,view_type, context, toolbar,submenu)
     #print "Result OF Goals Hope :", result
     data = result['arch']
     if uid == 1:
        L=[]
        ldata = data.split("\n")
        for var in ldata:
             if re.search("str_goals",var):
                 pass
             else:
                 L.append(var)
        reqdata =''.join(L)
        result['arch']=reqdata
     else:
        L=[]
        ldata = data.split("\n")
        for var in ldata:
             if re.search("strategic_goals",var):
                 pass
             else:
                 L.append(var)
        reqdata =''.join(L)
        result['arch']=reqdata

     if context.get('name_related',''):
         if result['name'] == "hr.performancegoals.form":

             cr.execute("select str_goals,objectives,specific_actions_required_to_deliver_strategic_goal,completion_date from hr_performancegoals where employee_id=%s" %(context.get('id','')))
             dicdata = cr.dictfetchall()
             L=self._get_objectives(cr,uid,context)
             print "Objectives :",L
             data = result['fields']
             arch = result['arch'].split('</tree>')
             arch=arch[0]+'''<label align='0.0' string = "Omkar"/></tree>'''
             #print"Architecture::", arch

             meet = self.pool.get('hr.performancegoals')
             meet_obj = meet.browse(cr, uid, context.get('id',''), context=context)
             result = meet.fields_view_get( cr, uid, view_id, 'form')
             print "Result Here Once :", result
             #result['arch']=arch

     return result


def _get_employee_id(self,cr,uid,ids,name,arg,context=None):
    if context.get('id',''):
        res = dict.fromkeys(ids,context.get('id',''))
        return res
    else:
        cr.execute("select id from resource_resource where user_id=%s"%context.get('uid',''))
        log_name = cr.dictfetchall()[0]
        res = dict.fromkeys(ids,log_name['id'])
        return res

def _get_objectives(self, cr, uid,context):
    L=[]
    if context.get('name_related','') :
       cr.execute ("select parent_id from hr_employee where name_related='%s'"%context.get('name_related',''))
       parent_id=cr.dictfetchall()[0]
       cr.execute("select objectives from hr_performancegoals where employee_id=%s"%int(parent_id['parent_id']))
       data = cr.dictfetchall()
       for i,values in enumerate(data):
         if values['objectives'] == None:
             pass
         else:
             a=unicodedata.normalize('NFKD', values['objectives']).encode('ascii','ignore')
             L.append((a,a))
    else:
        if context.get('uid',''):
            user_id = int(context.get('uid',''))
            cr.execute("select id from resource_resource where user_id=%s"%user_id)
            log_name = cr.dictfetchall()[0]
            if log_name['id'] == 1:
                L=[]
            else:
                cr.execute ("select parent_id from hr_employee where id=%s"%log_name['id'])
                parent_id=cr.dictfetchall()[0]
                cr.execute("select objectives from hr_performancegoals where employee_id=%s"%parent_id['parent_id'])
                data = cr.dictfetchall()
                for i,values in enumerate(data):
                    a=unicodedata.normalize('NFKD', values['objectives']).encode('ascii','ignore')
                    L.append((a,a))
    return L

_columns = {
'employee_id': fields.function(_get_employee_id,method=True, type='many2one', relation="hr.employee", string="Employee",store=True),
'strategic_goals': fields.char('Strategic Goals'),
'str_goals': fields.selection(_get_objectives, type='selection', method=True, store=False, string="Strategic"),
'objectives' : fields.text('Objectives'),
'completion_date' : fields.date('Completion Date'),
'specific_actions_required_to_deliver_strategic_goal' : fields.text('Specific Actions Required To Deliver Strategic Goal'),
'status': fields.selection([('Yet To Start','Yet To Start'),
                           ('In Progress','In Progress'),
                           ('Invalid','Invalid'),
                           ('Completed','Completed'),
                           ('Closed','Closed'),],
                            'Status', required=True),
            }

class hr_team(osv.osv): # Instead of Act Win I want to call Function _name = "hr.team" _inherit="hr.employee" _description = "Team Goals"

_columns = {
'id':fields.char('Employee ID'),
'name_related':fields.char('EMPLOYEE NAME', require=True),
'department_id':fields.char('Department'),
'work_location': fields.char('Office Location', size=32),
'job_id':fields.char('Role/Designation', required=True),
             }

Here is the XML File...

    <record model="ir.ui.view" id="view_hr_performancegoals_form">
        <field name="name">hr.performancegoals.form</field>
        <field name="model">hr.performancegoals</field>
        <field name="arch" type="xml">
            <form string="Goals" version="7.0">
            <sheet>
             <notebook>
               <page string="Add New Goals">
               <group>
               <field name="employee_id" invisible="1"/>
               </group>
                    <group col="4">
                        <field name="str_goals" context="{'employee_id':employee_id}"/>
                        <field name="strategic_goals" />
                        <field name="objectives"/>
                        <field name="completion_date"/>
                        <field name="specific_actions_required_to_deliver_strategic_goal"/>
                        <field name="status"/>
                    </group>
                </page>
              </notebook>
              </sheet>
            </form>
        </field>
    </record>

    <record model="ir.ui.view" id="view_hr_performancegoals_tree">
        <field name="name">hr.performancegoals.form</field>
        <field name="model">hr.performancegoals</field>
        <field name="arch" type="xml">
            <tree string="Goals" editable="bottom" >
                <field name="employee_id" invisible="1"/>
                <field name="str_goals" context="{'employee_id':employee_id}"/>
                <field name="strategic_goals"/>
                <field name="objectives"/>
                <field name="completion_date"/>
                <field name="specific_actions_required_to_deliver_strategic_goal"/>
                <field name="status"/>
            </tree>
        </field>
</record>

<record id="hr_performancegoals_action" model="ir.actions.act_window"> <field name="name">Goals</field> <field name="res_model">hr.performancegoals</field> <field name="view_type">form</field> <field name="view_mode">tree,form</field> <field name="view_id" ref="view_hr_performancegoals_tree"/> </record> <menuitem parent="hr_evaluation.menu_eval_hr" id="hr_performancegoals" name="Goals" action="hr_performancegoals_action"/>

<record model="ir.ui.view" id="view_hr_team_form"> <field name="name">hr.team.form</field> <field name="model">hr.employee</field> <field name="arch" type="xml"> <notebook position="inside"> <page string="Team"> <group col="4"> <field name="id" invisible="1"/> <field name="name_related"/> <field name="department_id"/> <field name="work_location"/> <field name="job_id"/> <button name="%(act_view_hr_performancegoals_tree)d" type="action" string="Assign Goals" class="oe_link oe_edit_only" icon="STOCK_DIRECTORY_MENU" context="{'id':id,'name_related':name_related}"/> </group> </page> </notebook> </field> </record>

    <record model="ir.ui.view" id="view_hr_team_tree">
        <field name="name">hr.team.tree</field>
        <field name="model">hr.employee</field>
        <field name="type">tree</field>
        <field name="arch" type="xml">
            <tree string="Team" editable="bottom" >
                        <field name="id" invisible="1"/>
                        <field name="name_related"/>
                        <field name="department_id"/>
                        <field name="work_location"/>
                        <field name="job_id"/>
                    <!--<button name="action_button_confirm" type="object"  string="Assign Goals" class="oe_link oe_edit_only" icon="STOCK_DIRECTORY_MENU" context="{'id':id,'name_related':name_related,'employee_id':id}"/>  -->
                        <button name="%(act_view_hr_performancegoals_tree)d" type="action" string="Assign Goals" class="oe_link oe_edit_only" icon="STOCK_DIRECTORY_MENU" context="{'id':id,'name_related':name_related}"/>
            </tree>
        </field>
    </record>

    <record id="hr_team_action" model="ir.actions.act_window">
        <field name="name">Team</field>
        <field name="res_model">hr.employee</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
        <field name="view_id" ref="view_hr_team_tree"/>
    </record>

<menuitem id="hr_team" name="Team" parent="hr_evaluation.menu_eval_hr" action="hr_team_action"/>

My Query was that In the Team Menu If i select and Click on the Person of my team , the I want to see only his Goals rather than My goals which will visible in the goals page. Team menu should be inherited from hr employee

Hi Jack Any Update regarding this???

omkar
on 4/14/14, 5:52 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

0 follower(s)

Stats

Asked: 3/31/14, 1:18 PM
Seen: 1892 times
Last updated: 3/16/15, 8:10 AM