Quantcast
Channel: OpenERP Help - Individual question feed
Viewing all articles
Browse latest Browse all 69

Default values for child field

$
0
0
I'm trying to set default values for a child field in the parent module.
Those default values have to be created in the database first.
However, my issue is to link them to the parent, since the parent record itself isn't yet created in the default method.

My Code in the parent module: _columns = { ... 'project_line_ids': fields.one2many('timesheet.project.line','timesheet_line_id','Project Lines'), } def _get_default_project_lines(self, cr, uid, context=None): emp_ids = self.pool.get('hr.employee').search(cr, uid, [('user_id', '=', uid)]); p_line = self.pool.get('timesheet.project.line'); vals = p_line.default_get(cr, uid, ['timesheet_line_id', 'comment', 'used time'], context=None); ids = []; for p_id in self.pool.get('project.project').search(cr, uid, [('member_ids', 'in', emp_ids), ('active', '=', True)]): vals['project_id']=p_id; ids.append(p_line.create(cr, uid, vals, context=None)); return ids; _defaults = { ... 'project_line_ids': _get_default_project_lines, Snippet from the child module: _columns = { ... 'timesheet_line_id': fields.many2one('timesheet.line', 'Timesheet Line', ondelete='cascade'), } To explain: The parent is a line in a timesheet. And i want each line to have several child records of project.line The issue is not that the children aren't created. But they are not linked to the parent correctly. I've tried to use active_id in the context of the field in the view to set the default value for the timesheet_line_id, but that fails.. View:
Any advice?
Is there a way to get the id of the new record during creation process?

Viewing all articles
Browse latest Browse all 69

Trending Articles