X-Git-Url: http://git.inspyration.org/?a=blobdiff_plain;f=projet.py;h=611c4221ce2ba3e010b821c13bab3a9b17098831;hb=4495114a4605c2f1fbe47e0aafce3b6a08d02e53;hp=dd108b2385e7419554c7065147cfd1635504f614;hpb=9a717c89dee5566944bad788ae9631459ef4f7ef;p=OpenERP%2Fcmmi.git diff --git a/projet.py b/projet.py index dd108b2..611c422 100644 --- a/projet.py +++ b/projet.py @@ -9,29 +9,71 @@ class Projet(osv.Model): _name = "cmmi.projet" - _domains = { - 'moe': [('role_mo_id.type_mo', '=', "MOE")], - 'moa': [('role_mo_id.type_mo', '=', "MOA")], - } + def _get_main_domain(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 domain in project.domains: + if domain.main: + result[project.id] = domain.name + break + else: + result[project.id] = "Any domain is selected as main domain yet" + + 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 + + + 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 + _columns = { "name": fields.char(string="Title", size=64, required=True), "description": fields.text(string="Description"), - "domaines": fields.one2many("cmmi.projet.domaine", + "domains": fields.one2many("cmmi.projet.domaine", "project_id", string="Domaines"), - "structures": fields.many2many("cmmi.mo.structure", - string="Structures"), - "structures_moe": fields.many2many("cmmi.mo.structure", - string="Structures", - domain=_domains['moe']), - "structures_moa": fields.many2many("cmmi.mo.structure", - string="Structures", - domain=_domains['moa']), - "team_members": fields.many2many("cmmi.partner.teammember", - "cmmi_projet_teammember_rel", + "team_members": fields.one2many("cmmi.projet.teammember", "projet_id", - "partner_id", string="Team Members"), "modules": fields.one2many("cmmi.description.module", "projet_id", @@ -42,23 +84,62 @@ class Projet(osv.Model): "paliers": fields.one2many("cmmi.axes.palier", "projet_id", string="Paliers"), - "phases": fields.one2many("cmmi.phase", + "phases": fields.one2many("cmmi.projet.phase", "projet_id", string="Phases"), "evolutions": fields.one2many("cmmi.evolution", "projet_id", string="Evolutions"), - "moe_id": fields.many2one("cmmi.mo.moe", string="MoE", required=True), - "moa_id": fields.many2one("cmmi.mo.moa", string="MoA", required=True), - "main_domain": fields.many2one("cmmi.description.domaine", + "moe_ids": fields.one2many("cmmi.projet.moe", + "project_id", + string="MOEs"), + "moa_ids": fields.one2many("cmmi.projet.moa", + "project_id", + string="MOAs"), + "moe_id": fields.function(_get_main_moe, + type="string", + string="MOE principale"), + "moa_id": fields.function(_get_main_moa, + type="string", + string="MOA principale"), + "main_domain": fields.function(_get_main_domain, + type="string", string="Domaine principal"), - "main_structure": fields.many2one("cmmi.mo.structure", - string="Structure principale"), } + + def create(self, cr, uid, vals, context=None): + project_id = osv.Model.create(self, cr, uid, vals, context=context) + + # Récupération des ids de toutes les phases + phase_model = self.pool.get("cmmi.phase.type") + phases_ids = phase_model.search(cr, uid, []) + + # Création des relations + projet_phase_model = self.pool.get("cmmi.projet.phase") + for phase_id in phases_ids: + projet_phase_model.create( + cr, + uid, + { + 'projet_id': project_id, + 'phase_id': phase_id, + 'selectionne': False, + } + ) + + return project_id + + def action_add_domain(self, cr, uid, ids, context=None): pass + def action_add_moe(self, cr, uid, ids, context=None): + pass + + def action_add_moa(self, cr, uid, ids, context=None): + pass + class ProjetDomaine(osv.Model): _name = "cmmi.projet.domaine" @@ -122,29 +203,62 @@ class ProjetMoe(osv.Model): 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 + return dict([(i, r.moe_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, + store=True, # Permet d'enregistrer le champ. string="Nom de la MOE"), "main": fields.boolean(string="MOE principale ?"), "project_id": fields.many2one("cmmi.projet", - string="Projet"), + string="Projet", + required=True), "moe_id": fields.many2one("cmmi.mo.moe", - string="MOE"), + string="MOE", + required=True), } + def onchange_main(self, cr, uid, ids, project, moe, main, context=None): + 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): - _name = "cmmi.projet.moe" + _name = "cmmi.projet.moa" 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 + return dict([(i, r.moa_id.name) for i, r in zip(ids, self.browse(cr, uid, ids, context=context))]) _columns = { @@ -154,7 +268,100 @@ class ProjetMoa(osv.Model): string="Nom de la MOA"), "main": fields.boolean(string="MOA principale ?"), "project_id": fields.many2one("cmmi.projet", - string="Projet"), + string="Projet", + required=True), "moa_id": fields.many2one("cmmi.mo.moa", - string="MOA"), + string="MOA", + required=True), + } + + def onchange_main(self, cr, uid, ids, project, moa, main, context=None): + 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): + _name = "cmmi.projet.phase" + + 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.phase_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 phase"), + "selectionne": fields.boolean(string="Phase sélectionnée ?"), + "projet_id": fields.many2one("cmmi.projet", + string="Projet", + required=True), + "phase_id": fields.many2one("cmmi.phase.type", + string="Phase", + required=True), + } + + +class ProjetTeammember(osv.Model): + _name = "cmmi.projet.teammember" + + def _get_partner_name(self, cr, uid, ids, field_name=None, arg=None, context=None): + if isinstance(ids, (int, long)): + ids = [ids] + return dict([(i, r.partner_id.name) for i, r in + zip(ids, self.browse(cr, uid, ids, context=context))]) + + def _get_project_name(self, cr, uid, ids, field_name=None, arg=None, context=None): + if isinstance(ids, (int, long)): + ids = [ids] + return dict([(i, r.projet_id.name) for i, r in + zip(ids, self.browse(cr, uid, ids, context=context))]) + + _columns = { + "name": fields.function(_get_partner_name, + type='char', + store=True, + string="Nom du partner"), + "projet_name": fields.function(_get_project_name, + type='char', + store=True, + string="Nom du projet"), + "affecte": fields.integer(string="Affecté à"), + "depuis": fields.date(string="Depuis"), + "jusqua": fields.date(string="Jusqu'à"), + "projet_id": fields.many2one("cmmi.projet", + string="Projet", + required=True), + "partner_id": fields.many2one("res.partner", + string="Team Member", + required=True), } \ No newline at end of file