X-Git-Url: http://git.inspyration.org/?a=blobdiff_plain;f=wizards%2FpalierPhase.py;fp=wizards%2FpalierPhase.py;h=26375dfd42dba175abd1ee7a0956a4a802ac5862;hb=83ff6f3c4410bcbf68cd6a98a7b6db4ed542a742;hp=8716880a512fed88380e660239c8ecd925177214;hpb=96a734d69f523be91b449709294b3e9f336a9def;p=OpenERP%2Fcmmi.git diff --git a/wizards/palierPhase.py b/wizards/palierPhase.py index 8716880..26375df 100644 --- a/wizards/palierPhase.py +++ b/wizards/palierPhase.py @@ -2,7 +2,6 @@ from openerp.osv import osv, fields -# TODO: finir PalierPhaseWizard class PalierPhaseWizard(osv.TransientModel): _name = "cmmi.palier.phase.wizard" @@ -16,14 +15,69 @@ class PalierPhaseWizard(osv.TransientModel): return result - def _phases_selection(self, cr, uid, context=None): - phase_model = self.pool.get("cmmi.phase") + phase_model = self.pool.get("cmmi.projet.phase") palier_phase_model = self.pool.get("cmmi.axes.palier.phase") if context is None or not context.has_key("palier_id"): return [] + # on recherche des palier-phases + links_ids = palier_phase_model.search( + cr, + uid, + [('palier_id', '=', context["palier_id"])], + context=context, + ) + + # on recherche phases déjà présentes dans le palier + excluded_ids = list(set([p['phase_id'][0] for p in palier_phase_model.read( + cr, + uid, + links_ids, + fields=["phase_id"], + context=context + )])) + + # on exclu les phases déjà présentes dans le palier + phases_ids = phase_model.search( + cr, + uid, + [('id', 'not in', excluded_ids), ('selectionne', '=', True)], + context=context, + ) + + print [(p["id"], p["name"]) for p in phase_model.read( + cr, + uid, + phases_ids, + fields=["id", "name"], + context=context + )] + return [(p["id"], p["name"]) for p in phase_model.read( + cr, + uid, + phases_ids, + fields=["id", "name"], + context=context + )] + + + def action_add_phase_to_palier(self, cr, uid, ids, context=None): + palier_phase_model = self.pool.get("cmmi.axes.palier.phase") + + id = ids[0] + + result = self.read(cr, uid, id, context=context) + + palier_phase_model.create ( + cr, + uid, + {"palier_id": result["palier_id"][0],"phase_id": result["phase_id"]}, + context=context, + ) + + return {'type': 'ir.actions.act_window_close'} _columns = { @@ -34,7 +88,7 @@ class PalierPhaseWizard(osv.TransientModel): # string="Phase", # required=True, # domain=[("selectionne", "=", True)]), - "phase_id": fields.function(_phases_selection, + "phase_id": fields.selection(_phases_selection, string="Phase", required=True), } \ No newline at end of file