From: Alicia FLOREZ Date: Fri, 24 May 2013 14:39:19 +0000 (+0200) Subject: Prise en compte de la MOE principale pour les projets X-Git-Url: http://git.inspyration.org/?p=OpenERP%2Fcmmi.git;a=commitdiff_plain;h=c6500e05c7b05f0df5a6fb0146b7abf24793c086 Prise en compte de la MOE principale pour les projets --- diff --git a/projet.py b/projet.py index 153a64d..6dc86ed 100644 --- a/projet.py +++ b/projet.py @@ -42,7 +42,26 @@ class Projet(osv.Model): result[project.id] = moa.name break else: - result[project.id] = "Any moa is selected as main moa yet" + result[project.id] = "Any MOA is selected as main MOA yet" + + return result + + + def _get_main_moe(self, cr, uid, ids, field_name=None, arg=None, context=None): + if type(ids) in (int, float): + ids = [ids] + + projects = self.browse(cr, uid, ids, context=context) + + result = {} + + for project in projects: + for moe in project.moe_ids: + if moe.main: + result[project.id] = moe.name + break + else: + result[project.id] = "Any MOE is selected as main MOE yet" return result @@ -79,10 +98,9 @@ class Projet(osv.Model): "moa_ids": fields.one2many("cmmi.projet.moa", "project_id", string="MOAs"), - "moe_id": fields.one2many("cmmi.projet.moe", - "project_id", - string="MOE principale", - domaine=[('main', '=', True)]), + "moe_id": fields.function(_get_main_moe, + type="string", + string="MOE principale"), "moa_id": fields.function(_get_main_moa, type="string", string="MOA principale"), @@ -205,7 +223,35 @@ class ProjetMoe(osv.Model): } def onchange_main(self, cr, uid, ids, project, moe, main, context=None): - pass + if not main: + return {'value': {'main': True}, + 'warning': { + 'title' : "Integrity Warning", + 'message' : "Une des MOE doit être la MOE principale", + } + } + ids = self.search( + cr, + uid, + [ + ('project_id', '=', project), + ('moe_id', '!=', moe), + ], + context=context, + ) + current_id = self.search( + cr, + uid, + [ + ('project_id', '=', project), + ('moe_id', '=', moe), + ], + context=context, + ) + self.write(cr, uid, ids, {'main': False}, context=context) + self.write(cr, uid, current_id, {'main': True}, context=context) + + return {'value': {'main': True}} class ProjetMoa(osv.Model): diff --git a/views/projet.xml b/views/projet.xml index da6de3e..7c76796 100644 --- a/views/projet.xml +++ b/views/projet.xml @@ -16,7 +16,7 @@