X-Git-Url: http://git.inspyration.org/?a=blobdiff_plain;f=projet.py;h=8758a83fa14e19aab6a9027af075941ef797575b;hb=9cd9465271cb7dae51c38210bc2fcb81ed4b771e;hp=2b4d94ace1b5638a5f0932a8f83bd205415d1745;hpb=5115fe3c592a50a93ff740ba11b8737cdedc68ef;p=OpenERP%2Fcmmi.git diff --git a/projet.py b/projet.py index 2b4d94a..8758a83 100644 --- a/projet.py +++ b/projet.py @@ -17,8 +17,9 @@ class Projet(osv.Model): _columns = { "name": fields.char(string="Title", size=64, required=True), "description": fields.text(string="Description"), - "domaines": fields.many2many("cmmi.description.domaine", - string="Domaines"), + "domaines": fields.one2many("cmmi.projet.domaine", + "project_id", + string="Domaines"), "structures": fields.many2many("cmmi.mo.structure", string="Structures"), "structures_moe": fields.many2many("cmmi.mo.structure", @@ -54,3 +55,84 @@ class Projet(osv.Model): "main_structure": fields.many2one("cmmi.mo.structure", string="Structure principale"), } + + def action_add_domain(self, cr, uid, ids, context=None): + pass + +class ProjetDomaine(osv.Model): + + _name = "cmmi.projet.domaine" + + def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None): + if isinstance(ids, (int, long)): + ids = [ids] + #return {i: r.domaine_id.name for i, r in + # zip(ids, self.browse(cr, uid, ids, context=context))} + return dict([(i, r.domaine_id.name) for i, r in + zip(ids, self.browse(cr, uid, ids, context=context))]) + + _columns = { + "name": fields.function(_get_name, + type='char', + store=True, + string="Nom du domaine"), + "main": fields.boolean(string="Domaine principal ?"), + "project_id": fields.many2one("cmmi.projet", + string="Projet"), + "domaine_id": fields.many2one("cmmi.description.domaine", + string="Domaine"), + } + + def onchange_main(self, cr, uid, ids, project, domaine, main, context=None): + if not main: + return {'value': {'main': True}, + 'warning': { + 'title' : "Integrity Warning", + 'message' : "One of the domains should be the main domain", + } + } + ids = self.search( + cr, + uid, + [ + ('project_id', '=', project), + ('domaine_id', '!=', domaine), + ], + context=context, + ) + current_id = self.search( + cr, + uid, + [ + ('project_id', '=', project), + ('domaine_id', '=', domaine), + ], + 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 ProjetMoe(osv.Model): + _name = "cmmi.projet.moe" + + def _get_name(self, cr, uid, ids, field_name=None, arg=None, context=None): + if isinstance(ids, (int, long)): + ids = [ids] + return dict([(i, r.domaine_id.name) for i, r in + zip(ids, self.browse(cr, uid, ids, context=context))]) + + _columns = { + "name": fields.function(_get_name, + type='char', + store=True, + string="Nom de la MOE"), + "main": fields.boolean(string="MOE principale ?"), + "project_id": fields.many2one("cmmi.projet", + string="Projet"), + "moe_id": fields.many2one("cmmi.mo.moe", + string="MOE"), + } \ No newline at end of file