X-Git-Url: http://git.inspyration.org/?a=blobdiff_plain;f=projet.py;h=153a64d80e0659ab1f347fe1bbabc9628f66e6a4;hb=57de0ff5185bc197f3a4fcd7d9eb713c7daff256;hp=d312223fad89ab8554c714a8c3d2720dd6531a7e;hpb=442727d096ad65edb81c462f5a673d3b6a460602;p=OpenERP%2Fcmmi.git diff --git a/projet.py b/projet.py index d312223..153a64d 100644 --- a/projet.py +++ b/projet.py @@ -28,6 +28,25 @@ class Projet(osv.Model): return result + def _get_main_moa(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 moa in project.moa_ids: + if moa.main: + result[project.id] = moa.name + break + else: + result[project.id] = "Any moa is selected as main moa yet" + + return result + + _columns = { "name": fields.char(string="Title", size=64, required=True), "description": fields.text(string="Description"), @@ -64,15 +83,15 @@ class Projet(osv.Model): "project_id", string="MOE principale", domaine=[('main', '=', True)]), - "moa_id": fields.one2many("cmmi.projet.moa", - "project_id", - string="MOA principale", - domaine=[('main', '=', True)]), + "moa_id": fields.function(_get_main_moa, + type="string", + string="MOA principale"), "main_domain": fields.function(_get_main_domain, type="string", string="Domaine principal"), } + def create(self, cr, uid, vals, context=None): project_id = osv.Model.create(self, cr, uid, vals, context=context) @@ -213,7 +232,35 @@ class ProjetMoa(osv.Model): } def onchange_main(self, cr, uid, ids, project, moa, main, context=None): - pass + if not main: + return {'value': {'main': True}, + 'warning': { + 'title' : "Integrity Warning", + 'message' : "Une des MOA doit être la MOA principale", + } + } + ids = self.search( + cr, + uid, + [ + ('project_id', '=', project), + ('moa_id', '!=', moa), + ], + context=context, + ) + current_id = self.search( + cr, + uid, + [ + ('project_id', '=', project), + ('moa_id', '=', moa), + ], + 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 ProjetPhase(osv.Model):