how to pass values from a one2many field to another field in different model of same form? form view image given below (ial)
ial
one2many field name: survey_request_ids
model of one2many field : hr_evaluation.evaluation
Field name of 'Interviewer' inside one2many : user_id
model of 'Interviewer' inside one2many : hr.evaluation.interview
I want to create a new field 'Interviewer' below 'Appraisal Deadline'
which will have values from the below field 'Interviewer' which is in a one2many.
I tried like these,
from openerp import models,fields,api
class hr_evaluation_interview(models.Model):
_inherit = 'hr.evaluation.interview'
@api.onchange('user_id')
def _onchange_user_id(self):
rec = self.env['hr_evaluation.evaluation'].search([('id','=',
self.evaluation_id.id)])
rec.update(
'interviewer_ids': [(4,self.user_id.id)]
)
class hr_evaluation_inherit(models.Model):
_inherit = 'hr_evaluation.evaluation'
_columns =
'interviewer_ids': fields.many2many('res.users',
string='Interviewer',readonly=True)
xml python-2.7 odoo-8
add a comment |
ial
one2many field name: survey_request_ids
model of one2many field : hr_evaluation.evaluation
Field name of 'Interviewer' inside one2many : user_id
model of 'Interviewer' inside one2many : hr.evaluation.interview
I want to create a new field 'Interviewer' below 'Appraisal Deadline'
which will have values from the below field 'Interviewer' which is in a one2many.
I tried like these,
from openerp import models,fields,api
class hr_evaluation_interview(models.Model):
_inherit = 'hr.evaluation.interview'
@api.onchange('user_id')
def _onchange_user_id(self):
rec = self.env['hr_evaluation.evaluation'].search([('id','=',
self.evaluation_id.id)])
rec.update(
'interviewer_ids': [(4,self.user_id.id)]
)
class hr_evaluation_inherit(models.Model):
_inherit = 'hr_evaluation.evaluation'
_columns =
'interviewer_ids': fields.many2many('res.users',
string='Interviewer',readonly=True)
xml python-2.7 odoo-8
add a comment |
ial
one2many field name: survey_request_ids
model of one2many field : hr_evaluation.evaluation
Field name of 'Interviewer' inside one2many : user_id
model of 'Interviewer' inside one2many : hr.evaluation.interview
I want to create a new field 'Interviewer' below 'Appraisal Deadline'
which will have values from the below field 'Interviewer' which is in a one2many.
I tried like these,
from openerp import models,fields,api
class hr_evaluation_interview(models.Model):
_inherit = 'hr.evaluation.interview'
@api.onchange('user_id')
def _onchange_user_id(self):
rec = self.env['hr_evaluation.evaluation'].search([('id','=',
self.evaluation_id.id)])
rec.update(
'interviewer_ids': [(4,self.user_id.id)]
)
class hr_evaluation_inherit(models.Model):
_inherit = 'hr_evaluation.evaluation'
_columns =
'interviewer_ids': fields.many2many('res.users',
string='Interviewer',readonly=True)
xml python-2.7 odoo-8
ial
one2many field name: survey_request_ids
model of one2many field : hr_evaluation.evaluation
Field name of 'Interviewer' inside one2many : user_id
model of 'Interviewer' inside one2many : hr.evaluation.interview
I want to create a new field 'Interviewer' below 'Appraisal Deadline'
which will have values from the below field 'Interviewer' which is in a one2many.
I tried like these,
from openerp import models,fields,api
class hr_evaluation_interview(models.Model):
_inherit = 'hr.evaluation.interview'
@api.onchange('user_id')
def _onchange_user_id(self):
rec = self.env['hr_evaluation.evaluation'].search([('id','=',
self.evaluation_id.id)])
rec.update(
'interviewer_ids': [(4,self.user_id.id)]
)
class hr_evaluation_inherit(models.Model):
_inherit = 'hr_evaluation.evaluation'
_columns =
'interviewer_ids': fields.many2many('res.users',
string='Interviewer',readonly=True)
xml python-2.7 odoo-8
xml python-2.7 odoo-8
edited Nov 14 at 6:41
asked Nov 11 at 15:41
Afthab
33
33
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can use a computed many2many field. The compute method will loop through all the appraisal forms and create a recordset containing all the interviewers that appear in all the forms. Then populate the many2many field with that recordset.
It would look something like this:
def _compute_interviewer_ids(self):
for record in self:
interviewer_ids =
for appraisal_form in record.survey_request_ids:
interviewer_ids.append(appraisal_form.interviewer_id.id)
record.interviewer_ids = self.env['interviewer.model'].browse(interviewer_ids)
interviewer_ids = fields.Many2many('interviewer.model', compute='_compute_interviewer_ids', string='Interviewers')
Edit: here is an entire model and its submodel so you can see it in context. Tested in v12.
from odoo import models, fields, api
class ExampleModel(models.Model):
_name = 'example_module.example_model'
_description = 'Example Model'
def _compute_interviewer_ids(self):
for record in self:
interviewer_ids =
for appraisal_form in record.submodel_ids:
interviewer_ids.append(appraisal_form.partner_id.id)
record.interviewer_ids = self.env['res.partner'].browse(interviewer_ids)
name = fields.Char()
description = fields.Text()
submodel_ids = fields.One2many('example_module.example_sub_model', 'examplemodel_id', 'SubModel Records')
interviewer_ids = fields.Many2many('res.partner', compute='_compute_interviewer_ids', string='Interviewers')
class ExampleSubModel(models.Model):
_name = 'example_module.example_sub_model'
_description = 'Example Sub-model'
name = fields.Char()
examplemodel_id = fields.Many2one('example_module.example_model', 'Parent Record')
partner_id = fields.Many2one('res.partner', 'Partner')
This is not an onchange method, it's a compute method. I tested the code and it's working fine on my end. I will edit my post with the whole model and submodel for your reference
– djames
Nov 14 at 8:21
Thankyou. This worked in odoo8
– Afthab
Nov 14 at 9:26
Great, glad you got it working! Could you please accept my answer?
– djames
Nov 14 at 10:01
Accepted. Again thanks
– Afthab
Nov 16 at 5:55
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53250345%2fhow-to-pass-values-from-a-one2many-field-to-another-field-in-different-model-of%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use a computed many2many field. The compute method will loop through all the appraisal forms and create a recordset containing all the interviewers that appear in all the forms. Then populate the many2many field with that recordset.
It would look something like this:
def _compute_interviewer_ids(self):
for record in self:
interviewer_ids =
for appraisal_form in record.survey_request_ids:
interviewer_ids.append(appraisal_form.interviewer_id.id)
record.interviewer_ids = self.env['interviewer.model'].browse(interviewer_ids)
interviewer_ids = fields.Many2many('interviewer.model', compute='_compute_interviewer_ids', string='Interviewers')
Edit: here is an entire model and its submodel so you can see it in context. Tested in v12.
from odoo import models, fields, api
class ExampleModel(models.Model):
_name = 'example_module.example_model'
_description = 'Example Model'
def _compute_interviewer_ids(self):
for record in self:
interviewer_ids =
for appraisal_form in record.submodel_ids:
interviewer_ids.append(appraisal_form.partner_id.id)
record.interviewer_ids = self.env['res.partner'].browse(interviewer_ids)
name = fields.Char()
description = fields.Text()
submodel_ids = fields.One2many('example_module.example_sub_model', 'examplemodel_id', 'SubModel Records')
interviewer_ids = fields.Many2many('res.partner', compute='_compute_interviewer_ids', string='Interviewers')
class ExampleSubModel(models.Model):
_name = 'example_module.example_sub_model'
_description = 'Example Sub-model'
name = fields.Char()
examplemodel_id = fields.Many2one('example_module.example_model', 'Parent Record')
partner_id = fields.Many2one('res.partner', 'Partner')
This is not an onchange method, it's a compute method. I tested the code and it's working fine on my end. I will edit my post with the whole model and submodel for your reference
– djames
Nov 14 at 8:21
Thankyou. This worked in odoo8
– Afthab
Nov 14 at 9:26
Great, glad you got it working! Could you please accept my answer?
– djames
Nov 14 at 10:01
Accepted. Again thanks
– Afthab
Nov 16 at 5:55
add a comment |
You can use a computed many2many field. The compute method will loop through all the appraisal forms and create a recordset containing all the interviewers that appear in all the forms. Then populate the many2many field with that recordset.
It would look something like this:
def _compute_interviewer_ids(self):
for record in self:
interviewer_ids =
for appraisal_form in record.survey_request_ids:
interviewer_ids.append(appraisal_form.interviewer_id.id)
record.interviewer_ids = self.env['interviewer.model'].browse(interviewer_ids)
interviewer_ids = fields.Many2many('interviewer.model', compute='_compute_interviewer_ids', string='Interviewers')
Edit: here is an entire model and its submodel so you can see it in context. Tested in v12.
from odoo import models, fields, api
class ExampleModel(models.Model):
_name = 'example_module.example_model'
_description = 'Example Model'
def _compute_interviewer_ids(self):
for record in self:
interviewer_ids =
for appraisal_form in record.submodel_ids:
interviewer_ids.append(appraisal_form.partner_id.id)
record.interviewer_ids = self.env['res.partner'].browse(interviewer_ids)
name = fields.Char()
description = fields.Text()
submodel_ids = fields.One2many('example_module.example_sub_model', 'examplemodel_id', 'SubModel Records')
interviewer_ids = fields.Many2many('res.partner', compute='_compute_interviewer_ids', string='Interviewers')
class ExampleSubModel(models.Model):
_name = 'example_module.example_sub_model'
_description = 'Example Sub-model'
name = fields.Char()
examplemodel_id = fields.Many2one('example_module.example_model', 'Parent Record')
partner_id = fields.Many2one('res.partner', 'Partner')
This is not an onchange method, it's a compute method. I tested the code and it's working fine on my end. I will edit my post with the whole model and submodel for your reference
– djames
Nov 14 at 8:21
Thankyou. This worked in odoo8
– Afthab
Nov 14 at 9:26
Great, glad you got it working! Could you please accept my answer?
– djames
Nov 14 at 10:01
Accepted. Again thanks
– Afthab
Nov 16 at 5:55
add a comment |
You can use a computed many2many field. The compute method will loop through all the appraisal forms and create a recordset containing all the interviewers that appear in all the forms. Then populate the many2many field with that recordset.
It would look something like this:
def _compute_interviewer_ids(self):
for record in self:
interviewer_ids =
for appraisal_form in record.survey_request_ids:
interviewer_ids.append(appraisal_form.interviewer_id.id)
record.interviewer_ids = self.env['interviewer.model'].browse(interviewer_ids)
interviewer_ids = fields.Many2many('interviewer.model', compute='_compute_interviewer_ids', string='Interviewers')
Edit: here is an entire model and its submodel so you can see it in context. Tested in v12.
from odoo import models, fields, api
class ExampleModel(models.Model):
_name = 'example_module.example_model'
_description = 'Example Model'
def _compute_interviewer_ids(self):
for record in self:
interviewer_ids =
for appraisal_form in record.submodel_ids:
interviewer_ids.append(appraisal_form.partner_id.id)
record.interviewer_ids = self.env['res.partner'].browse(interviewer_ids)
name = fields.Char()
description = fields.Text()
submodel_ids = fields.One2many('example_module.example_sub_model', 'examplemodel_id', 'SubModel Records')
interviewer_ids = fields.Many2many('res.partner', compute='_compute_interviewer_ids', string='Interviewers')
class ExampleSubModel(models.Model):
_name = 'example_module.example_sub_model'
_description = 'Example Sub-model'
name = fields.Char()
examplemodel_id = fields.Many2one('example_module.example_model', 'Parent Record')
partner_id = fields.Many2one('res.partner', 'Partner')
You can use a computed many2many field. The compute method will loop through all the appraisal forms and create a recordset containing all the interviewers that appear in all the forms. Then populate the many2many field with that recordset.
It would look something like this:
def _compute_interviewer_ids(self):
for record in self:
interviewer_ids =
for appraisal_form in record.survey_request_ids:
interviewer_ids.append(appraisal_form.interviewer_id.id)
record.interviewer_ids = self.env['interviewer.model'].browse(interviewer_ids)
interviewer_ids = fields.Many2many('interviewer.model', compute='_compute_interviewer_ids', string='Interviewers')
Edit: here is an entire model and its submodel so you can see it in context. Tested in v12.
from odoo import models, fields, api
class ExampleModel(models.Model):
_name = 'example_module.example_model'
_description = 'Example Model'
def _compute_interviewer_ids(self):
for record in self:
interviewer_ids =
for appraisal_form in record.submodel_ids:
interviewer_ids.append(appraisal_form.partner_id.id)
record.interviewer_ids = self.env['res.partner'].browse(interviewer_ids)
name = fields.Char()
description = fields.Text()
submodel_ids = fields.One2many('example_module.example_sub_model', 'examplemodel_id', 'SubModel Records')
interviewer_ids = fields.Many2many('res.partner', compute='_compute_interviewer_ids', string='Interviewers')
class ExampleSubModel(models.Model):
_name = 'example_module.example_sub_model'
_description = 'Example Sub-model'
name = fields.Char()
examplemodel_id = fields.Many2one('example_module.example_model', 'Parent Record')
partner_id = fields.Many2one('res.partner', 'Partner')
edited Nov 14 at 8:24
answered Nov 13 at 15:37
djames
642
642
This is not an onchange method, it's a compute method. I tested the code and it's working fine on my end. I will edit my post with the whole model and submodel for your reference
– djames
Nov 14 at 8:21
Thankyou. This worked in odoo8
– Afthab
Nov 14 at 9:26
Great, glad you got it working! Could you please accept my answer?
– djames
Nov 14 at 10:01
Accepted. Again thanks
– Afthab
Nov 16 at 5:55
add a comment |
This is not an onchange method, it's a compute method. I tested the code and it's working fine on my end. I will edit my post with the whole model and submodel for your reference
– djames
Nov 14 at 8:21
Thankyou. This worked in odoo8
– Afthab
Nov 14 at 9:26
Great, glad you got it working! Could you please accept my answer?
– djames
Nov 14 at 10:01
Accepted. Again thanks
– Afthab
Nov 16 at 5:55
This is not an onchange method, it's a compute method. I tested the code and it's working fine on my end. I will edit my post with the whole model and submodel for your reference
– djames
Nov 14 at 8:21
This is not an onchange method, it's a compute method. I tested the code and it's working fine on my end. I will edit my post with the whole model and submodel for your reference
– djames
Nov 14 at 8:21
Thankyou. This worked in odoo8
– Afthab
Nov 14 at 9:26
Thankyou. This worked in odoo8
– Afthab
Nov 14 at 9:26
Great, glad you got it working! Could you please accept my answer?
– djames
Nov 14 at 10:01
Great, glad you got it working! Could you please accept my answer?
– djames
Nov 14 at 10:01
Accepted. Again thanks
– Afthab
Nov 16 at 5:55
Accepted. Again thanks
– Afthab
Nov 16 at 5:55
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53250345%2fhow-to-pass-values-from-a-one2many-field-to-another-field-in-different-model-of%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown