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

Copy / show record from one2many to other one2many

By
Nanda Kanoko
on 7/24/13, 2:43 AM 1,144 views

I need to show record in one2many field according to project

my py :

class notebook_project(osv.osv):
    _name = "notebook.project"
    _description = "Notebook Project ID"

    def onchange_project(self, cr, uid, ids, project, arg, context=None):
        if project :
            proj = self.pool.get('project.project').browse(cr, uid, project, context=context)
            return {'value': {'name': proj.name}}
        return {}
    _columns = {
        'name' : fields.char('Name', size=64),
        'project' : fields.many2one('project.project', 'Project'),
        'notebook_project_lines' : fields.one2many('notebook.project', 'notebook_project_id', 'Members Lines'),
        'notebook_project_id': fields.many2one('notebook.project', 'Parent Project', ondelete='cascade', select=True),
        'member' : fields.many2one('hr.employee', 'Members'),

        }

notebook_project()


class notebook_sheet(osv.osv):
    _name = "notebook.sheet"
    _description = "Notebook Project Sheet"

    def onchange_notebook_project(self, cr, uid, ids, notebook_project, context=None):
        res = {}
        employee_lines = []
        if not notebook_project : return {}
        if notebook_project :
            notebook_project_obj = self.pool.get('notebook.project').browse(cr, uid, notebook_project_id)
            for p in notebook_project_obj.notebook_project_lines:
            employee_lines.append((0,0,{'notebook_sheet_lines':p.id
            }))#this dict contain keys which are fields of one2many field 
            res['notebook_sheet_lines']=employee_lines
            return res

    def onchange_project(self, cr, uid, ids, project, context=None):
        if project :
            proj = self.pool.get('project.project').browse(cr, uid, project, context=context)
            return {'value': {'name': proj.name}}
        return {}

    _columns = {
        'name' : fields.char('Name', size=64),
        'notebook_sheet_lines' : fields.many2many('notebook.project', 'notebook_project_sheet_rel', 'notebook_project', 'notebook_project_id'),
        'notebook_project': fields.many2one('notebook.project', 'Project ID',domain=[('notebook_project_id','=',False)]),
        'project' : fields.many2one('project.project', 'Project'),
        'member' : fields.many2one('hr.employee', 'Members'),

        }

notebook_sheet()

Lets say on notebook.project i have project A with employee B , C and D , while in project X i have employee Y and Z . So when i choose project X on notebook.sheet , it will show employee Y and Z on notebook_sheet_lines Please help , thanks

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: 7/24/13, 2:43 AM
Seen: 1144 times
Last updated: 3/16/15, 8:10 AM