I'm creating a custom module connected many2one to res_partner, that has some data for tasks that the contact has. I've tried first with a selection field and then with a many2one field, but nothing worked.
Can some one help, am I doing it wrong, is there a better way?
The try with selection field
def get_contacts_projects(self): selection_list = list() if self.partner_id: following = self.env['mail.followers'].sudo().search([('partner_id', '=', self.partner_id.id), ('res_model', '=', 'project.project')]) partners_sub_projects = list() for follow in following: partners_sub_projects.append(follow.res_id) projects = self.env['project.project'].sudo().search([('analytic_account_id.parent_project_id', '!=', False), ('id', '=', partners_sub_projects), ('active', '=', True) ]) for project in projects: selection_list.append((project.id, project.sudo().analytic_account_id.name)) return selection_list
# the fields
partner_id = fields.Many2one('res.partner', string='Contact', required=True, ondelete='cascade')
project_id = fields.Selection(selection=lambda self: self.get_contacts_projects())
The try with Many2one field
def get_contacts_projects(self): selection_list = list() if self.partner_id: following = self.env['mail.followers'].sudo().search([('partner_id', '=', self.partner_id.id), ('res_model', '=', 'project.project')]) for follow in following: selection_list.append(follow.res_id)
return selection_list# the fieldspartner_id = fields.Many2one('res.partner', string='Contact', required=True, ondelete='cascade')
project_id = fields.Many2one('project.project', string='Pod področje', domain=lambda self: [('id', 'in', self.get_contacts_projects())])
Odoo Customization Tips: https://learnopenerp.tumblr.com/
If you don't want to help you don't need to comment! I know how to use google and I didn't find a working answers on it! That's why I posted my problem on the forum!