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

Add one2many record onchange SNAFU

By
Nanda Kanoko
on 7/18/13, 2:43 AM 1,550 views

I want to copy record from one2many field from class notebook.project to one2many field in notebook.sheet , but somehow the employee showed is not correct according to their assigned project from the first time .

My py :

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

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

        }

notebook_project()


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

    def onchange_project(self, cr, uid, ids, notebook_project, context=None):
            res = {}
        employee_lines = []
        employee_ids = self.pool.get('notebook.project').search(cr, uid, [('notebook_project_id', '=', notebook_project)],limit=5)
            for p in self.pool.get('notebook.project').browse(cr, uid, employee_ids):
                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_id(self, cr, uid, ids, project_id, context=None):
        if project_id :
            prod = self.pool.get('project.project').browse(cr, uid, project_id, context=context)
            return {'value': {'name': prod.name}}
        return {}

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

        }

notebook_sheet()

The error is like this :

Let's say I have project A with employee X and Y , while project B with employee K , L , M and N . While I create on notebook.sheet , i choose project B , so logical outcome for notebook_sheet_lines show employee K , L , M and N . But instead it shows employee X and Y from project A . I really need help on this , thanks in advance .

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