--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+ <data>
+
+
+ <!-- View -->
+ <record model="ir.ui.view" id="wizard_add_moe_to_project_form">
+ <field name="name">wizard.project.moe.add</field>
+ <field name="model">cmmi.projet.moe.wizard</field>
+ <field name="arch" type="xml">
+ <form string="Add MOE to Project">
+ <field name="project_id" colspan="4" readonly="1" />
+ <field name="moe_id" colspan="4" />
+ <field name="main" colspan="4" />
+ <button type="object" name="action_add_moe_to_project" string="Add MOE to Project"/>
+ </form>
+ </field>
+ </record>
+
+ <!-- Actions window -->
+ <record model="ir.actions.act_window" id="wizard_add_moe_to_project">
+ <field name="name">Add MOE to Project</field>
+ <field name="res_model">cmmi.projet.moe.wizard</field>
+ <field name="view_mode">form</field>
+ <field name="target">new</field>
+ </record>
+
+
+ </data>
+</openerp>
_name = "cmmi.projet.moe.wizard"
+ def default_get(self, cr, uid, fields, context=None):
+ ret = osv.TransientModel.default_get(self, cr, uid, fields, context=context)
+ project_id = context.get('project_id', False)
+ if project_id:
+ ret['project_id'] = project_id
+ return ret
+
def _moes_selection(self, cr, uid, context=None):
model_base = self.pool.get("cmmi.mo.moe")
- model_proj = self.pool.get("cmmi.projet.domaine")
+ model_proj = self.pool.get("cmmi.projet.moe")
if context is None or not context.has_key("project_id"):
return []
- # recherche des lien entre le projet et les domaines
+ # recherche des lien entre le projet et les moes
links_ids = model_proj.search(
cr,
uid,
)]))
# recherche des domaines autres que ceux déjà sélectionnés
- domaines_ids = model_base.search(
+ moe_ids = model_base.search(
cr,
uid,
[('id', 'not in', excluded_ids)],
print [(r["id"], r["name"]) for r in model_base.read(
cr,
uid,
- domaines_ids,
+ moe_ids,
fields=["id", "name"],
context=context
)]
return [(r["id"], r["name"]) for r in model_base.read(
cr,
uid,
- domaines_ids,
+ moe_ids,
fields=["id", "name"],
context=context
)]
+
+ def action_add_domain_to_project(self, cr, uid, ids, context=None):
+ # Récupération du modèle utile pour écrire les données
+ model = self.pool.get("cmmi.projet.moe")
+
+ # Un wizard, donc un seul identifiant
+ id = ids[0]
+
+ # Récupération des informations mises dans l'assistant
+ result = self.read(cr, uid, id, context=context)
+
+ # Si on a coché principal, on vire principal des autres moes
+ if result["main"]:
+ model.write(
+ cr,
+ uid,
+ model.search(
+ cr,
+ uid,
+ [('project_id', '=', result["project_id"][0])],
+ context=context,
+ ),
+ {'main': False},
+ context=context,
+ )
+
+ # Création de la donnée à partir de la donnée du magicien
+ model.create(cr, uid, {
+ "main": result["main"],
+ "project_id": result["project_id"][0],
+ "moe_id": result["moe_id"],
+ }, context=context)
+
+
+ # Renvoi vers la vue du modèle
+ return {
+ "type": 'ir.actions.act_window',
+ "res_model": "cmmi.projet",
+ 'view_type': 'form',
+ 'view_mode': 'form',
+ 'res_id': result["project_id"][0],
+ 'context': context,
+ }
+
_columns = {
- "main": fields.boolean(string="Domaine principal ?"),
+ "main": fields.boolean(string="MOE principale ?"),
"project_id": fields.many2one("cmmi.projet",
string="Projet"),
- "domaine_id": fields.selection(_domaines_selection,
- string="Domaine"),
+ "moe_id": fields.selection(_moes_selection,
+ string="MOE"),
}
\ No newline at end of file