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

Constraint, domain or onchange function ?

By
Célia Couiller
on 11/25/16, 3:43 AM 119 views

Hi


I have the following model :

class Project(models.Model):  
    _inherit = 'project.project'
    releases_ids= fields.Many2many('project_extension.release')
sprint_ids= fields.Many2many('project_extension.sprint')
class Release(models.Model):
_name = 'project_extension.release'
     project_id = fields.Many2one('project.project', string="Project")
class Sprint(models.Model):
    _name = 'project_extension.sprint'
    project_id = fields.Many2one('project.project')
    release_id = fields.Many2one('project_extension.release')


I want my sprints to be in the same project as there parent release (and the other way), but I don't know the better way to express it.

Should I make it with python constraint, domain filter, computed field (with get and inverse set function) or with a onchange ?


Thanks for your help.

1
Juan Vicente Pascual
On 11/25/16, 11:32 AM

make project_id (from class project_extension.sprint) readonly, then in the onchange function of the release, write the project in the sprint.


class Sprint(models.Model):
    _name = 'project_extension.sprint'   

project_id = fields.Many2one('project.project')   

release_id = fields.Many2one('project_extension.release', readonly=True)


@api.multi   

@api.onchange('release_id')   

def _compute_change_release_id(self):

     if self.release_id:
        self.project_id = self.release_id.project_id

Kind regards,

Juanvi


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: 11/25/16, 3:43 AM
Seen: 119 times
Last updated: 11/28/16, 3:16 AM