from openerp.osv import osv, fields
+
class Projet(osv.Model):
- _name = "projet.projet"
+ _name = "cmmi.projet"
+
+ 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
+
_columns = {
"name": fields.char(string="Title", size=64, required=True),
"description": fields.text(string="Description"),
- "domaines": fields.many2many("projet.domaine",
- "projet_projet_domaine_rel",
- "projets",
- string="Domaines"),
- "structures": fields.many2many("projet.structure",
- "projet_projet_structure_rel",
- "projets",
- string="Structures"),
- "structures_moe": fields.many2many("projet.structure",
- "projet_projet_structure_rel",
- "projets",
- string="Structures",
- domain=[('role_mo_id.type_mo', '=', "MOE")]),
- "structures_moa": fields.many2many("projet.structure",
- "projet_projet_structure_rel",
- "projets",
- string="Structures",
- domain=[('role_mo_id.type_mo', '=', "MOA")]),
- "team_members": fields.many2many("projet.teammember",
- "projet_projet_teammember_rel",
- "projets",
+ "domains": fields.one2many("cmmi.projet.domaine",
+ "project_id",
+ string="Domaines"),
+ "team_members": fields.many2many("res.partner",
+ "cmmi_projet_teammember_rel",
+ "projet_id",
+ "partner_id",
string="Team Members"),
- "modules": fields.one2many("projet.module",
+ "modules": fields.one2many("cmmi.description.module",
"projet_id",
string="Modules"),
- "chantiers": fields.one2many("projet.chantier",
+ "chantiers": fields.one2many("cmmi.axes.chantier",
"projet_id",
string="Chantiers"),
- "paliers": fields.one2many("projet.palier",
+ "paliers": fields.one2many("cmmi.axes.palier",
"projet_id",
string="Paliers"),
- "phases": fields.one2many("projet.phase",
- "projet_id",
- string="Phases"),
- "evolutions":fields.one2many("projet.evolution",
- "projet_id",
- string="Evolutions"),
- "moe_id": fields.many2one("projet.moe", string="MoE", required=True),
- "moa_id": fields.many2one("projet.moa", string="MoA", required=True),
- "main_domain": fields.many2one("projet.domaine",
+ "phases": fields.one2many("cmmi.projet.phase",
+ "projet_id",
+ string="Phases"),
+ "evolutions": fields.one2many("cmmi.evolution",
+ "projet_id",
+ string="Evolutions"),
+ "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.one2many("cmmi.projet.moe",
+ "project_id",
+ string="MOE principale",
+ domaine=[('main', '=', True)]),
+ "moa_id": fields.one2many("cmmi.projet.moa",
+ "project_id",
+ string="MOA principale",
+ domaine=[('main', '=', True)]),
+ "main_domain": fields.function(_get_main_domain,
+ type="string",
string="Domaine principal"),
- "main_structure": fields.many2one("projet.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")
+ 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
-class Evolution(osv.Model):
- _name = "projet.evolution"
+ def action_add_moa(self, cr, uid, ids, context=None):
+ pass
- _priorites = [("incontournable", "Incontournable"),
- ("necessaire", "Nécéssaire"),
- ("utile", "Utile")]
+class ProjetDomaine(osv.Model):
- _statuts = [("cree", "Crée"), ("encours", "En cours"),
- ("termine", "Terminé"), ("abandonne", "Abandonné"),
- ("suspendu", "Suspendu")]
+ _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 = {
- "pid": fields.integer(string="PID"),
- "name": fields.char(string="Title", size=64, required=True),
- "description": fields.text(string="Description"),
- "objectif": fields.text(string="Objectif"),
- "commentaire": fields.text(string="Commentaire"),
- "keywords": fields.text(string="Mots clés"),
- "priorite": fields.selection(_priorites, string="Priorité"),
- "statut": fields.selection(_statuts, string="Statut"),
- "charges": fields.one2many("projet.charge",
- "evolution_id",
- string="Charges"),
- "module_id": fields.many2one("projet.module",
- string="Modules"),
- "chantier_id": fields.many2one("projet.chantier",
- string="Chantier"),
- "palier_id": fields.many2one("projet.palier",
- string="Palier"),
- "phase_id": fields.many2one("projet.phase",
- string="Phase"),
- "projet_id": fields.many2one("projet.projet",
- string="Projet"),
+ "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.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, # Permet d'enregistrer le champ.
+ string="Nom de la MOE"),
+ "main": fields.boolean(string="MOE principale ?"),
+ "project_id": fields.many2one("cmmi.projet",
+ string="Projet",
+ required=True),
+ "moe_id": fields.many2one("cmmi.mo.moe",
+ string="MOE",
+ required=True),
}
+ def onchange_main(self, cr, uid, ids, project, moe, main, context=None):
+ pass
-class Teammember(osv.Model):
- _name = "projet.teammember"
- _inherit = "res.partner"
+class ProjetMoa(osv.Model):
+ _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.moa_id.name) for i, r in
+ zip(ids, self.browse(cr, uid, ids, context=context))])
_columns = {
- "projets": fields.many2many("projet.projet",
- "projet_projet_teammember_rel",
- "team_members",
- string="Projets"),
- "charges": fields.one2many("projet.projet",
- "team_members",
- string="Charges"),
+ "name": fields.function(_get_name,
+ type='char',
+ store=True,
+ string="Nom de la MOA"),
+ "main": fields.boolean(string="MOA principale ?"),
+ "project_id": fields.many2one("cmmi.projet",
+ string="Projet",
+ required=True),
+ "moa_id": fields.many2one("cmmi.mo.moa",
+ string="MOA",
+ required=True),
}
+ def onchange_main(self, cr, uid, ids, project, moa, main, context=None):
+ pass
+
-class Charge(osv.Model):
- _name = "projet.charge"
+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.char(string="Title", size=64, required=True),
- "description": fields.text(string="Description"),
- "teammember_id": fields.many2one("projet.teammember",
- string="Team Member",
- required=True),
- "phase_id": fields.many2one("projet.phase",
+ "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",
string="Phase",
required=True),
- "evolution_id": fields.many2one("projet.evolution",
- string="Evolution",
- required=True),
- "mo_id": fields.many2one("projet.mo",
- string="Mo"),
- }
+ }
\ No newline at end of file